api.c 3.7 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936929379293892939929409294192942929439294492945929469294792948929499295092951929529295392954929559295692957929589295992960929619296292963929649296592966929679296892969929709297192972929739297492975929769297792978929799298092981929829298392984929859298692987929889298992990929919299292993929949299592996929979299892999930009300193002930039300493005930069300793008930099301093011930129301393014930159301693017930189301993020930219302293023930249302593026930279302893029930309303193032930339303493035930369303793038930399304093041930429304393044930459304693047930489304993050930519305293053930549305593056930579305893059930609306193062930639306493065930669306793068930699307093071930729307393074930759307693077930789307993080930819308293083930849308593086930879308893089930909309193092930939309493095930969309793098930999310093101931029310393104931059310693107931089310993110931119311293113931149311593116931179311893119931209312193122931239312493125931269312793128931299313093131931329313393134931359313693137931389313993140931419314293143931449314593146931479314893149931509315193152931539315493155931569315793158931599316093161931629316393164931659316693167931689316993170931719317293173931749317593176931779317893179931809318193182931839318493185931869318793188931899319093191931929319393194931959319693197931989319993200932019320293203932049320593206932079320893209932109321193212932139321493215932169321793218932199322093221932229322393224932259322693227932289322993230932319323293233932349323593236932379323893239932409324193242932439324493245932469324793248932499325093251932529325393254932559325693257932589325993260932619326293263932649326593266932679326893269932709327193272932739327493275932769327793278932799328093281932829328393284932859328693287932889328993290932919329293293932949329593296932979329893299933009330193302933039330493305933069330793308933099331093311933129331393314933159331693317933189331993320933219332293323933249332593326933279332893329933309333193332933339333493335933369333793338933399334093341933429334393344933459334693347933489334993350933519335293353933549335593356933579335893359933609336193362933639336493365933669336793368933699337093371933729337393374933759337693377933789337993380933819338293383933849338593386933879338893389933909339193392933939339493395933969339793398933999340093401934029340393404934059340693407934089340993410934119341293413934149341593416934179341893419934209342193422934239342493425934269342793428934299343093431934329343393434934359343693437934389343993440934419344293443934449344593446934479344893449934509345193452934539345493455934569345793458934599346093461934629346393464934659346693467934689346993470934719347293473934749347593476934779347893479934809348193482934839348493485934869348793488934899349093491934929349393494934959349693497934989349993500935019350293503935049350593506935079350893509935109351193512935139351493515935169351793518935199352093521935229352393524935259352693527935289352993530935319353293533935349353593536935379353893539935409354193542935439354493545935469354793548935499355093551935529355393554935559355693557935589355993560935619356293563935649356593566935679356893569935709357193572935739357493575935769357793578935799358093581935829358393584935859358693587935889358993590935919359293593935949359593596935979359893599936009360193602936039360493605936069360793608936099361093611936129361393614936159361693617936189361993620936219362293623936249362593626936279362893629936309363193632936339363493635936369363793638936399364093641936429364393644936459364693647936489364993650936519365293653936549365593656936579365893659936609366193662936639366493665936669366793668936699367093671936729367393674936759367693677936789367993680936819368293683936849368593686936879368893689936909369193692936939369493695936969369793698936999370093701937029370393704937059370693707937089370993710937119371293713937149371593716937179371893719937209372193722937239372493725937269372793728937299373093731937329373393734937359373693737937389373993740937419374293743937449374593746937479374893749937509375193752937539375493755937569375793758937599376093761937629376393764937659376693767937689376993770937719377293773937749377593776937779377893779937809378193782937839378493785937869378793788937899379093791937929379393794937959379693797937989379993800938019380293803938049380593806938079380893809938109381193812938139381493815938169381793818938199382093821938229382393824938259382693827938289382993830938319383293833938349383593836938379383893839938409384193842938439384493845938469384793848938499385093851938529385393854938559385693857938589385993860938619386293863938649386593866938679386893869938709387193872938739387493875938769387793878938799388093881938829388393884938859388693887938889388993890938919389293893938949389593896938979389893899939009390193902939039390493905939069390793908939099391093911939129391393914939159391693917939189391993920939219392293923939249392593926939279392893929939309393193932939339393493935939369393793938939399394093941939429394393944939459394693947939489394993950939519395293953939549395593956939579395893959939609396193962939639396493965939669396793968939699397093971939729397393974939759397693977939789397993980939819398293983939849398593986939879398893989939909399193992939939399493995939969399793998939999400094001940029400394004940059400694007940089400994010940119401294013940149401594016940179401894019940209402194022940239402494025940269402794028940299403094031940329403394034940359403694037940389403994040940419404294043940449404594046940479404894049940509405194052940539405494055940569405794058940599406094061940629406394064940659406694067940689406994070940719407294073940749407594076940779407894079940809408194082940839408494085940869408794088940899409094091940929409394094940959409694097940989409994100941019410294103941049410594106941079410894109941109411194112941139411494115941169411794118941199412094121941229412394124941259412694127941289412994130941319413294133941349413594136941379413894139941409414194142941439414494145941469414794148941499415094151941529415394154941559415694157941589415994160941619416294163941649416594166941679416894169941709417194172941739417494175941769417794178941799418094181941829418394184941859418694187941889418994190941919419294193941949419594196941979419894199942009420194202942039420494205942069420794208942099421094211942129421394214942159421694217942189421994220942219422294223942249422594226942279422894229942309423194232942339423494235942369423794238942399424094241942429424394244942459424694247942489424994250942519425294253942549425594256942579425894259942609426194262942639426494265942669426794268942699427094271942729427394274942759427694277942789427994280942819428294283942849428594286942879428894289942909429194292942939429494295942969429794298942999430094301943029430394304943059430694307943089430994310943119431294313943149431594316943179431894319943209432194322943239432494325943269432794328943299433094331943329433394334943359433694337943389433994340943419434294343943449434594346943479434894349943509435194352943539435494355943569435794358943599436094361943629436394364943659436694367943689436994370943719437294373943749437594376943779437894379943809438194382943839438494385943869438794388943899439094391943929439394394943959439694397943989439994400944019440294403944049440594406944079440894409944109441194412944139441494415944169441794418944199442094421944229442394424944259442694427944289442994430944319443294433944349443594436944379443894439944409444194442944439444494445944469444794448944499445094451944529445394454944559445694457944589445994460944619446294463944649446594466944679446894469944709447194472944739447494475944769447794478944799448094481944829448394484944859448694487944889448994490944919449294493944949449594496944979449894499945009450194502945039450494505945069450794508945099451094511945129451394514945159451694517945189451994520945219452294523945249452594526945279452894529945309453194532945339453494535945369453794538945399454094541945429454394544945459454694547945489454994550945519455294553945549455594556945579455894559945609456194562945639456494565945669456794568945699457094571945729457394574945759457694577945789457994580945819458294583945849458594586945879458894589945909459194592945939459494595945969459794598945999460094601946029460394604946059460694607946089460994610946119461294613946149461594616946179461894619946209462194622946239462494625946269462794628946299463094631946329463394634946359463694637946389463994640946419464294643946449464594646946479464894649946509465194652946539465494655946569465794658946599466094661946629466394664946659466694667946689466994670946719467294673946749467594676946779467894679946809468194682946839468494685946869468794688946899469094691946929469394694946959469694697946989469994700947019470294703947049470594706947079470894709947109471194712947139471494715947169471794718947199472094721947229472394724947259472694727947289472994730947319473294733947349473594736947379473894739947409474194742947439474494745947469474794748947499475094751947529475394754947559475694757947589475994760947619476294763947649476594766947679476894769947709477194772947739477494775947769477794778947799478094781947829478394784947859478694787947889478994790947919479294793947949479594796947979479894799948009480194802948039480494805948069480794808948099481094811948129481394814948159481694817948189481994820948219482294823948249482594826948279482894829948309483194832948339483494835948369483794838948399484094841948429484394844948459484694847948489484994850948519485294853948549485594856948579485894859948609486194862948639486494865948669486794868948699487094871948729487394874948759487694877948789487994880948819488294883948849488594886948879488894889948909489194892948939489494895948969489794898948999490094901949029490394904949059490694907949089490994910949119491294913949149491594916949179491894919949209492194922949239492494925949269492794928949299493094931949329493394934949359493694937949389493994940949419494294943949449494594946949479494894949949509495194952949539495494955949569495794958949599496094961949629496394964949659496694967949689496994970949719497294973949749497594976949779497894979949809498194982949839498494985949869498794988949899499094991949929499394994949959499694997949989499995000950019500295003950049500595006950079500895009950109501195012950139501495015950169501795018950199502095021950229502395024950259502695027950289502995030950319503295033950349503595036950379503895039950409504195042950439504495045950469504795048950499505095051950529505395054950559505695057950589505995060950619506295063950649506595066950679506895069950709507195072950739507495075950769507795078950799508095081950829508395084950859508695087950889508995090950919509295093950949509595096950979509895099951009510195102951039510495105951069510795108951099511095111951129511395114951159511695117951189511995120951219512295123951249512595126951279512895129951309513195132951339513495135951369513795138951399514095141951429514395144951459514695147951489514995150951519515295153951549515595156951579515895159951609516195162951639516495165951669516795168951699517095171951729517395174951759517695177951789517995180951819518295183951849518595186951879518895189951909519195192951939519495195951969519795198951999520095201952029520395204952059520695207952089520995210952119521295213952149521595216952179521895219952209522195222952239522495225952269522795228952299523095231952329523395234952359523695237952389523995240952419524295243952449524595246952479524895249952509525195252952539525495255952569525795258952599526095261952629526395264952659526695267952689526995270952719527295273952749527595276952779527895279952809528195282952839528495285952869528795288952899529095291952929529395294952959529695297952989529995300953019530295303953049530595306953079530895309953109531195312953139531495315953169531795318953199532095321953229532395324953259532695327953289532995330953319533295333953349533595336953379533895339953409534195342953439534495345953469534795348953499535095351953529535395354953559535695357953589535995360953619536295363953649536595366953679536895369953709537195372953739537495375953769537795378953799538095381953829538395384953859538695387953889538995390953919539295393953949539595396953979539895399954009540195402954039540495405954069540795408954099541095411954129541395414954159541695417954189541995420954219542295423954249542595426954279542895429954309543195432954339543495435954369543795438954399544095441954429544395444954459544695447954489544995450954519545295453954549545595456954579545895459954609546195462954639546495465954669546795468954699547095471954729547395474954759547695477954789547995480954819548295483954849548595486954879548895489954909549195492954939549495495954969549795498954999550095501955029550395504955059550695507955089550995510955119551295513955149551595516955179551895519955209552195522955239552495525955269552795528955299553095531955329553395534955359553695537955389553995540955419554295543955449554595546955479554895549955509555195552955539555495555955569555795558955599556095561955629556395564955659556695567955689556995570955719557295573955749557595576955779557895579955809558195582955839558495585955869558795588955899559095591955929559395594955959559695597955989559995600956019560295603956049560595606956079560895609956109561195612956139561495615956169561795618956199562095621956229562395624956259562695627956289562995630956319563295633956349563595636956379563895639956409564195642956439564495645956469564795648956499565095651956529565395654956559565695657956589565995660956619566295663956649566595666956679566895669956709567195672956739567495675956769567795678956799568095681956829568395684956859568695687956889568995690956919569295693956949569595696956979569895699957009570195702957039570495705957069570795708957099571095711957129571395714957159571695717957189571995720957219572295723957249572595726957279572895729957309573195732957339573495735957369573795738957399574095741957429574395744957459574695747957489574995750957519575295753957549575595756957579575895759957609576195762957639576495765957669576795768957699577095771957729577395774957759577695777957789577995780957819578295783957849578595786957879578895789957909579195792957939579495795957969579795798957999580095801958029580395804958059580695807958089580995810958119581295813958149581595816958179581895819958209582195822958239582495825958269582795828958299583095831958329583395834958359583695837958389583995840958419584295843958449584595846958479584895849958509585195852958539585495855958569585795858958599586095861958629586395864958659586695867958689586995870958719587295873958749587595876958779587895879958809588195882958839588495885958869588795888958899589095891958929589395894958959589695897958989589995900959019590295903959049590595906959079590895909959109591195912959139591495915959169591795918959199592095921959229592395924959259592695927959289592995930959319593295933959349593595936959379593895939959409594195942959439594495945959469594795948959499595095951959529595395954959559595695957959589595995960959619596295963959649596595966959679596895969959709597195972959739597495975959769597795978959799598095981959829598395984959859598695987959889598995990959919599295993959949599595996959979599895999960009600196002960039600496005960069600796008960099601096011960129601396014960159601696017960189601996020960219602296023960249602596026960279602896029960309603196032960339603496035960369603796038960399604096041960429604396044960459604696047960489604996050960519605296053960549605596056960579605896059960609606196062960639606496065960669606796068960699607096071960729607396074960759607696077960789607996080960819608296083960849608596086960879608896089960909609196092960939609496095960969609796098960999610096101961029610396104961059610696107961089610996110961119611296113961149611596116961179611896119961209612196122961239612496125961269612796128961299613096131961329613396134961359613696137961389613996140961419614296143961449614596146961479614896149961509615196152961539615496155961569615796158961599616096161961629616396164961659616696167961689616996170961719617296173961749617596176961779617896179961809618196182961839618496185961869618796188961899619096191961929619396194961959619696197961989619996200962019620296203962049620596206962079620896209962109621196212962139621496215962169621796218962199622096221962229622396224962259622696227962289622996230962319623296233962349623596236962379623896239962409624196242962439624496245962469624796248962499625096251962529625396254962559625696257962589625996260962619626296263962649626596266962679626896269962709627196272962739627496275962769627796278962799628096281962829628396284962859628696287962889628996290962919629296293962949629596296962979629896299963009630196302963039630496305963069630796308963099631096311963129631396314963159631696317963189631996320963219632296323963249632596326963279632896329963309633196332963339633496335963369633796338963399634096341963429634396344963459634696347963489634996350963519635296353963549635596356963579635896359963609636196362963639636496365963669636796368963699637096371963729637396374963759637696377963789637996380963819638296383963849638596386963879638896389963909639196392963939639496395963969639796398963999640096401964029640396404964059640696407964089640996410964119641296413964149641596416964179641896419964209642196422964239642496425964269642796428964299643096431964329643396434964359643696437964389643996440964419644296443964449644596446964479644896449964509645196452964539645496455964569645796458964599646096461964629646396464964659646696467964689646996470964719647296473964749647596476964779647896479964809648196482964839648496485964869648796488964899649096491964929649396494964959649696497964989649996500965019650296503965049650596506965079650896509965109651196512965139651496515965169651796518965199652096521965229652396524965259652696527965289652996530965319653296533965349653596536965379653896539965409654196542965439654496545965469654796548965499655096551965529655396554965559655696557965589655996560965619656296563965649656596566965679656896569965709657196572965739657496575965769657796578965799658096581965829658396584965859658696587965889658996590965919659296593965949659596596965979659896599966009660196602966039660496605966069660796608966099661096611966129661396614966159661696617966189661996620966219662296623966249662596626966279662896629966309663196632966339663496635966369663796638966399664096641966429664396644966459664696647966489664996650966519665296653966549665596656966579665896659966609666196662966639666496665966669666796668966699667096671966729667396674966759667696677966789667996680966819668296683966849668596686966879668896689966909669196692966939669496695966969669796698966999670096701967029670396704967059670696707967089670996710967119671296713967149671596716967179671896719967209672196722967239672496725967269672796728967299673096731967329673396734967359673696737967389673996740967419674296743967449674596746967479674896749967509675196752967539675496755967569675796758967599676096761967629676396764967659676696767967689676996770967719677296773967749677596776967779677896779967809678196782967839678496785967869678796788967899679096791967929679396794967959679696797967989679996800968019680296803968049680596806968079680896809968109681196812968139681496815968169681796818968199682096821968229682396824968259682696827968289682996830968319683296833968349683596836968379683896839968409684196842968439684496845968469684796848968499685096851968529685396854968559685696857968589685996860968619686296863968649686596866968679686896869968709687196872968739687496875968769687796878968799688096881968829688396884968859688696887968889688996890968919689296893968949689596896968979689896899969009690196902969039690496905969069690796908969099691096911969129691396914969159691696917969189691996920969219692296923969249692596926969279692896929969309693196932969339693496935969369693796938969399694096941969429694396944969459694696947969489694996950969519695296953969549695596956969579695896959969609696196962969639696496965969669696796968
  1. /* api.c API unit tests
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* For AES-CBC, input lengths can optionally be validated to be a
  22. * multiple of the block size, by defining WOLFSSL_AES_CBC_LENGTH_CHECKS,
  23. * also available via the configure option --enable-aescbc-length-checks.
  24. */
  25. /*----------------------------------------------------------------------------*
  26. | Includes
  27. *----------------------------------------------------------------------------*/
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/settings.h>
  32. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  33. #include <wolfssl/wolfcrypt/logging.h>
  34. #include <wolfssl/wolfcrypt/hash.h>
  35. #if defined(WOLFSSL_STATIC_MEMORY)
  36. #include <wolfssl/wolfcrypt/memory.h>
  37. #endif
  38. #ifdef WOLFSSL_ASNC_CRYPT
  39. #include <wolfssl/wolfcrypt/async.h>
  40. #endif
  41. #ifdef HAVE_ECC
  42. #include <wolfssl/wolfcrypt/ecc.h> /* wc_ecc_fp_free */
  43. #ifdef WOLFSSL_SM2
  44. #include <wolfssl/wolfcrypt/sm2.h>
  45. #endif
  46. #endif
  47. #ifndef NO_ASN
  48. #include <wolfssl/wolfcrypt/asn_public.h>
  49. #endif
  50. #include <stdlib.h>
  51. #include <wolfssl/ssl.h> /* compatibility layer */
  52. #include <wolfssl/error-ssl.h>
  53. #include <wolfssl/test.h>
  54. #include <tests/unit.h>
  55. #include <tests/utils.h>
  56. /* for testing compatibility layer callbacks */
  57. #include "examples/server/server.h"
  58. #ifndef NO_MD5
  59. #include <wolfssl/wolfcrypt/md5.h>
  60. #endif
  61. #ifndef NO_SHA
  62. #include <wolfssl/wolfcrypt/sha.h>
  63. #endif
  64. #ifndef NO_SHA256
  65. #include <wolfssl/wolfcrypt/sha256.h>
  66. #endif
  67. #ifdef WOLFSSL_SHA512
  68. #include <wolfssl/wolfcrypt/sha512.h>
  69. #endif
  70. #ifdef WOLFSSL_SHA384
  71. #include <wolfssl/wolfcrypt/sha512.h>
  72. #endif
  73. #ifdef WOLFSSL_SHA3
  74. #include <wolfssl/wolfcrypt/sha3.h>
  75. #endif
  76. #ifdef WOLFSSL_SM3
  77. #include <wolfssl/wolfcrypt/sm3.h>
  78. #endif
  79. #ifndef NO_AES
  80. #include <wolfssl/wolfcrypt/aes.h>
  81. #ifdef HAVE_AES_DECRYPT
  82. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  83. #endif
  84. #endif
  85. #ifdef WOLFSSL_SM4
  86. #include <wolfssl/wolfcrypt/sm4.h>
  87. #endif
  88. #ifdef WOLFSSL_RIPEMD
  89. #include <wolfssl/wolfcrypt/ripemd.h>
  90. #endif
  91. #ifndef NO_DES3
  92. #include <wolfssl/wolfcrypt/des3.h>
  93. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  94. #endif
  95. #ifdef WC_RC2
  96. #include <wolfssl/wolfcrypt/rc2.h>
  97. #endif
  98. #ifndef NO_HMAC
  99. #include <wolfssl/wolfcrypt/hmac.h>
  100. #endif
  101. #ifdef HAVE_CHACHA
  102. #include <wolfssl/wolfcrypt/chacha.h>
  103. #endif
  104. #ifdef HAVE_POLY1305
  105. #include <wolfssl/wolfcrypt/poly1305.h>
  106. #endif
  107. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  108. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  109. #endif
  110. #ifdef HAVE_CAMELLIA
  111. #include <wolfssl/wolfcrypt/camellia.h>
  112. #endif
  113. #ifndef NO_RC4
  114. #include <wolfssl/wolfcrypt/arc4.h>
  115. #endif
  116. #ifdef HAVE_BLAKE2
  117. #include <wolfssl/wolfcrypt/blake2.h>
  118. #endif
  119. #ifndef NO_RSA
  120. #include <wolfssl/wolfcrypt/rsa.h>
  121. #endif
  122. #ifndef NO_SIG_WRAPPER
  123. #include <wolfssl/wolfcrypt/signature.h>
  124. #endif
  125. #ifdef HAVE_AESCCM
  126. #include <wolfssl/wolfcrypt/aes.h>
  127. #endif
  128. #ifdef HAVE_PKCS7
  129. #include <wolfssl/wolfcrypt/pkcs7.h>
  130. #include <wolfssl/wolfcrypt/asn.h>
  131. #ifdef HAVE_LIBZ
  132. #include <wolfssl/wolfcrypt/compress.h>
  133. #endif
  134. #endif
  135. #ifdef WOLFSSL_SMALL_CERT_VERIFY
  136. #include <wolfssl/wolfcrypt/asn.h>
  137. #endif
  138. #ifndef NO_DSA
  139. #include <wolfssl/wolfcrypt/dsa.h>
  140. #endif
  141. #ifdef WOLFSSL_CMAC
  142. #include <wolfssl/wolfcrypt/cmac.h>
  143. #endif
  144. #ifdef HAVE_ED25519
  145. #include <wolfssl/wolfcrypt/ed25519.h>
  146. #endif
  147. #ifdef HAVE_CURVE25519
  148. #include <wolfssl/wolfcrypt/curve25519.h>
  149. #endif
  150. #ifdef HAVE_ED448
  151. #include <wolfssl/wolfcrypt/ed448.h>
  152. #endif
  153. #ifdef HAVE_CURVE448
  154. #include <wolfssl/wolfcrypt/curve448.h>
  155. #endif
  156. #ifdef WOLFSSL_HAVE_KYBER
  157. #include <wolfssl/wolfcrypt/kyber.h>
  158. #ifdef WOLFSSL_WC_KYBER
  159. #include <wolfssl/wolfcrypt/wc_kyber.h>
  160. #endif
  161. #endif
  162. #ifdef HAVE_DILITHIUM
  163. #include <wolfssl/wolfcrypt/dilithium.h>
  164. #endif
  165. #ifdef HAVE_PKCS12
  166. #include <wolfssl/wolfcrypt/pkcs12.h>
  167. #endif
  168. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  169. defined(OPENSSL_ALL)
  170. #include <wolfssl/openssl/ssl.h>
  171. #ifndef NO_ASN
  172. /* for ASN_COMMON_NAME DN_tags enum */
  173. #include <wolfssl/wolfcrypt/asn.h>
  174. #endif
  175. #ifdef HAVE_OCSP
  176. #include <wolfssl/openssl/ocsp.h>
  177. #endif
  178. #endif
  179. #ifdef OPENSSL_EXTRA
  180. #include <wolfssl/openssl/cmac.h>
  181. #include <wolfssl/openssl/x509v3.h>
  182. #include <wolfssl/openssl/asn1.h>
  183. #include <wolfssl/openssl/crypto.h>
  184. #include <wolfssl/openssl/pkcs12.h>
  185. #include <wolfssl/openssl/evp.h>
  186. #include <wolfssl/openssl/dh.h>
  187. #include <wolfssl/openssl/bn.h>
  188. #include <wolfssl/openssl/buffer.h>
  189. #include <wolfssl/openssl/pem.h>
  190. #include <wolfssl/openssl/ec.h>
  191. #include <wolfssl/openssl/ecdh.h>
  192. #include <wolfssl/openssl/engine.h>
  193. #include <wolfssl/openssl/hmac.h>
  194. #include <wolfssl/openssl/objects.h>
  195. #include <wolfssl/openssl/rand.h>
  196. #include <wolfssl/openssl/modes.h>
  197. #include <wolfssl/openssl/fips_rand.h>
  198. #include <wolfssl/openssl/kdf.h>
  199. #ifdef OPENSSL_ALL
  200. #include <wolfssl/openssl/txt_db.h>
  201. #include <wolfssl/openssl/lhash.h>
  202. #endif
  203. #ifndef NO_AES
  204. #include <wolfssl/openssl/aes.h>
  205. #endif
  206. #ifndef NO_DES3
  207. #include <wolfssl/openssl/des.h>
  208. #endif
  209. #ifndef NO_RC4
  210. #include <wolfssl/openssl/rc4.h>
  211. #endif
  212. #ifdef HAVE_ECC
  213. #include <wolfssl/openssl/ecdsa.h>
  214. #endif
  215. #ifdef HAVE_PKCS7
  216. #include <wolfssl/openssl/pkcs7.h>
  217. #endif
  218. #ifdef HAVE_CURVE25519
  219. #include <wolfssl/openssl/ec25519.h>
  220. #endif
  221. #ifdef HAVE_ED25519
  222. #include <wolfssl/openssl/ed25519.h>
  223. #endif
  224. #ifdef HAVE_CURVE448
  225. #include <wolfssl/openssl/ec448.h>
  226. #endif
  227. #ifdef HAVE_ED448
  228. #include <wolfssl/openssl/ed448.h>
  229. #endif
  230. #endif /* OPENSSL_EXTRA */
  231. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  232. !defined(NO_SHA256) && !defined(RC_NO_RNG)
  233. #include <wolfssl/wolfcrypt/srp.h>
  234. #endif
  235. #if (defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)) || \
  236. defined(HAVE_SESSION_TICKET) || (defined(OPENSSL_EXTRA) && \
  237. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)) || \
  238. defined(WOLFSSL_TEST_STATIC_BUILD) || defined(WOLFSSL_DTLS) || \
  239. defined(HAVE_ECH) || defined(HAVE_EX_DATA) || !defined(NO_SESSION_CACHE) \
  240. || !defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13)
  241. /* for testing SSL_get_peer_cert_chain, or SESSION_TICKET_HINT_DEFAULT,
  242. * for setting authKeyIdSrc in WOLFSSL_X509, or testing DTLS sequence
  243. * number tracking */
  244. #include "wolfssl/internal.h"
  245. #endif
  246. /* force enable test buffers */
  247. #ifndef USE_CERT_BUFFERS_2048
  248. #define USE_CERT_BUFFERS_2048
  249. #endif
  250. #ifndef USE_CERT_BUFFERS_256
  251. #define USE_CERT_BUFFERS_256
  252. #endif
  253. #include <wolfssl/certs_test.h>
  254. /* include misc.c here regardless of NO_INLINE, because misc.c implementations
  255. * have default (hidden) visibility, and in the absence of visibility, it's
  256. * benign to mask out the library implementation.
  257. */
  258. #define WOLFSSL_MISC_INCLUDED
  259. #include <wolfcrypt/src/misc.c>
  260. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  261. !defined(NO_RSA) && !defined(SINGLE_THREADED) && \
  262. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  263. #define HAVE_IO_TESTS_DEPENDENCIES
  264. #endif
  265. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  266. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  267. !defined(WOLFSSL_TIRTOS)
  268. #define HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  269. #endif
  270. #if !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_FILESYSTEM) && \
  271. !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  272. !defined(WOLFSSL_NO_CLIENT_AUTH))
  273. #define HAVE_CERT_CHAIN_VALIDATION
  274. #endif
  275. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  276. /* FIPS build has replaced ecc.h. */
  277. #define wc_ecc_key_get_priv(key) (&((key)->k))
  278. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  279. #endif
  280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  281. #if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || defined(SESSION_CERTS)
  282. #ifdef OPENSSL_EXTRA
  283. #define TEST_TLS_STATIC_MEMSZ (400000)
  284. #else
  285. #define TEST_TLS_STATIC_MEMSZ (320000)
  286. #endif
  287. #else
  288. #define TEST_TLS_STATIC_MEMSZ (80000)
  289. #endif
  290. #endif
  291. #ifdef HAVE_ECC
  292. #ifndef ECC_ASN963_MAX_BUF_SZ
  293. #define ECC_ASN963_MAX_BUF_SZ 133
  294. #endif
  295. #ifndef ECC_PRIV_KEY_BUF
  296. #define ECC_PRIV_KEY_BUF 66 /* For non user defined curves. */
  297. #endif
  298. /* ecc key sizes: 14, 16, 20, 24, 28, 30, 32, 40, 48, 64 */
  299. /* logic to choose right key ECC size */
  300. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  301. #define KEY14 14
  302. #else
  303. #define KEY14 32
  304. #endif
  305. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  306. #define KEY16 16
  307. #else
  308. #define KEY16 32
  309. #endif
  310. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  311. #define KEY20 20
  312. #else
  313. #define KEY20 32
  314. #endif
  315. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  316. #define KEY24 24
  317. #else
  318. #define KEY24 32
  319. #endif
  320. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  321. #define KEY28 28
  322. #else
  323. #define KEY28 32
  324. #endif
  325. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  326. #define KEY30 30
  327. #else
  328. #define KEY30 32
  329. #endif
  330. #define KEY32 32
  331. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  332. #define KEY40 40
  333. #else
  334. #define KEY40 32
  335. #endif
  336. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  337. #define KEY48 48
  338. #else
  339. #define KEY48 32
  340. #endif
  341. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  342. #define KEY64 64
  343. #else
  344. #define KEY64 32
  345. #endif
  346. #if !defined(HAVE_COMP_KEY)
  347. #if !defined(NOCOMP)
  348. #define NOCOMP 0
  349. #endif
  350. #else
  351. #if !defined(COMP)
  352. #define COMP 1
  353. #endif
  354. #endif
  355. #if !defined(DER_SZ)
  356. #define DER_SZ(ks) ((ks) * 2 + 1)
  357. #endif
  358. #endif /* HAVE_ECC */
  359. #ifndef NO_DSA
  360. #ifndef DSA_SIG_SIZE
  361. #define DSA_SIG_SIZE 40
  362. #endif
  363. #ifndef MAX_DSA_PARAM_SIZE
  364. #define MAX_DSA_PARAM_SIZE 256
  365. #endif
  366. #endif
  367. #ifndef NO_RSA
  368. #define GEN_BUF 294
  369. #endif
  370. #ifndef ONEK_BUF
  371. #define ONEK_BUF 1024
  372. #endif
  373. #ifndef TWOK_BUF
  374. #define TWOK_BUF 2048
  375. #endif
  376. #ifndef FOURK_BUF
  377. #define FOURK_BUF 4096
  378. #endif
  379. #ifndef HEAP_HINT
  380. #define HEAP_HINT NULL
  381. #endif
  382. typedef struct testVector {
  383. const char* input;
  384. const char* output;
  385. size_t inLen;
  386. size_t outLen;
  387. } testVector;
  388. #if defined(HAVE_PKCS7)
  389. typedef struct {
  390. const byte* content;
  391. word32 contentSz;
  392. int contentOID;
  393. int encryptOID;
  394. int keyWrapOID;
  395. int keyAgreeOID;
  396. byte* cert;
  397. size_t certSz;
  398. byte* privateKey;
  399. word32 privateKeySz;
  400. } pkcs7EnvelopedVector;
  401. #ifndef NO_PKCS7_ENCRYPTED_DATA
  402. typedef struct {
  403. const byte* content;
  404. word32 contentSz;
  405. int contentOID;
  406. int encryptOID;
  407. byte* encryptionKey;
  408. word32 encryptionKeySz;
  409. } pkcs7EncryptedVector;
  410. #endif
  411. #endif /* HAVE_PKCS7 */
  412. typedef int (*ctx_cb)(WOLFSSL_CTX* ctx);
  413. typedef int (*ssl_cb)(WOLFSSL* ssl);
  414. typedef int (*test_cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
  415. typedef int (*hs_cb)(WOLFSSL_CTX **ctx, WOLFSSL **ssl);
  416. typedef struct test_ssl_cbf {
  417. method_provider method;
  418. ctx_cb ctx_ready;
  419. ssl_cb ssl_ready;
  420. ssl_cb on_result;
  421. ctx_cb on_ctx_cleanup;
  422. ssl_cb on_cleanup;
  423. hs_cb on_handshake;
  424. WOLFSSL_CTX* ctx;
  425. const char* caPemFile;
  426. const char* certPemFile;
  427. const char* keyPemFile;
  428. const char* crlPemFile;
  429. #ifdef WOLFSSL_STATIC_MEMORY
  430. byte* mem;
  431. word32 memSz;
  432. wolfSSL_method_func method_ex;
  433. #endif
  434. int devId;
  435. int return_code;
  436. int last_err;
  437. unsigned char isSharedCtx:1;
  438. unsigned char loadToSSL:1;
  439. unsigned char ticNoInit:1;
  440. unsigned char doUdp:1;
  441. } test_ssl_cbf;
  442. #define TEST_SSL_MEMIO_BUF_SZ (64 * 1024)
  443. typedef struct test_ssl_memio_ctx {
  444. WOLFSSL_CTX* s_ctx;
  445. WOLFSSL_CTX* c_ctx;
  446. WOLFSSL* s_ssl;
  447. WOLFSSL* c_ssl;
  448. const char* c_ciphers;
  449. const char* s_ciphers;
  450. char* c_msg;
  451. int c_msglen;
  452. char* s_msg;
  453. int s_msglen;
  454. test_ssl_cbf s_cb;
  455. test_ssl_cbf c_cb;
  456. byte c_buff[TEST_SSL_MEMIO_BUF_SZ];
  457. int c_len;
  458. byte s_buff[TEST_SSL_MEMIO_BUF_SZ];
  459. int s_len;
  460. } test_ssl_memio_ctx;
  461. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  462. test_ssl_cbf* server_cb, test_cbType client_on_handshake);
  463. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  464. const char* currentTestName;
  465. char tmpDirName[16];
  466. int tmpDirNameSet = 0;
  467. #endif
  468. /*----------------------------------------------------------------------------*
  469. | Constants
  470. *----------------------------------------------------------------------------*/
  471. /* Returns the result based on whether check is true.
  472. *
  473. * @param [in] check Condition for success.
  474. * @return When condition is true: TEST_SUCCESS.
  475. * @return When condition is false: TEST_FAIL.
  476. */
  477. #ifdef DEBUG_WOLFSSL_VERBOSE
  478. #define XSTRINGIFY(s) STRINGIFY(s)
  479. #define STRINGIFY(s) #s
  480. #define TEST_RES_CHECK(check) ({ \
  481. int _ret = (check) ? TEST_SUCCESS : TEST_FAIL; \
  482. if (_ret == TEST_FAIL) { \
  483. fprintf(stderr, " check \"%s\" at %d ", \
  484. XSTRINGIFY(check), __LINE__); \
  485. } \
  486. _ret; })
  487. #else
  488. #define TEST_RES_CHECK(check) \
  489. ((check) ? TEST_SUCCESS : TEST_FAIL)
  490. #endif /* DEBUG_WOLFSSL_VERBOSE */
  491. #define TEST_STRING "Everyone gets Friday off."
  492. #define TEST_STRING_SZ 25
  493. #ifndef NO_RSA
  494. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  495. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  496. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  497. #define TEST_RSA_BITS 1024
  498. #else
  499. #define TEST_RSA_BITS 2048
  500. #endif
  501. #define TEST_RSA_BYTES (TEST_RSA_BITS/8)
  502. #endif /* !NO_RSA */
  503. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  504. (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
  505. static const char* bogusFile =
  506. #ifdef _WIN32
  507. "NUL"
  508. #else
  509. "/dev/null"
  510. #endif
  511. ;
  512. #endif /* !NO_FILESYSTEM && !NO_CERTS && (!NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT) */
  513. enum {
  514. TESTING_RSA = 1,
  515. TESTING_ECC = 2
  516. };
  517. #ifdef WOLFSSL_QNX_CAAM
  518. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  519. static int testDevId = WOLFSSL_CAAM_DEVID;
  520. #else
  521. static int testDevId = INVALID_DEVID;
  522. #endif
  523. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  524. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  525. /* This set of memio functions allows for more fine tuned control of the TLS
  526. * connection operations. For new tests, try to use ssl_memio first. */
  527. /* To dump the memory in gdb use
  528. * dump memory client.bin test_ctx.c_buff test_ctx.c_buff+test_ctx.c_len
  529. * dump memory server.bin test_ctx.s_buff test_ctx.s_buff+test_ctx.s_len
  530. * This can be imported into Wireshark by transforming the file with
  531. * od -Ax -tx1 -v client.bin > client.bin.hex
  532. * od -Ax -tx1 -v server.bin > server.bin.hex
  533. * And then loading test_output.dump.hex into Wireshark using the
  534. * "Import from Hex Dump..." option ion and selecting the TCP
  535. * encapsulation option.
  536. */
  537. #define HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES
  538. static WC_INLINE int test_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  539. void *ctx)
  540. {
  541. struct test_memio_ctx *test_ctx;
  542. byte *buf;
  543. int *len;
  544. test_ctx = (struct test_memio_ctx*)ctx;
  545. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  546. buf = test_ctx->c_buff;
  547. len = &test_ctx->c_len;
  548. }
  549. else {
  550. buf = test_ctx->s_buff;
  551. len = &test_ctx->s_len;
  552. }
  553. if ((unsigned)(*len + sz) > TEST_MEMIO_BUF_SZ)
  554. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  555. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  556. {
  557. char dump_file_name[64];
  558. WOLFSSL_BIO *dump_file;
  559. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  560. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  561. if (dump_file != NULL) {
  562. (void)wolfSSL_BIO_write(dump_file, data, sz);
  563. wolfSSL_BIO_free(dump_file);
  564. }
  565. }
  566. #endif
  567. XMEMCPY(buf + *len, data, (size_t)sz);
  568. *len += sz;
  569. return sz;
  570. }
  571. static WC_INLINE int test_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  572. void *ctx)
  573. {
  574. struct test_memio_ctx *test_ctx;
  575. int read_sz;
  576. byte *buf;
  577. int *len;
  578. test_ctx = (struct test_memio_ctx*)ctx;
  579. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  580. buf = test_ctx->s_buff;
  581. len = &test_ctx->s_len;
  582. }
  583. else {
  584. buf = test_ctx->c_buff;
  585. len = &test_ctx->c_len;
  586. }
  587. if (*len == 0)
  588. return WOLFSSL_CBIO_ERR_WANT_READ;
  589. read_sz = sz < *len ? sz : *len;
  590. XMEMCPY(data, buf, (size_t)read_sz);
  591. XMEMMOVE(buf, buf + read_sz,(size_t) (*len - read_sz));
  592. *len -= read_sz;
  593. return read_sz;
  594. }
  595. int test_memio_do_handshake(WOLFSSL *ssl_c, WOLFSSL *ssl_s,
  596. int max_rounds, int *rounds)
  597. {
  598. byte handshake_complete = 0, hs_c = 0, hs_s = 0;
  599. int ret, err;
  600. if (rounds != NULL)
  601. *rounds = 0;
  602. while (!handshake_complete && max_rounds > 0) {
  603. if (!hs_c) {
  604. wolfSSL_SetLoggingPrefix("client");
  605. ret = wolfSSL_connect(ssl_c);
  606. wolfSSL_SetLoggingPrefix(NULL);
  607. if (ret == WOLFSSL_SUCCESS) {
  608. hs_c = 1;
  609. }
  610. else {
  611. err = wolfSSL_get_error(ssl_c, ret);
  612. if (err != WOLFSSL_ERROR_WANT_READ &&
  613. err != WOLFSSL_ERROR_WANT_WRITE)
  614. return -1;
  615. }
  616. }
  617. if (!hs_s) {
  618. wolfSSL_SetLoggingPrefix("server");
  619. ret = wolfSSL_accept(ssl_s);
  620. wolfSSL_SetLoggingPrefix(NULL);
  621. if (ret == WOLFSSL_SUCCESS) {
  622. hs_s = 1;
  623. }
  624. else {
  625. err = wolfSSL_get_error(ssl_s, ret);
  626. if (err != WOLFSSL_ERROR_WANT_READ &&
  627. err != WOLFSSL_ERROR_WANT_WRITE)
  628. return -1;
  629. }
  630. }
  631. handshake_complete = hs_c && hs_s;
  632. max_rounds--;
  633. if (rounds != NULL)
  634. *rounds = *rounds + 1;
  635. }
  636. if (!handshake_complete)
  637. return -1;
  638. return 0;
  639. }
  640. int test_memio_setup_ex(struct test_memio_ctx *ctx,
  641. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  642. method_provider method_c, method_provider method_s,
  643. byte *caCert, int caCertSz, byte *serverCert, int serverCertSz,
  644. byte *serverKey, int serverKeySz)
  645. {
  646. int ret;
  647. (void)caCert;
  648. (void)caCertSz;
  649. (void)serverCert;
  650. (void)serverCertSz;
  651. (void)serverKey;
  652. (void)serverKeySz;
  653. if (ctx_c != NULL && *ctx_c == NULL) {
  654. *ctx_c = wolfSSL_CTX_new(method_c());
  655. if (*ctx_c == NULL)
  656. return -1;
  657. #ifndef NO_CERTS
  658. if (caCert == NULL) {
  659. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  660. }
  661. else {
  662. ret = wolfSSL_CTX_load_verify_buffer(*ctx_c, caCert, (long)caCertSz,
  663. WOLFSSL_FILETYPE_ASN1);
  664. }
  665. if (ret != WOLFSSL_SUCCESS)
  666. return -1;
  667. #endif /* NO_CERTS */
  668. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  669. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  670. if (ctx->c_ciphers != NULL) {
  671. ret = wolfSSL_CTX_set_cipher_list(*ctx_c, ctx->c_ciphers);
  672. if (ret != WOLFSSL_SUCCESS)
  673. return -1;
  674. }
  675. }
  676. if (ctx_s != NULL && *ctx_s == NULL) {
  677. *ctx_s = wolfSSL_CTX_new(method_s());
  678. if (*ctx_s == NULL)
  679. return -1;
  680. #ifndef NO_CERTS
  681. if (serverKey == NULL) {
  682. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, svrKeyFile,
  683. WOLFSSL_FILETYPE_PEM);
  684. }
  685. else {
  686. ret = wolfSSL_CTX_use_PrivateKey_buffer(*ctx_s, serverKey,
  687. (long)serverKeySz, WOLFSSL_FILETYPE_ASN1);
  688. }
  689. if (ret != WOLFSSL_SUCCESS)
  690. return- -1;
  691. if (serverCert == NULL) {
  692. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, svrCertFile,
  693. WOLFSSL_FILETYPE_PEM);
  694. }
  695. else {
  696. ret = wolfSSL_CTX_use_certificate_chain_buffer_format(*ctx_s,
  697. serverCert, (long)serverCertSz, WOLFSSL_FILETYPE_ASN1);
  698. }
  699. if (ret != WOLFSSL_SUCCESS)
  700. return -1;
  701. #endif /* NO_CERTS */
  702. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  703. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  704. if (ctx->s_ciphers != NULL) {
  705. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  706. if (ret != WOLFSSL_SUCCESS)
  707. return -1;
  708. }
  709. }
  710. if (ctx_c != NULL && ssl_c != NULL) {
  711. *ssl_c = wolfSSL_new(*ctx_c);
  712. if (*ssl_c == NULL)
  713. return -1;
  714. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  715. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  716. }
  717. if (ctx_s != NULL && ssl_s != NULL) {
  718. *ssl_s = wolfSSL_new(*ctx_s);
  719. if (*ssl_s == NULL)
  720. return -1;
  721. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  722. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  723. #if !defined(NO_DH)
  724. SetDH(*ssl_s);
  725. #endif
  726. }
  727. return 0;
  728. }
  729. int test_memio_setup(struct test_memio_ctx *ctx,
  730. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  731. method_provider method_c, method_provider method_s)
  732. {
  733. return test_memio_setup_ex(ctx, ctx_c, ctx_s, ssl_c, ssl_s, method_c,
  734. method_s, NULL, 0, NULL, 0, NULL, 0);
  735. }
  736. #endif
  737. /*----------------------------------------------------------------------------*
  738. | BIO with fixed read/write size
  739. *----------------------------------------------------------------------------*/
  740. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  741. static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data,
  742. int len)
  743. {
  744. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  745. len = 0;
  746. }
  747. else {
  748. if (bio->wrSz - bio->wrIdx < len) {
  749. len = bio->wrSz - bio->wrIdx;
  750. }
  751. XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len);
  752. bio->wrIdx += len;
  753. }
  754. return len;
  755. }
  756. static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len)
  757. {
  758. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  759. len = 0;
  760. }
  761. else {
  762. if (bio->wrSz - bio->rdIdx < len) {
  763. len = bio->wrSz - bio->rdIdx;
  764. }
  765. XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len);
  766. bio->rdIdx += len;
  767. }
  768. return len;
  769. }
  770. static WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void)
  771. {
  772. static WOLFSSL_BIO_METHOD meth;
  773. meth.type = WOLFSSL_BIO_BIO;
  774. XMEMCPY(meth.name, "Fixed Memory Size", 18);
  775. meth.writeCb = wolfssl_bio_s_fixed_mem_write;
  776. meth.readCb = wolfssl_bio_s_fixed_mem_read;
  777. return &meth;
  778. }
  779. #endif
  780. /*----------------------------------------------------------------------------*
  781. | Setup
  782. *----------------------------------------------------------------------------*/
  783. static int test_wolfSSL_Init(void)
  784. {
  785. EXPECT_DECLS;
  786. ExpectIntEQ(wolfSSL_Init(), WOLFSSL_SUCCESS);
  787. return EXPECT_RESULT();
  788. }
  789. static int test_wolfSSL_Cleanup(void)
  790. {
  791. EXPECT_DECLS;
  792. ExpectIntEQ(wolfSSL_Cleanup(), WOLFSSL_SUCCESS);
  793. return EXPECT_RESULT();
  794. }
  795. /* Initialize the wolfCrypt state.
  796. * POST: 0 success.
  797. */
  798. static int test_wolfCrypt_Init(void)
  799. {
  800. EXPECT_DECLS;
  801. ExpectIntEQ(wolfCrypt_Init(), 0);
  802. return EXPECT_RESULT();
  803. } /* END test_wolfCrypt_Init */
  804. static int test_wolfCrypt_Cleanup(void)
  805. {
  806. EXPECT_DECLS;
  807. ExpectIntEQ(wolfCrypt_Cleanup(), 0);
  808. return EXPECT_RESULT();
  809. }
  810. #ifdef WOLFSSL_STATIC_MEMORY
  811. #define TEST_LSM_STATIC_SIZE 440000
  812. /* Create new bucket list, using the default list, adding
  813. * one dang large buffer size. */
  814. #define TEST_LSM_DEF_BUCKETS (WOLFMEM_DEF_BUCKETS+1)
  815. #define TEST_LSM_BUCKETS WOLFMEM_BUCKETS,(LARGEST_MEM_BUCKET*2)
  816. #define TEST_LSM_DIST WOLFMEM_DIST,1
  817. #endif
  818. static int test_wc_LoadStaticMemory_ex(void)
  819. {
  820. EXPECT_DECLS;
  821. #ifdef WOLFSSL_STATIC_MEMORY
  822. byte staticMemory[TEST_LSM_STATIC_SIZE];
  823. word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
  824. word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
  825. WOLFSSL_HEAP_HINT* heap;
  826. /* For this test, the size and dist lists will be the ones configured
  827. * for the build, or default. The value of WOLFMEM_DEF_BUCKETS is 9,
  828. * so these lists are 10 long. For most tests, the value of
  829. * WOLFMEM_DEF_BUCKETS is used. There's a test case where one is added
  830. * to that, to make sure the list size is larger than
  831. * WOLFMEM_MAX_BUCKETS. */
  832. /* Pass in zero everything. */
  833. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
  834. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  835. /* Set the heap pointer to NULL. */
  836. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
  837. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  838. staticMemory, (word32)sizeof(staticMemory),
  839. 0, 1),
  840. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  841. /* Set other pointer values to NULL one at a time. */
  842. heap = NULL;
  843. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  844. WOLFMEM_DEF_BUCKETS, NULL, distList,
  845. staticMemory, (word32)sizeof(staticMemory),
  846. 0, 1),
  847. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  848. heap = NULL;
  849. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  850. WOLFMEM_DEF_BUCKETS, sizeList, NULL,
  851. staticMemory, (word32)sizeof(staticMemory),
  852. 0, 1),
  853. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  854. heap = NULL;
  855. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  856. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  857. NULL, (word32)sizeof(staticMemory),
  858. 0, 1),
  859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  860. /* Set the size of the static buffer to 0. */
  861. heap = NULL;
  862. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  863. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  864. staticMemory, 0,
  865. 0, 1),
  866. WC_NO_ERR_TRACE(BUFFER_E));
  867. /* Set the size of the static buffer to one less than minimum allowed. */
  868. heap = NULL;
  869. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  870. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  871. staticMemory,
  872. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
  873. 0, 1),
  874. WC_NO_ERR_TRACE(BUFFER_E));
  875. /* Set the size of the static buffer to exactly the minimum size. */
  876. heap = NULL;
  877. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  878. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  879. staticMemory,
  880. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
  881. 0, 1),
  882. 0);
  883. wc_UnloadStaticMemory(heap);
  884. /* Use more buckets than able. Success case. */
  885. heap = NULL;
  886. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  887. WOLFMEM_DEF_BUCKETS*2, sizeList, distList,
  888. staticMemory, (word32)sizeof(staticMemory),
  889. 0, 1),
  890. 0);
  891. wc_UnloadStaticMemory(heap);
  892. /* Success case. */
  893. heap = NULL;
  894. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  895. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  896. staticMemory, (word32)sizeof(staticMemory),
  897. 0, 1),
  898. 0);
  899. wc_UnloadStaticMemory(heap);
  900. #endif /* WOLFSSL_STATIC_MEMORY */
  901. return EXPECT_RESULT();
  902. }
  903. /*----------------------------------------------------------------------------*
  904. | Platform dependent function test
  905. *----------------------------------------------------------------------------*/
  906. static int test_fileAccess(void)
  907. {
  908. EXPECT_DECLS;
  909. #if defined(WOLFSSL_TEST_PLATFORMDEPEND) && !defined(NO_FILESYSTEM)
  910. const char *fname[] = {
  911. svrCertFile, svrKeyFile, caCertFile,
  912. eccCertFile, eccKeyFile, eccRsaCertFile,
  913. cliCertFile, cliCertDerFile, cliKeyFile,
  914. dhParamFile,
  915. cliEccKeyFile, cliEccCertFile, caEccCertFile, edCertFile, edKeyFile,
  916. cliEdCertFile, cliEdKeyFile, caEdCertFile,
  917. NULL
  918. };
  919. const char derfile[] = "./certs/server-cert.der";
  920. XFILE f = XBADFILE;
  921. size_t sz;
  922. byte *buff = NULL;
  923. int i;
  924. ExpectTrue(XFOPEN("badfilename", "rb") == XBADFILE);
  925. for (i=0; EXPECT_SUCCESS() && fname[i] != NULL ; i++) {
  926. ExpectTrue((f = XFOPEN(fname[i], "rb")) != XBADFILE);
  927. XFCLOSE(f);
  928. }
  929. ExpectTrue((f = XFOPEN(derfile, "rb")) != XBADFILE);
  930. ExpectTrue(XFSEEK(f, 0, XSEEK_END) == 0);
  931. ExpectIntGE(sz = (size_t) XFTELL(f), sizeof_server_cert_der_2048);
  932. ExpectTrue(XFSEEK(f, 0, XSEEK_SET) == 0);
  933. ExpectTrue((buff = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE)) != NULL);
  934. ExpectTrue(XFREAD(buff, 1, sz, f) == sz);
  935. ExpectIntEQ(XMEMCMP(server_cert_der_2048, buff, sz), 0);
  936. XFREE(buff, NULL, DYNAMIC_TYPE_FILE);
  937. XFCLOSE(f);
  938. #endif
  939. return EXPECT_RESULT();
  940. }
  941. /*----------------------------------------------------------------------------*
  942. | Method Allocators
  943. *----------------------------------------------------------------------------*/
  944. static int test_wolfSSL_Method_Allocators(void)
  945. {
  946. EXPECT_DECLS;
  947. #define TEST_METHOD_ALLOCATOR(allocator, condition) \
  948. do { \
  949. WOLFSSL_METHOD *method = NULL; \
  950. condition(method = allocator()); \
  951. XFREE(method, 0, DYNAMIC_TYPE_METHOD); \
  952. } while (0)
  953. #define TEST_VALID_METHOD_ALLOCATOR(a) \
  954. TEST_METHOD_ALLOCATOR(a, ExpectNotNull)
  955. #define TEST_INVALID_METHOD_ALLOCATOR(a) \
  956. TEST_METHOD_ALLOCATOR(a, ExpectNull)
  957. #ifndef NO_OLD_TLS
  958. #ifdef WOLFSSL_ALLOW_SSLV3
  959. #ifndef NO_WOLFSSL_SERVER
  960. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_server_method);
  961. #endif
  962. #ifndef NO_WOLFSSL_CLIENT
  963. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_client_method);
  964. #endif
  965. #endif
  966. #ifdef WOLFSSL_ALLOW_TLSV10
  967. #ifndef NO_WOLFSSL_SERVER
  968. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_server_method);
  969. #endif
  970. #ifndef NO_WOLFSSL_CLIENT
  971. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_client_method);
  972. #endif
  973. #endif
  974. #ifndef NO_WOLFSSL_SERVER
  975. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_server_method);
  976. #endif
  977. #ifndef NO_WOLFSSL_CLIENT
  978. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_client_method);
  979. #endif
  980. #endif /* !NO_OLD_TLS */
  981. #ifndef WOLFSSL_NO_TLS12
  982. #ifndef NO_WOLFSSL_SERVER
  983. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_server_method);
  984. #endif
  985. #ifndef NO_WOLFSSL_CLIENT
  986. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_client_method);
  987. #endif
  988. #endif /* !WOLFSSL_NO_TLS12 */
  989. #ifdef WOLFSSL_TLS13
  990. #ifndef NO_WOLFSSL_SERVER
  991. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_server_method);
  992. #endif
  993. #ifndef NO_WOLFSSL_CLIENT
  994. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_client_method);
  995. #endif
  996. #endif /* WOLFSSL_TLS13 */
  997. #ifndef NO_WOLFSSL_SERVER
  998. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_server_method);
  999. #endif
  1000. #ifndef NO_WOLFSSL_CLIENT
  1001. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_client_method);
  1002. #endif
  1003. #ifdef WOLFSSL_DTLS
  1004. #ifndef NO_OLD_TLS
  1005. #ifndef NO_WOLFSSL_SERVER
  1006. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_server_method);
  1007. #endif
  1008. #ifndef NO_WOLFSSL_CLIENT
  1009. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_client_method);
  1010. #endif
  1011. #endif
  1012. #ifndef WOLFSSL_NO_TLS12
  1013. #ifndef NO_WOLFSSL_SERVER
  1014. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_server_method);
  1015. #endif
  1016. #ifndef NO_WOLFSSL_CLIENT
  1017. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_client_method);
  1018. #endif
  1019. #endif
  1020. #endif /* WOLFSSL_DTLS */
  1021. #if !defined(NO_OLD_TLS) && defined(OPENSSL_EXTRA)
  1022. /* Stubs */
  1023. #ifndef NO_WOLFSSL_SERVER
  1024. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_server_method);
  1025. #endif
  1026. #ifndef NO_WOLFSSL_CLIENT
  1027. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_client_method);
  1028. #endif
  1029. #endif
  1030. /* Test Either Method (client or server) */
  1031. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  1032. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_method);
  1033. #ifndef NO_OLD_TLS
  1034. #ifdef WOLFSSL_ALLOW_TLSV10
  1035. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_method);
  1036. #endif
  1037. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_method);
  1038. #endif /* !NO_OLD_TLS */
  1039. #ifndef WOLFSSL_NO_TLS12
  1040. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_method);
  1041. #endif /* !WOLFSSL_NO_TLS12 */
  1042. #ifdef WOLFSSL_TLS13
  1043. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_method);
  1044. #endif /* WOLFSSL_TLS13 */
  1045. #ifdef WOLFSSL_DTLS
  1046. TEST_VALID_METHOD_ALLOCATOR(wolfDTLS_method);
  1047. #ifndef NO_OLD_TLS
  1048. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_method);
  1049. #endif /* !NO_OLD_TLS */
  1050. #ifndef WOLFSSL_NO_TLS12
  1051. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_method);
  1052. #endif /* !WOLFSSL_NO_TLS12 */
  1053. #ifdef WOLFSSL_DTLS13
  1054. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_3_method);
  1055. #endif /* WOLFSSL_DTLS13 */
  1056. #endif /* WOLFSSL_DTLS */
  1057. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  1058. return EXPECT_RESULT();
  1059. }
  1060. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  1061. /*----------------------------------------------------------------------------*
  1062. | Dual algorithm Certificate Tests
  1063. *----------------------------------------------------------------------------*/
  1064. #define LARGE_TEMP_SZ 4096
  1065. /* To better understand this, please see the X9.146 example in wolfssl-examples
  1066. * repo. */
  1067. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  1068. char *sapkiFile, char *altPrivFile)
  1069. {
  1070. EXPECT_DECLS;
  1071. FILE* file = NULL;
  1072. Cert newCert;
  1073. DecodedCert preTBS;
  1074. byte caKeyBuf[LARGE_TEMP_SZ];
  1075. word32 caKeySz = LARGE_TEMP_SZ;
  1076. byte sapkiBuf[LARGE_TEMP_SZ];
  1077. word32 sapkiSz = LARGE_TEMP_SZ;
  1078. byte altPrivBuf[LARGE_TEMP_SZ];
  1079. word32 altPrivSz = LARGE_TEMP_SZ;
  1080. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1081. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1082. byte scratchBuf[LARGE_TEMP_SZ];
  1083. word32 scratchSz = LARGE_TEMP_SZ;
  1084. byte preTbsBuf[LARGE_TEMP_SZ];
  1085. word32 preTbsSz = LARGE_TEMP_SZ;
  1086. byte altSigValBuf[LARGE_TEMP_SZ];
  1087. word32 altSigValSz = LARGE_TEMP_SZ;
  1088. byte *outBuf = NULL;
  1089. word32 outSz = LARGE_TEMP_SZ;
  1090. WC_RNG rng;
  1091. RsaKey caKey;
  1092. ecc_key altCaKey;
  1093. word32 idx = 0;
  1094. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1095. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1096. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1097. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1098. DYNAMIC_TYPE_TMP_BUFFER));
  1099. ExpectIntEQ(wc_InitRng(&rng), 0);
  1100. XMEMSET(caKeyBuf, 0, caKeySz);
  1101. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1102. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1103. if (file) {
  1104. fclose(file);
  1105. file = NULL;
  1106. }
  1107. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1108. idx = 0;
  1109. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  1110. 0);
  1111. XMEMSET(sapkiBuf, 0, sapkiSz);
  1112. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1113. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1114. if (file) {
  1115. fclose(file);
  1116. file = NULL;
  1117. }
  1118. XMEMSET(altPrivBuf, 0, altPrivSz);
  1119. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1120. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1121. if (file) {
  1122. fclose(file);
  1123. file = NULL;
  1124. }
  1125. wc_ecc_init(&altCaKey);
  1126. idx = 0;
  1127. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1128. (word32)altPrivSz), 0);
  1129. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1130. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1131. oidSigType, 0), 0);
  1132. wc_InitCert(&newCert);
  1133. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1134. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1135. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1136. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1137. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1138. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1139. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  1140. newCert.sigType = CTC_SHA256wRSA;
  1141. newCert.isCA = 1;
  1142. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  1143. (const byte *)"This is NOT a critical extension", 32), 0);
  1144. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1145. sapkiSz), 0);
  1146. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1147. altSigAlgSz), 0);
  1148. XMEMSET(scratchBuf, 0, scratchSz);
  1149. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  1150. &caKey, &rng), 0);
  1151. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1152. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1153. XMEMSET(preTbsBuf, 0, preTbsSz);
  1154. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1155. XMEMSET(altSigValBuf, 0, altSigValSz);
  1156. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1157. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1158. &rng), 0);
  1159. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  1160. altSigValSz), 0);
  1161. /* Finally, generate the new certificate. */
  1162. if (outBuf != NULL) {
  1163. XMEMSET(outBuf, 0, outSz);
  1164. }
  1165. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  1166. 0);
  1167. *out = outBuf;
  1168. wc_FreeRsaKey(&caKey);
  1169. wc_FreeRng(&rng);
  1170. wc_FreeDecodedCert(&preTBS);
  1171. return outSz;
  1172. }
  1173. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  1174. char *sapkiFile, char *altPrivFile,
  1175. char *serverKeyFile,
  1176. byte *caCertBuf, int caCertSz)
  1177. {
  1178. EXPECT_DECLS;
  1179. FILE* file = NULL;
  1180. Cert newCert;
  1181. DecodedCert preTBS;
  1182. byte serverKeyBuf[LARGE_TEMP_SZ];
  1183. word32 serverKeySz = LARGE_TEMP_SZ;
  1184. byte caKeyBuf[LARGE_TEMP_SZ];
  1185. word32 caKeySz = LARGE_TEMP_SZ;
  1186. byte sapkiBuf[LARGE_TEMP_SZ];
  1187. word32 sapkiSz = LARGE_TEMP_SZ;
  1188. byte altPrivBuf[LARGE_TEMP_SZ];
  1189. word32 altPrivSz = LARGE_TEMP_SZ;
  1190. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1191. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1192. byte scratchBuf[LARGE_TEMP_SZ];
  1193. word32 scratchSz = LARGE_TEMP_SZ;
  1194. byte preTbsBuf[LARGE_TEMP_SZ];
  1195. word32 preTbsSz = LARGE_TEMP_SZ;
  1196. byte altSigValBuf[LARGE_TEMP_SZ];
  1197. word32 altSigValSz = LARGE_TEMP_SZ;
  1198. byte *outBuf = NULL;
  1199. word32 outSz = LARGE_TEMP_SZ;
  1200. WC_RNG rng;
  1201. RsaKey caKey;
  1202. RsaKey serverKey;
  1203. ecc_key altCaKey;
  1204. word32 idx = 0;
  1205. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1206. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1207. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  1208. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1209. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1210. DYNAMIC_TYPE_TMP_BUFFER));
  1211. ExpectIntEQ(wc_InitRng(&rng), 0);
  1212. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1213. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1214. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1215. 0);
  1216. if (file) {
  1217. fclose(file);
  1218. file = NULL;
  1219. }
  1220. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1221. idx = 0;
  1222. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1223. (word32)serverKeySz), 0);
  1224. XMEMSET(caKeyBuf, 0, caKeySz);
  1225. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1226. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1227. if (file) {
  1228. fclose(file);
  1229. file = NULL;
  1230. }
  1231. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1232. idx = 0;
  1233. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1234. (word32)caKeySz), 0);
  1235. XMEMSET(sapkiBuf, 0, sapkiSz);
  1236. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1237. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1238. if (file) {
  1239. fclose(file);
  1240. file = NULL;
  1241. }
  1242. XMEMSET(altPrivBuf, 0, altPrivSz);
  1243. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1244. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1245. if (file) {
  1246. fclose(file);
  1247. file = NULL;
  1248. }
  1249. wc_ecc_init(&altCaKey);
  1250. idx = 0;
  1251. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1252. (word32)altPrivSz), 0);
  1253. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1254. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1255. oidSigType, 0), 0);
  1256. wc_InitCert(&newCert);
  1257. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1258. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1259. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1260. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1261. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1262. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1263. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1264. newCert.sigType = CTC_SHA256wRSA;
  1265. newCert.isCA = 0;
  1266. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1267. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1268. sapkiSz), 0);
  1269. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1270. altSigAlgSz), 0);
  1271. XMEMSET(scratchBuf, 0, scratchSz);
  1272. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1273. &rng), 0);
  1274. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1275. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1276. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1277. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1278. XMEMSET(preTbsBuf, 0, preTbsSz);
  1279. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1280. XMEMSET(altSigValBuf, 0, altSigValSz);
  1281. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1282. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1283. &rng), 0);
  1284. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1285. altSigValBuf, altSigValSz), 0);
  1286. /* Finally, generate the new certificate. */
  1287. if (outBuf != NULL) {
  1288. XMEMSET(outBuf, 0, outSz);
  1289. }
  1290. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1291. 0);
  1292. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1293. outSz, &caKey, NULL, &rng), 0);
  1294. *out = outBuf;
  1295. wc_FreeRsaKey(&caKey);
  1296. wc_FreeRsaKey(&serverKey);
  1297. wc_FreeRng(&rng);
  1298. wc_FreeDecodedCert(&preTBS);
  1299. return outSz;
  1300. }
  1301. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1302. byte *serverCert, word32 serverCertSz,
  1303. byte *serverKey, word32 serverKeySz,
  1304. int negative_test)
  1305. {
  1306. EXPECT_DECLS;
  1307. WOLFSSL_CTX *ctx_c = NULL;
  1308. WOLFSSL_CTX *ctx_s = NULL;
  1309. WOLFSSL *ssl_c = NULL;
  1310. WOLFSSL *ssl_s = NULL;
  1311. struct test_memio_ctx test_ctx;
  1312. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1313. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1314. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1315. caCert, caCertSz, serverCert, serverCertSz,
  1316. serverKey, serverKeySz), 0);
  1317. if (negative_test) {
  1318. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1319. }
  1320. else {
  1321. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1322. }
  1323. wolfSSL_free(ssl_c);
  1324. wolfSSL_free(ssl_s);
  1325. wolfSSL_CTX_free(ctx_c);
  1326. wolfSSL_CTX_free(ctx_s);
  1327. return EXPECT_RESULT();
  1328. }
  1329. static int test_dual_alg_support(void)
  1330. {
  1331. EXPECT_DECLS;
  1332. /* Root CA and server keys will be the same. This is only appropriate for
  1333. * testing. */
  1334. char keyFile[] = "./certs/ca-key.der";
  1335. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1336. char altPrivFile[] = "./certs/ecc-key.der";
  1337. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1338. byte *serverKey = NULL;
  1339. size_t serverKeySz = 0;
  1340. byte *root = NULL;
  1341. int rootSz = 0;
  1342. byte *server = NULL;
  1343. int serverSz = 0;
  1344. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1345. /* Base normal case. */
  1346. if (EXPECT_SUCCESS()) {
  1347. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1348. altPrivFile);
  1349. }
  1350. ExpectNotNull(root);
  1351. ExpectIntGT(rootSz, 0);
  1352. if (EXPECT_SUCCESS()) {
  1353. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1354. altPrivFile, keyFile, root, rootSz);
  1355. }
  1356. ExpectNotNull(server);
  1357. ExpectIntGT(serverSz, 0);
  1358. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1359. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1360. TEST_SUCCESS);
  1361. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1362. root = NULL;
  1363. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1364. server = NULL;
  1365. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1366. * the alternative signature and then set negative_test to true for the
  1367. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1368. * because the signature won't verify. The exception is if
  1369. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1370. * and this is no longer a negative test. */
  1371. if (EXPECT_SUCCESS()) {
  1372. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1373. wrongPrivFile);
  1374. }
  1375. ExpectNotNull(root);
  1376. ExpectIntGT(rootSz, 0);
  1377. if (EXPECT_SUCCESS()) {
  1378. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1379. wrongPrivFile, keyFile, root, rootSz);
  1380. }
  1381. ExpectNotNull(server);
  1382. ExpectIntGT(serverSz, 0);
  1383. #ifdef WOLFSSL_TRUST_PEER_CERT
  1384. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1385. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1386. TEST_SUCCESS);
  1387. #else
  1388. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1389. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1390. TEST_SUCCESS);
  1391. #endif
  1392. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1393. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1394. free(serverKey);
  1395. return EXPECT_RESULT();
  1396. }
  1397. #else
  1398. static int test_dual_alg_support(void)
  1399. {
  1400. return TEST_SKIPPED;
  1401. }
  1402. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1403. /*----------------------------------------------------------------------------*
  1404. | Context
  1405. *----------------------------------------------------------------------------*/
  1406. #ifndef NO_WOLFSSL_SERVER
  1407. static int test_wolfSSL_CTX_new(void)
  1408. {
  1409. EXPECT_DECLS;
  1410. WOLFSSL_CTX *ctx;
  1411. WOLFSSL_METHOD* method = NULL;
  1412. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1413. ExpectNotNull(method = wolfSSLv23_server_method());
  1414. if (method != NULL)
  1415. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1416. wolfSSL_CTX_free(ctx);
  1417. return EXPECT_RESULT();
  1418. }
  1419. #endif
  1420. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1421. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1422. static int test_for_double_Free(void)
  1423. {
  1424. EXPECT_DECLS;
  1425. WOLFSSL_CTX* ctx = NULL;
  1426. WOLFSSL* ssl = NULL;
  1427. int skipTest = 0;
  1428. const char* testCertFile;
  1429. const char* testKeyFile;
  1430. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1431. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1432. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1433. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1434. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1435. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1436. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1437. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1438. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1439. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1440. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1441. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1442. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1443. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1444. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1445. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1446. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1447. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1448. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1449. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1450. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1451. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1452. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1453. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1454. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1455. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1456. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1457. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1458. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1459. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1460. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1461. #ifdef OPENSSL_EXTRA
  1462. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1463. "!SRP:!kRSA:!aNULL:!eNULL";
  1464. #endif
  1465. #ifndef NO_RSA
  1466. testCertFile = svrCertFile;
  1467. testKeyFile = svrKeyFile;
  1468. #elif defined(HAVE_ECC)
  1469. testCertFile = eccCertFile;
  1470. testKeyFile = eccKeyFile;
  1471. #else
  1472. skipTest = 1;
  1473. #endif
  1474. if (skipTest != 1) {
  1475. #ifndef NO_WOLFSSL_SERVER
  1476. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1477. #else
  1478. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1479. #endif
  1480. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1481. WOLFSSL_FILETYPE_PEM));
  1482. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1483. WOLFSSL_FILETYPE_PEM));
  1484. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1485. /* First test freeing SSL, then CTX */
  1486. wolfSSL_free(ssl);
  1487. ssl = NULL;
  1488. wolfSSL_CTX_free(ctx);
  1489. ctx = NULL;
  1490. #ifndef NO_WOLFSSL_CLIENT
  1491. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1492. #else
  1493. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1494. #endif
  1495. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1496. WOLFSSL_FILETYPE_PEM));
  1497. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1498. WOLFSSL_FILETYPE_PEM));
  1499. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1500. /* Next test freeing CTX then SSL */
  1501. wolfSSL_CTX_free(ctx);
  1502. ctx = NULL;
  1503. wolfSSL_free(ssl);
  1504. ssl = NULL;
  1505. #ifndef NO_WOLFSSL_SERVER
  1506. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1507. #else
  1508. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1509. #endif
  1510. /* Test setting ciphers at ctx level */
  1511. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1512. WOLFSSL_FILETYPE_PEM));
  1513. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1514. WOLFSSL_FILETYPE_PEM));
  1515. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1516. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1517. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1518. /* only update TLSv13 suites */
  1519. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1520. #endif
  1521. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1522. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1523. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1524. /* only update pre-TLSv13 suites */
  1525. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1526. "ECDHE-RSA-AES128-GCM-SHA256"));
  1527. #endif
  1528. #ifdef OPENSSL_EXTRA
  1529. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1530. #endif
  1531. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1532. wolfSSL_CTX_free(ctx);
  1533. ctx = NULL;
  1534. wolfSSL_free(ssl);
  1535. ssl = NULL;
  1536. #ifndef NO_WOLFSSL_CLIENT
  1537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1538. #else
  1539. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1540. #endif
  1541. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1542. WOLFSSL_FILETYPE_PEM));
  1543. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1544. WOLFSSL_FILETYPE_PEM));
  1545. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1546. /* test setting ciphers at SSL level */
  1547. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1548. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1549. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1550. /* only update TLSv13 suites */
  1551. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1552. #endif
  1553. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1554. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1555. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1556. /* only update pre-TLSv13 suites */
  1557. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1558. #endif
  1559. wolfSSL_CTX_free(ctx);
  1560. ctx = NULL;
  1561. wolfSSL_free(ssl);
  1562. ssl = NULL;
  1563. }
  1564. return EXPECT_RESULT();
  1565. }
  1566. #endif
  1567. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1568. {
  1569. EXPECT_DECLS;
  1570. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1571. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1572. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1573. const char* testCertFile;
  1574. const char* testKeyFile;
  1575. WOLFSSL_CTX* ctx = NULL;
  1576. WOLFSSL* ssl = NULL;
  1577. const byte cipherList[] =
  1578. {
  1579. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1580. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1581. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1582. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1583. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1584. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1585. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1586. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1587. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1588. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1589. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1590. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1591. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1592. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1593. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1594. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1595. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1596. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1597. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1598. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1599. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1600. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1601. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1602. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1603. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1604. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1605. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1606. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1607. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1608. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1609. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1610. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1611. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1612. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1613. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1614. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1615. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1616. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1617. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1618. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1619. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1620. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1621. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1622. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1623. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1624. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1625. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1626. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1627. /* SHA256 */
  1628. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1629. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1630. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1631. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1632. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1633. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1634. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1635. /* SHA384 */
  1636. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1637. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1638. /* AES-GCM */
  1639. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1640. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1641. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1642. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1643. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1644. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1645. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1646. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1647. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1648. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1649. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1650. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1651. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1652. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1653. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1654. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1655. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1656. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1657. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1658. * also, in some of the other AES-CCM suites
  1659. * there will be second byte number conflicts
  1660. * with non-ECC AES-GCM */
  1661. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1662. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1663. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1664. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1665. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1666. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1667. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1668. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1669. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1670. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1671. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1672. /* Camellia */
  1673. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1674. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1675. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1676. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1677. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1678. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1679. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1680. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1681. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1682. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1683. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1684. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1685. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1686. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1687. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1688. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1689. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1690. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1691. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1692. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1693. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1694. /* TLS v1.3 cipher suites */
  1695. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1696. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1697. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1698. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1699. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1700. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1701. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1702. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1703. };
  1704. #ifndef NO_RSA
  1705. testCertFile = svrCertFile;
  1706. testKeyFile = svrKeyFile;
  1707. #elif defined(HAVE_ECC)
  1708. testCertFile = eccCertFile;
  1709. testKeyFile = eccKeyFile;
  1710. #endif
  1711. #ifndef NO_WOLFSSL_SERVER
  1712. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1713. #else
  1714. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1715. #endif
  1716. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1717. sizeof(cipherList)));
  1718. wolfSSL_CTX_free(ctx);
  1719. ctx = NULL;
  1720. #ifndef NO_WOLFSSL_SERVER
  1721. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1722. #else
  1723. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1724. #endif
  1725. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1726. WOLFSSL_FILETYPE_PEM));
  1727. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1728. WOLFSSL_FILETYPE_PEM));
  1729. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1730. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1731. sizeof(cipherList)));
  1732. wolfSSL_free(ssl);
  1733. wolfSSL_CTX_free(ctx);
  1734. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1735. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1736. return EXPECT_RESULT();
  1737. }
  1738. static int test_wolfSSL_CTX_use_certificate(void)
  1739. {
  1740. EXPECT_DECLS;
  1741. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1742. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1743. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1744. defined(WOLFSSL_HAPROXY)
  1745. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1746. WOLFSSL_CTX* ctx = NULL;
  1747. X509* x509 = NULL;
  1748. #ifndef NO_WOLFSSL_SERVER
  1749. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1750. #else
  1751. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1752. #endif
  1753. ExpectNotNull(x509 = wolfSSL_X509_new());
  1754. /* Negative tests. */
  1755. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1756. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1757. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1758. /* Empty certificate */
  1759. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1760. wolfSSL_X509_free(x509);
  1761. wolfSSL_CTX_free(ctx);
  1762. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1763. #endif
  1764. return EXPECT_RESULT();
  1765. }
  1766. static int test_wolfSSL_CTX_use_certificate_file(void)
  1767. {
  1768. EXPECT_DECLS;
  1769. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1770. WOLFSSL_CTX *ctx = NULL;
  1771. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1772. /* invalid context */
  1773. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1774. WOLFSSL_FILETYPE_PEM));
  1775. /* invalid cert file */
  1776. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1777. WOLFSSL_FILETYPE_PEM));
  1778. /* invalid cert type */
  1779. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1780. #ifdef NO_RSA
  1781. /* rsa needed */
  1782. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1783. WOLFSSL_FILETYPE_PEM));
  1784. #else
  1785. /* success */
  1786. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1787. WOLFSSL_FILETYPE_PEM));
  1788. #endif
  1789. wolfSSL_CTX_free(ctx);
  1790. #endif
  1791. return EXPECT_RESULT();
  1792. }
  1793. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1794. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1795. {
  1796. EXPECT_DECLS;
  1797. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1798. WOLFSSL_CTX* ctx = NULL;
  1799. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1800. /* Failure cases. */
  1801. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1802. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1803. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1804. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1805. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1806. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1807. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1808. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1809. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1810. server_cert_der_2048), WOLFSSL_SUCCESS);
  1811. wolfSSL_CTX_free(ctx);
  1812. #endif
  1813. return EXPECT_RESULT();
  1814. }
  1815. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1816. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1817. * context using buffer.
  1818. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1819. * --enable-testcert flag.
  1820. */
  1821. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1822. {
  1823. EXPECT_DECLS;
  1824. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1825. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1826. WOLFSSL_CTX* ctx = NULL;
  1827. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1828. /* Invalid parameters. */
  1829. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1830. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1831. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1832. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1833. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1834. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1835. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1836. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1837. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1838. server_cert_der_2048, sizeof_server_cert_der_2048,
  1839. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1840. wolfSSL_CTX_free(ctx);
  1841. #endif
  1842. return EXPECT_RESULT();
  1843. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1844. static int test_wolfSSL_use_certificate_buffer(void)
  1845. {
  1846. EXPECT_DECLS;
  1847. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1848. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1849. WOLFSSL_CTX* ctx = NULL;
  1850. WOLFSSL* ssl = NULL;
  1851. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1852. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1853. /* Invalid parameters. */
  1854. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1855. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1856. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1857. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1858. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1859. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1860. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1861. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1862. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1863. client_cert_der_2048, sizeof_client_cert_der_2048,
  1864. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1865. wolfSSL_free(ssl);
  1866. wolfSSL_CTX_free(ctx);
  1867. #endif
  1868. return EXPECT_RESULT();
  1869. }
  1870. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1871. {
  1872. EXPECT_DECLS;
  1873. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1874. WOLFSSL_CTX *ctx = NULL;
  1875. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1876. /* invalid context */
  1877. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1878. WOLFSSL_FILETYPE_PEM));
  1879. /* invalid key file */
  1880. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1881. WOLFSSL_FILETYPE_PEM));
  1882. /* invalid key type */
  1883. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1884. /* success */
  1885. #ifdef NO_RSA
  1886. /* rsa needed */
  1887. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1888. WOLFSSL_FILETYPE_PEM));
  1889. #else
  1890. /* success */
  1891. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1892. WOLFSSL_FILETYPE_PEM));
  1893. #endif
  1894. wolfSSL_CTX_free(ctx);
  1895. #endif
  1896. return EXPECT_RESULT();
  1897. }
  1898. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1899. {
  1900. EXPECT_DECLS;
  1901. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1902. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1903. WOLFSSL_CTX *ctx = NULL;
  1904. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1905. /* invalid context */
  1906. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1907. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1908. /* invalid key file */
  1909. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1910. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1911. /* invalid key type */
  1912. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1913. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1914. /* success */
  1915. #ifdef NO_RSA
  1916. /* rsa needed */
  1917. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1918. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1919. #else
  1920. /* success */
  1921. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1922. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1923. #endif
  1924. wolfSSL_CTX_free(ctx);
  1925. #endif
  1926. return EXPECT_RESULT();
  1927. }
  1928. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1929. {
  1930. EXPECT_DECLS;
  1931. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1932. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1933. WOLFSSL_CTX* ctx = NULL;
  1934. WOLFSSL* ssl = NULL;
  1935. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1936. ExpectNotNull(ssl = SSL_new(ctx));
  1937. /* invalid context */
  1938. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1939. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1940. /* invalid key file */
  1941. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1942. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1943. /* invalid key type */
  1944. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1945. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1946. /* success */
  1947. #ifdef NO_RSA
  1948. /* rsa needed */
  1949. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1950. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1951. #else
  1952. /* success */
  1953. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1954. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1955. #endif
  1956. wolfSSL_free(ssl);
  1957. wolfSSL_CTX_free(ctx);
  1958. #endif
  1959. return EXPECT_RESULT();
  1960. }
  1961. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1962. {
  1963. EXPECT_DECLS;
  1964. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1965. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1966. WOLFSSL_CTX *ctx = NULL;
  1967. WOLFSSL_EVP_PKEY* pkey = NULL;
  1968. const unsigned char* p;
  1969. (void)p;
  1970. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1971. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1972. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1973. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1974. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1975. /* No data. */
  1976. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1977. wolfSSL_EVP_PKEY_free(pkey);
  1978. pkey = NULL;
  1979. #if defined(USE_CERT_BUFFERS_2048)
  1980. #if !defined(NO_RSA)
  1981. p = client_key_der_2048;
  1982. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1983. sizeof_client_key_der_2048));
  1984. #if defined(WOLFSSL_KEY_GEN)
  1985. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1986. #else
  1987. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1988. #endif
  1989. wolfSSL_EVP_PKEY_free(pkey);
  1990. pkey = NULL;
  1991. #endif
  1992. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1993. #ifndef NO_DSA
  1994. p = dsa_key_der_2048;
  1995. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1996. sizeof_dsa_key_der_2048));
  1997. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1998. defined(WOLFSSL_CERT_GEN))
  1999. /* Not supported in ProcessBuffer. */
  2000. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2001. #else
  2002. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2003. #endif
  2004. wolfSSL_EVP_PKEY_free(pkey);
  2005. pkey = NULL;
  2006. #endif
  2007. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  2008. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  2009. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  2010. p = dh_ffdhe_statickey_der_2048;
  2011. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  2012. sizeof_dh_ffdhe_statickey_der_2048));
  2013. /* Not supported. */
  2014. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2015. wolfSSL_EVP_PKEY_free(pkey);
  2016. pkey = NULL;
  2017. #endif
  2018. #endif /* USE_CERT_BUFFERS_2048 */
  2019. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  2020. p = ecc_clikey_der_256;
  2021. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  2022. sizeof_ecc_clikey_der_256));
  2023. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  2024. wolfSSL_EVP_PKEY_free(pkey);
  2025. pkey = NULL;
  2026. #endif
  2027. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  2028. (unsigned char*)"01234567012345670123456701234567", 32));
  2029. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2030. wolfSSL_EVP_PKEY_free(pkey);
  2031. pkey = NULL;
  2032. wolfSSL_CTX_free(ctx);
  2033. #endif
  2034. return EXPECT_RESULT();
  2035. }
  2036. /* test both file and buffer versions along with unloading trusted peer certs */
  2037. static int test_wolfSSL_CTX_trust_peer_cert(void)
  2038. {
  2039. EXPECT_DECLS;
  2040. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2041. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  2042. WOLFSSL_CTX *ctx = NULL;
  2043. WOLFSSL* ssl = NULL;
  2044. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2045. ExpectNotNull(ssl = wolfSSL_new(ctx));
  2046. #if !defined(NO_FILESYSTEM)
  2047. /* invalid file */
  2048. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  2049. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2050. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  2051. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2052. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2053. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2054. /* success */
  2055. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2056. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2057. /* unload cert */
  2058. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2059. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2060. /* invalid file */
  2061. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  2062. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2063. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  2064. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2065. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2066. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2067. /* success */
  2068. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2069. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2070. #ifdef WOLFSSL_LOCAL_X509_STORE
  2071. /* unload cert */
  2072. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2073. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  2074. #endif
  2075. #endif
  2076. /* Test of loading certs from buffers */
  2077. /* invalid buffer */
  2078. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  2079. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2080. /* success */
  2081. #ifdef USE_CERT_BUFFERS_1024
  2082. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  2083. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2084. #endif
  2085. #ifdef USE_CERT_BUFFERS_2048
  2086. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  2087. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2088. #endif
  2089. /* unload cert */
  2090. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2091. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2092. wolfSSL_free(ssl);
  2093. wolfSSL_CTX_free(ctx);
  2094. #endif
  2095. return EXPECT_RESULT();
  2096. }
  2097. static int test_wolfSSL_CTX_load_verify_locations(void)
  2098. {
  2099. EXPECT_DECLS;
  2100. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  2101. WOLFSSL_CTX *ctx = NULL;
  2102. #ifndef NO_RSA
  2103. WOLFSSL_CERT_MANAGER* cm = NULL;
  2104. #ifdef PERSIST_CERT_CACHE
  2105. int cacheSz = 0;
  2106. unsigned char* cache = NULL;
  2107. int used = 0;
  2108. #ifndef NO_FILESYSTEM
  2109. const char* cacheFile = "./tests/cert_cache.tmp";
  2110. #endif
  2111. int i;
  2112. int t;
  2113. int* p;
  2114. #endif
  2115. #endif
  2116. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2117. const char* load_certs_path = "./certs/external";
  2118. const char* load_no_certs_path = "./examples";
  2119. const char* load_expired_path = "./certs/test/expired";
  2120. #endif
  2121. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2122. /* invalid arguments */
  2123. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  2124. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2125. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  2126. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2127. /* invalid ca file */
  2128. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  2129. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  2130. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2131. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  2132. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  2133. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  2134. /* invalid path */
  2135. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  2136. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2137. #endif
  2138. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  2139. /* test ignoring the invalid path */
  2140. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  2141. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  2142. #endif
  2143. /* load ca cert */
  2144. #ifdef NO_RSA
  2145. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2146. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2147. #else /* Skip the following test without RSA certs. */
  2148. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2149. WOLFSSL_SUCCESS);
  2150. #ifdef PERSIST_CERT_CACHE
  2151. /* Get cert cache size */
  2152. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  2153. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  2154. DYNAMIC_TYPE_TMP_BUFFER));
  2155. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  2156. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2157. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  2158. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2159. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  2160. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2161. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  2162. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2163. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  2164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2165. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  2166. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2167. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  2168. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2169. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  2170. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2171. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  2172. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2173. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  2174. WC_NO_ERR_TRACE(BUFFER_E));
  2175. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  2176. ExpectIntEQ(cacheSz, used);
  2177. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  2178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2179. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  2180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2181. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  2182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2183. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  2184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2185. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  2186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2187. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  2188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2189. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  2190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2191. /* Smaller than header. */
  2192. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  2193. for (i = 1; i < cacheSz; i++) {
  2194. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  2195. WC_NO_ERR_TRACE(BUFFER_E));
  2196. }
  2197. if (EXPECT_SUCCESS()) {
  2198. /* Modify header for bad results! */
  2199. p = (int*)cache;
  2200. /* version */
  2201. t = p[0]; p[0] = 0xff;
  2202. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2203. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2204. p[0] = t; p++;
  2205. /* rows */
  2206. t = p[0]; p[0] = 0xff;
  2207. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2208. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2209. p[0] = t; p++;
  2210. /* columns[0] */
  2211. t = p[0]; p[0] = -1;
  2212. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2213. WC_NO_ERR_TRACE(PARSE_ERROR));
  2214. p[0] = t; p += CA_TABLE_SIZE;
  2215. /* signerSz*/
  2216. t = p[0]; p[0] = 0xff;
  2217. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2218. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2219. p[0] = t;
  2220. }
  2221. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2222. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2223. #ifndef NO_FILESYSTEM
  2224. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2225. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2226. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2227. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2228. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2229. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2230. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2231. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2232. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2233. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2234. /* File contents is not a cache. */
  2235. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2236. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2237. #endif
  2238. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2239. #endif
  2240. /* Test unloading CA's */
  2241. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2242. #ifdef PERSIST_CERT_CACHE
  2243. /* Verify no certs (result is less than cacheSz) */
  2244. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2245. #endif
  2246. /* load ca cert again */
  2247. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2248. WOLFSSL_SUCCESS);
  2249. /* Test getting CERT_MANAGER */
  2250. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2251. /* Test unloading CA's using CM */
  2252. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2253. #ifdef PERSIST_CERT_CACHE
  2254. /* Verify no certs (result is less than cacheSz) */
  2255. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2256. #endif
  2257. #endif
  2258. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2259. /* Test loading CA certificates using a path */
  2260. #ifdef NO_RSA
  2261. /* failure here okay since certs in external directory are RSA */
  2262. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2263. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2264. #else
  2265. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2266. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2267. #endif
  2268. /* Test loading path with no files */
  2269. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2270. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2271. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2272. /* Test loading expired CA certificates */
  2273. #ifdef NO_RSA
  2274. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2275. load_expired_path,
  2276. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2277. WOLFSSL_SUCCESS);
  2278. #else
  2279. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2280. load_expired_path,
  2281. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2282. WOLFSSL_SUCCESS);
  2283. #endif
  2284. /* Test loading CA certificates and ignoring all errors */
  2285. #ifdef NO_RSA
  2286. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2287. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2288. #else
  2289. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2290. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2291. #endif
  2292. #endif
  2293. wolfSSL_CTX_free(ctx);
  2294. #endif
  2295. return EXPECT_RESULT();
  2296. }
  2297. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2298. {
  2299. int res = TEST_SKIPPED;
  2300. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2301. (!defined(NO_RSA) || defined(HAVE_ECC))
  2302. WOLFSSL_CTX* ctx;
  2303. byte dirValid = 0;
  2304. int ret = 0;
  2305. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2306. if (ctx == NULL) {
  2307. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2308. ret = -1;
  2309. }
  2310. if (ret == 0) {
  2311. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2312. dirValid = 1;
  2313. #else
  2314. word32 numDirs;
  2315. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2316. if (caDirs == NULL || numDirs == 0) {
  2317. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2318. ret = -1;
  2319. }
  2320. else {
  2321. ReadDirCtx dirCtx;
  2322. word32 i;
  2323. for (i = 0; i < numDirs; ++i) {
  2324. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2325. /* Directory isn't empty. */
  2326. dirValid = 1;
  2327. wc_ReadDirClose(&dirCtx);
  2328. break;
  2329. }
  2330. }
  2331. }
  2332. #endif
  2333. }
  2334. /*
  2335. * If the directory isn't empty, we should be able to load CA
  2336. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2337. * usable.
  2338. */
  2339. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2340. WOLFSSL_SUCCESS) {
  2341. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2342. ret = -1;
  2343. }
  2344. #ifdef OPENSSL_EXTRA
  2345. if (ret == 0 &&
  2346. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2347. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2348. ret = -1;
  2349. }
  2350. #endif /* OPENSSL_EXTRA */
  2351. wolfSSL_CTX_free(ctx);
  2352. res = TEST_RES_CHECK(ret == 0);
  2353. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2354. return res;
  2355. }
  2356. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2357. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2358. int file_type)
  2359. {
  2360. int ret;
  2361. WOLFSSL_CERT_MANAGER* cm;
  2362. cm = wolfSSL_CertManagerNew();
  2363. if (cm == NULL) {
  2364. fprintf(stderr, "test_cm_load_ca failed\n");
  2365. return -1;
  2366. }
  2367. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, cert_sz, file_type);
  2368. wolfSSL_CertManagerFree(cm);
  2369. return ret;
  2370. }
  2371. static int test_cm_load_ca_file(const char* ca_cert_file)
  2372. {
  2373. int ret = 0;
  2374. byte* cert_buf = NULL;
  2375. size_t cert_sz = 0;
  2376. #if defined(WOLFSSL_PEM_TO_DER)
  2377. DerBuffer* pDer = NULL;
  2378. #endif
  2379. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2380. if (ret == 0) {
  2381. /* normal test */
  2382. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2383. if (ret == WOLFSSL_SUCCESS) {
  2384. /* test including null terminator in length */
  2385. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2386. if (tmp == NULL) {
  2387. ret = MEMORY_E;
  2388. }
  2389. else {
  2390. cert_buf = tmp;
  2391. cert_buf[cert_sz] = '\0';
  2392. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2393. WOLFSSL_FILETYPE_PEM);
  2394. }
  2395. }
  2396. #if defined(WOLFSSL_PEM_TO_DER)
  2397. if (ret == WOLFSSL_SUCCESS) {
  2398. /* test loading DER */
  2399. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2400. if (ret == 0 && pDer != NULL) {
  2401. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2402. WOLFSSL_FILETYPE_ASN1);
  2403. wc_FreeDer(&pDer);
  2404. }
  2405. }
  2406. #endif
  2407. }
  2408. free(cert_buf);
  2409. return ret;
  2410. }
  2411. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2412. int file_type, word32 flags)
  2413. {
  2414. int ret;
  2415. WOLFSSL_CERT_MANAGER* cm;
  2416. cm = wolfSSL_CertManagerNew();
  2417. if (cm == NULL) {
  2418. fprintf(stderr, "test_cm_load_ca failed\n");
  2419. return -1;
  2420. }
  2421. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, cert_sz, file_type,
  2422. 0, flags);
  2423. wolfSSL_CertManagerFree(cm);
  2424. return ret;
  2425. }
  2426. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2427. {
  2428. int ret = 0;
  2429. byte* cert_buf = NULL;
  2430. size_t cert_sz = 0;
  2431. #if defined(WOLFSSL_PEM_TO_DER)
  2432. DerBuffer* pDer = NULL;
  2433. #endif
  2434. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2435. if (ret == 0) {
  2436. /* normal test */
  2437. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2438. WOLFSSL_FILETYPE_PEM, flags);
  2439. if (ret == WOLFSSL_SUCCESS) {
  2440. /* test including null terminator in length */
  2441. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2442. if (tmp == NULL) {
  2443. ret = MEMORY_E;
  2444. }
  2445. else {
  2446. cert_buf = tmp;
  2447. cert_buf[cert_sz] = '\0';
  2448. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2449. WOLFSSL_FILETYPE_PEM, flags);
  2450. }
  2451. }
  2452. #if defined(WOLFSSL_PEM_TO_DER)
  2453. if (ret == WOLFSSL_SUCCESS) {
  2454. /* test loading DER */
  2455. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2456. if (ret == 0 && pDer != NULL) {
  2457. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2458. WOLFSSL_FILETYPE_ASN1, flags);
  2459. wc_FreeDer(&pDer);
  2460. }
  2461. }
  2462. #endif
  2463. }
  2464. free(cert_buf);
  2465. return ret;
  2466. }
  2467. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2468. static int test_wolfSSL_CertManagerAPI(void)
  2469. {
  2470. EXPECT_DECLS;
  2471. #ifndef NO_CERTS
  2472. WOLFSSL_CERT_MANAGER* cm = NULL;
  2473. unsigned char c;
  2474. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2475. wolfSSL_CertManagerFree(NULL);
  2476. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2477. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2478. #ifdef WOLFSSL_TRUST_PEER_CERT
  2479. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2480. #endif
  2481. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2482. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2483. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2484. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2485. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2486. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2487. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2488. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2489. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2490. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1,
  2491. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1,
  2493. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2494. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1,
  2495. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2496. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2497. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2498. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2499. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2500. #endif
  2501. #if !defined(NO_FILESYSTEM)
  2502. {
  2503. const char* ca_cert = "./certs/ca-cert.pem";
  2504. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2505. const char* ca_cert_der = "./certs/ca-cert.der";
  2506. #endif
  2507. const char* ca_path = "./certs";
  2508. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2509. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2510. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2511. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2513. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2514. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2515. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2516. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2517. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2518. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2519. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2520. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2521. #endif
  2522. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2523. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2524. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2525. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2526. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2527. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2528. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2529. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2530. }
  2531. #endif
  2532. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2533. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2534. #elif !defined(HAVE_CRL)
  2535. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2536. #endif
  2537. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2538. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2539. #ifdef HAVE_CRL
  2540. /* Test APIs when CRL is disabled. */
  2541. #ifdef HAVE_CRL_IO
  2542. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2543. #endif
  2544. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2545. sizeof_server_cert_der_2048), 1);
  2546. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2547. #endif
  2548. /* OCSP */
  2549. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2550. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2551. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2552. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2553. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2554. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2555. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2556. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2557. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2558. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2559. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2560. #endif
  2561. #ifdef HAVE_OCSP
  2562. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2563. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2564. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2565. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2566. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2567. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2568. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2569. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2570. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2571. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2572. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2573. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2574. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2575. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2576. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2577. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2578. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2579. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2580. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2581. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2582. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2583. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2584. /* Test APIs when OCSP is disabled. */
  2585. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2586. NULL, NULL, NULL, NULL), 1);
  2587. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2588. #endif
  2589. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2590. if (EXPECT_SUCCESS()) {
  2591. wolfSSL_CertManagerFree(cm);
  2592. }
  2593. wolfSSL_CertManagerFree(cm);
  2594. cm = NULL;
  2595. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2596. #ifdef HAVE_OCSP
  2597. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2598. WOLFSSL_OCSP_CHECKALL), 1);
  2599. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2600. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2601. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2602. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2603. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2604. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2605. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2606. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2607. #endif
  2608. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2609. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2610. #endif
  2611. #ifdef WOLFSSL_TRUST_PEER_CERT
  2612. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2613. #endif
  2614. wolfSSL_CertManagerFree(cm);
  2615. #endif
  2616. return EXPECT_RESULT();
  2617. }
  2618. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2619. {
  2620. EXPECT_DECLS;
  2621. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2622. const char* ca_cert = "./certs/ca-cert.pem";
  2623. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2624. int ret;
  2625. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2626. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2627. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2628. #elif defined(NO_RSA)
  2629. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2630. #else
  2631. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2632. #endif
  2633. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2634. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2635. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2636. #elif defined(NO_RSA)
  2637. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2638. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2639. !defined(NO_ASN_TIME)
  2640. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2641. #else
  2642. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2643. #endif
  2644. #endif
  2645. return EXPECT_RESULT();
  2646. }
  2647. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2648. {
  2649. EXPECT_DECLS;
  2650. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2651. const char* ca_cert = "./certs/ca-cert.pem";
  2652. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2653. int ret;
  2654. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2655. 1);
  2656. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2657. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2658. #elif defined(NO_RSA)
  2659. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2660. #else
  2661. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2662. #endif
  2663. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2664. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2665. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2666. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2667. #elif defined(NO_RSA)
  2668. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2669. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2670. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2671. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2672. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2673. #else
  2674. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2675. #endif
  2676. #endif
  2677. return EXPECT_RESULT();
  2678. }
  2679. static int test_wolfSSL_CertManagerGetCerts(void)
  2680. {
  2681. EXPECT_DECLS;
  2682. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2683. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2684. defined(WOLFSSL_SIGNER_DER_CERT)
  2685. WOLFSSL_CERT_MANAGER* cm = NULL;
  2686. WOLFSSL_STACK* sk = NULL;
  2687. X509* x509 = NULL;
  2688. X509* cert1 = NULL;
  2689. FILE* file1 = NULL;
  2690. #ifdef DEBUG_WOLFSSL_VERBOSE
  2691. WOLFSSL_BIO* bio = NULL;
  2692. #endif
  2693. int i = 0;
  2694. int ret = 0;
  2695. const byte* der = NULL;
  2696. int derSz = 0;
  2697. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2698. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2699. if (file1 != NULL) {
  2700. fclose(file1);
  2701. }
  2702. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2703. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2704. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2705. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2706. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2707. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2708. * and full OpenSSL compatibility */
  2709. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2710. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2711. #else
  2712. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2713. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2714. #endif
  2715. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2716. "./certs/ca-cert.pem", NULL));
  2717. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2718. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2719. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2720. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2721. #ifdef DEBUG_WOLFSSL_VERBOSE
  2722. bio = BIO_new(wolfSSL_BIO_s_file());
  2723. if (bio != NULL) {
  2724. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2725. X509_print(bio, x509);
  2726. BIO_free(bio);
  2727. }
  2728. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2729. }
  2730. wolfSSL_X509_free(cert1);
  2731. sk_X509_pop_free(sk, NULL);
  2732. wolfSSL_CertManagerFree(cm);
  2733. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2734. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2735. defined(WOLFSSL_SIGNER_DER_CERT) */
  2736. return EXPECT_RESULT();
  2737. }
  2738. static int test_wolfSSL_CertManagerSetVerify(void)
  2739. {
  2740. EXPECT_DECLS;
  2741. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2742. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2743. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2744. WOLFSSL_CERT_MANAGER* cm = NULL;
  2745. int tmp = myVerifyAction;
  2746. const char* ca_cert = "./certs/ca-cert.pem";
  2747. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2748. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2749. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2750. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2751. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2752. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2753. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2754. #else
  2755. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2756. WOLFSSL_SUCCESS);
  2757. #endif
  2758. /* Use the test CB that always accepts certs */
  2759. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2760. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2761. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2762. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2763. {
  2764. const char* verifyCert = "./certs/server-cert.der";
  2765. /* Use the test CB that always fails certs */
  2766. myVerifyAction = VERIFY_FORCE_FAIL;
  2767. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2768. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2769. }
  2770. #endif
  2771. wolfSSL_CertManagerFree(cm);
  2772. myVerifyAction = tmp;
  2773. #endif
  2774. return EXPECT_RESULT();
  2775. }
  2776. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2777. defined(DEBUG_UNIT_TEST_CERTS)
  2778. /* Used when debugging name constraint tests. Not static to allow use in
  2779. * multiple locations with complex define guards. */
  2780. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2781. {
  2782. BIO* out = BIO_new_file(fileName, "wb");
  2783. if (out != NULL) {
  2784. PEM_write_bio_X509(out, x509);
  2785. BIO_free(out);
  2786. }
  2787. }
  2788. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2789. {
  2790. BIO* out = BIO_new_file(fileName, "wb");
  2791. if (out != NULL) {
  2792. BIO_write(out, der, derSz);
  2793. BIO_free(out);
  2794. }
  2795. }
  2796. #else
  2797. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2798. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2799. #endif
  2800. static int test_wolfSSL_CertManagerNameConstraint(void)
  2801. {
  2802. EXPECT_DECLS;
  2803. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2804. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2805. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2806. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2807. !defined(NO_SHA256)
  2808. WOLFSSL_CERT_MANAGER* cm = NULL;
  2809. WOLFSSL_EVP_PKEY *priv = NULL;
  2810. WOLFSSL_X509_NAME* name = NULL;
  2811. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2812. const char* server_cert = "./certs/test/server-goodcn.pem";
  2813. int i = 0;
  2814. static const byte extNameConsOid[] = {85, 29, 30};
  2815. RsaKey key;
  2816. WC_RNG rng;
  2817. byte *der = NULL;
  2818. int derSz = 0;
  2819. word32 idx = 0;
  2820. byte *pt;
  2821. WOLFSSL_X509 *x509 = NULL;
  2822. WOLFSSL_X509 *ca = NULL;
  2823. wc_InitRng(&rng);
  2824. /* load in CA private key for signing */
  2825. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2826. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2827. sizeof_server_key_der_2048), 0);
  2828. /* get ca certificate then alter it */
  2829. ExpectNotNull(der =
  2830. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2831. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2832. WOLFSSL_FILETYPE_ASN1));
  2833. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2834. if (EXPECT_SUCCESS() && (der != NULL)) {
  2835. XMEMCPY(der, pt, derSz);
  2836. /* find the name constraint extension and alter it */
  2837. pt = der;
  2838. for (i = 0; i < derSz - 3; i++) {
  2839. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2840. pt += 3;
  2841. break;
  2842. }
  2843. pt++;
  2844. }
  2845. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2846. /* go to the length value and set it to 0 */
  2847. while (i < derSz && *pt != 0x81) {
  2848. pt++;
  2849. i++;
  2850. }
  2851. ExpectIntNE(i, derSz); /* did not place to alter */
  2852. pt++;
  2853. *pt = 0x00;
  2854. }
  2855. /* resign the altered certificate */
  2856. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2857. FOURK_BUF, &key, NULL, &rng)), 0);
  2858. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2859. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2860. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2861. wolfSSL_CertManagerFree(cm);
  2862. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2863. wolfSSL_X509_free(x509);
  2864. wc_FreeRsaKey(&key);
  2865. wc_FreeRng(&rng);
  2866. /* add email alt name to satisfy constraint */
  2867. pt = (byte*)server_key_der_2048;
  2868. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2869. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2870. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2871. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2872. WOLFSSL_FILETYPE_ASN1));
  2873. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2874. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2875. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2876. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2877. /* Good cert test with proper alt email name */
  2878. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2879. WOLFSSL_FILETYPE_PEM));
  2880. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2881. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2882. name = NULL;
  2883. ExpectNotNull(name = X509_NAME_new());
  2884. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2885. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2886. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2887. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2888. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2889. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2890. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2891. X509_NAME_free(name);
  2892. name = NULL;
  2893. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2894. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2895. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2896. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2897. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2898. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2899. wolfSSL_X509_free(x509);
  2900. x509 = NULL;
  2901. /* Cert with bad alt name list */
  2902. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2903. WOLFSSL_FILETYPE_PEM));
  2904. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2905. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2906. name = NULL;
  2907. ExpectNotNull(name = X509_NAME_new());
  2908. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2909. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2910. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2911. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2912. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2913. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2914. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2915. X509_NAME_free(name);
  2916. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2917. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2918. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2919. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2920. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2921. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2922. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2923. wolfSSL_CertManagerFree(cm);
  2924. wolfSSL_X509_free(x509);
  2925. wolfSSL_X509_free(ca);
  2926. wolfSSL_EVP_PKEY_free(priv);
  2927. #endif
  2928. return EXPECT_RESULT();
  2929. }
  2930. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2931. {
  2932. EXPECT_DECLS;
  2933. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2934. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2935. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2936. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2937. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2938. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2939. const char* server_cert = "./certs/server-cert.pem";
  2940. WOLFSSL_CERT_MANAGER* cm = NULL;
  2941. WOLFSSL_X509 *x509 = NULL;
  2942. WOLFSSL_X509 *ca = NULL;
  2943. const unsigned char *der = NULL;
  2944. const unsigned char *pt;
  2945. WOLFSSL_EVP_PKEY *priv = NULL;
  2946. WOLFSSL_X509_NAME* name = NULL;
  2947. int derSz = 0;
  2948. /* C=US*/
  2949. char altName[] = {
  2950. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2951. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2952. };
  2953. /* C=ID */
  2954. char altNameFail[] = {
  2955. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2956. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2957. };
  2958. /* C=US ST=California*/
  2959. char altNameExc[] = {
  2960. 0x30, 0x22,
  2961. 0x31, 0x0B,
  2962. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2963. 0x31, 0x13,
  2964. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2965. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2966. };
  2967. /* load in CA private key for signing */
  2968. pt = ca_key_der_2048;
  2969. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2970. sizeof_ca_key_der_2048));
  2971. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2972. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2973. WOLFSSL_FILETYPE_ASN1));
  2974. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2975. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2976. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2977. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2978. WOLFSSL_FILETYPE_PEM));
  2979. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2980. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2981. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2982. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2983. #else
  2984. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2985. #endif
  2986. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2987. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2988. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2989. /* add in matching DIR alt name and resign */
  2990. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2991. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2992. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2993. #else
  2994. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2995. #endif
  2996. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2997. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2998. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2999. wolfSSL_X509_free(x509);
  3000. x509 = NULL;
  3001. /* check verify fail */
  3002. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3003. WOLFSSL_FILETYPE_PEM));
  3004. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3005. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3006. /* add in miss matching DIR alt name and resign */
  3007. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3008. ASN_DIR_TYPE);
  3009. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3010. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3011. #else
  3012. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3013. #endif
  3014. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3015. #ifndef WOLFSSL_NO_ASN_STRICT
  3016. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3017. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3018. #else
  3019. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3020. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3021. #endif
  3022. /* check that it still fails if one bad altname and one good altname is in
  3023. * the certificate */
  3024. wolfSSL_X509_free(x509);
  3025. x509 = NULL;
  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. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3031. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3032. ASN_DIR_TYPE);
  3033. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3034. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3035. #else
  3036. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3037. #endif
  3038. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3039. #ifndef WOLFSSL_NO_ASN_STRICT
  3040. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3041. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3042. #else
  3043. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3044. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3045. #endif
  3046. /* check it fails with switching position of bad altname */
  3047. wolfSSL_X509_free(x509);
  3048. x509 = NULL;
  3049. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3050. WOLFSSL_FILETYPE_PEM));
  3051. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3052. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3053. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3054. ASN_DIR_TYPE);
  3055. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3056. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3057. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3058. #else
  3059. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3060. #endif
  3061. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3062. #ifndef WOLFSSL_NO_ASN_STRICT
  3063. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3064. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3065. #else
  3066. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3067. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3068. #endif
  3069. wolfSSL_CertManagerFree(cm);
  3070. wolfSSL_X509_free(x509);
  3071. x509 = NULL;
  3072. wolfSSL_X509_free(ca);
  3073. ca = NULL;
  3074. /* now test with excluded name constraint */
  3075. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3076. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  3077. WOLFSSL_FILETYPE_ASN1));
  3078. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  3079. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3080. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3081. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3082. WOLFSSL_FILETYPE_PEM));
  3083. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  3084. ASN_DIR_TYPE);
  3085. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3086. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3087. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3088. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3089. #else
  3090. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3091. #endif
  3092. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3093. #ifndef WOLFSSL_NO_ASN_STRICT
  3094. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3095. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3096. #else
  3097. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3098. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3099. #endif
  3100. wolfSSL_CertManagerFree(cm);
  3101. wolfSSL_X509_free(x509);
  3102. wolfSSL_X509_free(ca);
  3103. wolfSSL_EVP_PKEY_free(priv);
  3104. #endif
  3105. return EXPECT_RESULT();
  3106. }
  3107. static int test_wolfSSL_CertManagerNameConstraint3(void)
  3108. {
  3109. EXPECT_DECLS;
  3110. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3111. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3112. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3113. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3114. !defined(NO_SHA256)
  3115. WOLFSSL_CERT_MANAGER* cm = NULL;
  3116. WOLFSSL_EVP_PKEY *priv = NULL;
  3117. WOLFSSL_X509_NAME* name = NULL;
  3118. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  3119. const char* server_cert = "./certs/test/server-goodcn.pem";
  3120. byte *der = NULL;
  3121. int derSz = 0;
  3122. byte *pt;
  3123. WOLFSSL_X509 *x509 = NULL;
  3124. WOLFSSL_X509 *ca = NULL;
  3125. pt = (byte*)server_key_der_2048;
  3126. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3127. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3128. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3129. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3130. WOLFSSL_FILETYPE_ASN1));
  3131. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3132. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3133. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3134. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3135. /* check satisfying .wolfssl.com constraint passes */
  3136. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3137. WOLFSSL_FILETYPE_PEM));
  3138. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3139. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3140. name = NULL;
  3141. ExpectNotNull(name = X509_NAME_new());
  3142. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3143. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3144. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3145. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3146. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3147. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  3148. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3149. X509_NAME_free(name);
  3150. name = NULL;
  3151. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  3152. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3153. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3154. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3155. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3156. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3157. wolfSSL_X509_free(x509);
  3158. x509 = NULL;
  3159. /* check satisfying .random.com constraint passes */
  3160. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3161. WOLFSSL_FILETYPE_PEM));
  3162. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3163. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3164. name = NULL;
  3165. ExpectNotNull(name = X509_NAME_new());
  3166. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3167. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3168. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3169. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3170. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3171. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  3172. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3173. X509_NAME_free(name);
  3174. name = NULL;
  3175. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  3176. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3177. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3178. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3179. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3180. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3181. wolfSSL_X509_free(x509);
  3182. x509 = NULL;
  3183. /* check fail case when neither constraint is matched */
  3184. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3185. WOLFSSL_FILETYPE_PEM));
  3186. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3187. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3188. name = NULL;
  3189. ExpectNotNull(name = X509_NAME_new());
  3190. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3191. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3192. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3193. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3194. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3195. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  3196. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3197. X509_NAME_free(name);
  3198. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  3199. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3200. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3201. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3202. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3203. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3204. wolfSSL_CertManagerFree(cm);
  3205. wolfSSL_X509_free(x509);
  3206. wolfSSL_X509_free(ca);
  3207. wolfSSL_EVP_PKEY_free(priv);
  3208. #endif
  3209. return EXPECT_RESULT();
  3210. }
  3211. static int test_wolfSSL_CertManagerNameConstraint4(void)
  3212. {
  3213. EXPECT_DECLS;
  3214. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3215. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3216. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3217. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3218. !defined(NO_SHA256)
  3219. WOLFSSL_CERT_MANAGER* cm = NULL;
  3220. WOLFSSL_EVP_PKEY *priv = NULL;
  3221. WOLFSSL_X509_NAME* name = NULL;
  3222. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3223. const char* server_cert = "./certs/test/server-goodcn.pem";
  3224. byte *der = NULL;
  3225. int derSz;
  3226. byte *pt;
  3227. WOLFSSL_X509 *x509 = NULL;
  3228. WOLFSSL_X509 *ca = NULL;
  3229. pt = (byte*)server_key_der_2048;
  3230. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3231. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3232. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3233. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3234. WOLFSSL_FILETYPE_ASN1));
  3235. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3236. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3237. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3238. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3239. /* check satisfying wolfssl.com constraint passes */
  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(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3249. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3250. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3251. X509_NAME_free(name);
  3252. name = NULL;
  3253. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3254. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3255. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3256. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3257. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3258. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3259. wolfSSL_X509_free(x509);
  3260. x509 = NULL;
  3261. /* check satisfying example.com constraint passes */
  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(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3271. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3272. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3273. X509_NAME_free(name);
  3274. name = NULL;
  3275. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3276. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3277. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3278. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3279. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3280. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3281. wolfSSL_X509_free(x509);
  3282. x509 = NULL;
  3283. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3284. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3285. WOLFSSL_FILETYPE_PEM));
  3286. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3287. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3288. name = NULL;
  3289. ExpectNotNull(name = X509_NAME_new());
  3290. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3291. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3292. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3293. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3294. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3295. X509_NAME_free(name);
  3296. name = NULL;
  3297. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3298. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3299. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3300. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3301. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3302. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3303. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3304. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3305. wolfSSL_X509_free(x509);
  3306. x509 = NULL;
  3307. /* check fail when one DNS in the list is bad */
  3308. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3309. WOLFSSL_FILETYPE_PEM));
  3310. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3311. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3312. name = NULL;
  3313. ExpectNotNull(name = X509_NAME_new());
  3314. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3315. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3316. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3317. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3318. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3319. X509_NAME_free(name);
  3320. name = NULL;
  3321. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3322. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3323. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3324. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3325. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3326. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3327. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3328. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3329. wolfSSL_X509_free(x509);
  3330. x509 = NULL;
  3331. /* check fail case when neither constraint is matched */
  3332. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3333. WOLFSSL_FILETYPE_PEM));
  3334. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3335. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3336. name = NULL;
  3337. ExpectNotNull(name = X509_NAME_new());
  3338. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3339. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3340. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3341. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3342. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3343. X509_NAME_free(name);
  3344. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3345. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3346. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3347. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3348. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3349. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3350. wolfSSL_CertManagerFree(cm);
  3351. wolfSSL_X509_free(x509);
  3352. wolfSSL_X509_free(ca);
  3353. wolfSSL_EVP_PKEY_free(priv);
  3354. #endif
  3355. return EXPECT_RESULT();
  3356. }
  3357. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3358. {
  3359. EXPECT_DECLS;
  3360. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3361. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3362. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3363. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3364. !defined(NO_SHA256)
  3365. WOLFSSL_CERT_MANAGER* cm = NULL;
  3366. WOLFSSL_EVP_PKEY *priv = NULL;
  3367. WOLFSSL_X509_NAME* name = NULL;
  3368. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3369. const char* server_cert = "./certs/test/server-goodcn.pem";
  3370. byte *der = NULL;
  3371. int derSz;
  3372. byte *pt;
  3373. WOLFSSL_X509 *x509 = NULL;
  3374. WOLFSSL_X509 *ca = NULL;
  3375. pt = (byte*)server_key_der_2048;
  3376. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3377. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3378. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3379. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3380. WOLFSSL_FILETYPE_ASN1));
  3381. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3382. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3383. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3384. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3385. /* check satisfying wolfssl.com constraint passes */
  3386. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3387. WOLFSSL_FILETYPE_PEM));
  3388. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3389. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3390. name = NULL;
  3391. ExpectNotNull(name = X509_NAME_new());
  3392. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3393. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3394. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3395. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3396. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3397. X509_NAME_free(name);
  3398. name = NULL;
  3399. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3400. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3401. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3402. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3403. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3404. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3405. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3406. wolfSSL_X509_free(x509);
  3407. x509 = NULL;
  3408. /* fail with DNS check because of common name */
  3409. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3410. WOLFSSL_FILETYPE_PEM));
  3411. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3412. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3413. name = NULL;
  3414. ExpectNotNull(name = X509_NAME_new());
  3415. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3416. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3417. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3418. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3419. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3420. X509_NAME_free(name);
  3421. name = NULL;
  3422. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3423. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3424. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3425. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3426. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3427. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3428. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3429. wolfSSL_X509_free(x509);
  3430. x509 = NULL;
  3431. /* fail on permitted DNS name constraint */
  3432. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3433. WOLFSSL_FILETYPE_PEM));
  3434. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3435. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3436. name = NULL;
  3437. ExpectNotNull(name = X509_NAME_new());
  3438. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3439. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3440. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3441. X509_NAME_free(name);
  3442. name = NULL;
  3443. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3444. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3445. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3446. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3447. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3448. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3449. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3450. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3451. wolfSSL_X509_free(x509);
  3452. x509 = NULL;
  3453. /* fail on permitted email name constraint */
  3454. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3455. WOLFSSL_FILETYPE_PEM));
  3456. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3457. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3458. name = NULL;
  3459. ExpectNotNull(name = X509_NAME_new());
  3460. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3461. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3462. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3463. X509_NAME_free(name);
  3464. name = NULL;
  3465. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3466. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3467. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3468. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3469. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3470. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3471. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3472. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3473. wolfSSL_X509_free(x509);
  3474. x509 = NULL;
  3475. /* success with empty email name */
  3476. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3477. WOLFSSL_FILETYPE_PEM));
  3478. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3479. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3480. name = NULL;
  3481. ExpectNotNull(name = X509_NAME_new());
  3482. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3483. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3484. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3485. X509_NAME_free(name);
  3486. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3487. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3488. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3489. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3490. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3491. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3492. wolfSSL_X509_free(x509);
  3493. wolfSSL_CertManagerFree(cm);
  3494. wolfSSL_X509_free(ca);
  3495. wolfSSL_EVP_PKEY_free(priv);
  3496. #endif
  3497. return EXPECT_RESULT();
  3498. }
  3499. static int test_wolfSSL_CertManagerCRL(void)
  3500. {
  3501. EXPECT_DECLS;
  3502. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3503. !defined(NO_RSA)
  3504. const char* ca_cert = "./certs/ca-cert.pem";
  3505. const char* crl1 = "./certs/crl/crl.pem";
  3506. const char* crl2 = "./certs/crl/crl2.pem";
  3507. #ifdef WC_RSA_PSS
  3508. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3509. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3510. #endif
  3511. const unsigned char crl_buff[] = {
  3512. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3513. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3514. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3515. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3516. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3517. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3518. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3519. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3520. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3521. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3522. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3523. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3524. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3525. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3526. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3527. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3528. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3529. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3530. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3531. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3532. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3533. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3534. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3535. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3536. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3537. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3538. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3539. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3540. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3541. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3542. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3543. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3544. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3545. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3546. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3547. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3548. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3549. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3550. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3551. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3552. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3553. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3554. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3555. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3556. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3557. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3558. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3559. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3560. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3561. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3562. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3563. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3564. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3565. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3566. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3567. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3568. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3569. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3570. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3571. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3572. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3573. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3574. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3575. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3576. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3577. };
  3578. WOLFSSL_CERT_MANAGER* cm = NULL;
  3579. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3580. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3581. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3582. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3583. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3584. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3585. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3586. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3587. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3588. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3589. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3590. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3591. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3592. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3594. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3595. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3597. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3598. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3599. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3600. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3601. #ifdef HAVE_CRL_IO
  3602. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3603. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3604. #endif
  3605. #ifndef NO_FILESYSTEM
  3606. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3607. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3608. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3609. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3610. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3611. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3612. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3613. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3614. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3615. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3616. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3617. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3618. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3619. #endif
  3620. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3621. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3622. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3623. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3624. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3625. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3626. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1,
  3627. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3628. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1,
  3629. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3630. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1,
  3631. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3632. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3633. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3634. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3635. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3636. ExpectIntEQ(WOLFSSL_SUCCESS,
  3637. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3638. ExpectIntEQ(WOLFSSL_SUCCESS,
  3639. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3640. ExpectIntEQ(WOLFSSL_SUCCESS,
  3641. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3642. wolfSSL_CertManagerFreeCRL(cm);
  3643. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3644. ExpectIntEQ(WOLFSSL_SUCCESS,
  3645. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3646. ExpectIntEQ(WOLFSSL_SUCCESS,
  3647. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3648. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3649. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3650. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3651. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3652. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3653. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3654. WOLFSSL_FILETYPE_ASN1), 1);
  3655. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3656. /* loading should fail without the CA set */
  3657. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3658. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3659. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3660. ExpectIntEQ(WOLFSSL_SUCCESS,
  3661. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3662. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3663. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3664. #endif
  3665. wolfSSL_CertManagerFree(cm);
  3666. #endif
  3667. return EXPECT_RESULT();
  3668. }
  3669. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3670. {
  3671. EXPECT_DECLS;
  3672. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3673. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3674. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3675. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3676. defined(HAVE_LIGHTY)
  3677. WOLFSSL_CERT_MANAGER* cm = NULL;
  3678. /* Raw OCSP response bytes captured using the following setup:
  3679. * - Run responder with
  3680. * openssl ocsp -port 9999 -ndays 9999
  3681. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3682. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3683. * -rkey certs/ocsp/ocsp-responder-key.pem
  3684. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3685. * - Run client with
  3686. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3687. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3688. * -cert certs/ocsp/server1-cert.pem
  3689. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3690. * - Select the response packet in Wireshark, and export it using
  3691. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3692. * packets only". After importing into the editor, remove the initial
  3693. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3694. */
  3695. static const byte response[] = {
  3696. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3697. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3698. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3699. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3700. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3701. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3702. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3703. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3704. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3705. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3706. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3707. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3708. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3709. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3710. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3711. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3712. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3713. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3714. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3715. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3716. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3717. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3718. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3719. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3720. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3721. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3722. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3723. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3724. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3725. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3726. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3727. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3728. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3729. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3730. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3731. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3732. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3733. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3734. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3735. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3736. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3737. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3738. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3739. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3740. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3741. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3742. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3743. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3744. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3745. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3746. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3747. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3748. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3749. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3750. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3751. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3752. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3753. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3754. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3755. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3756. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3757. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3758. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3759. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3760. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3761. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3762. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3763. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3764. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3765. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3766. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3767. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3768. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3769. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3770. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3771. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3772. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3773. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3774. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3775. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3776. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3777. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3778. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3779. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3780. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3781. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3782. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3783. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3784. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3785. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3786. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3787. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3788. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3789. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3790. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3791. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3792. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3793. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3794. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3795. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3796. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3797. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3798. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3799. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3800. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3801. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3802. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3803. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3804. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3805. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3806. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3807. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3808. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3809. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3810. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3811. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3812. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3813. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3814. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3815. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3816. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3817. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3818. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3819. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3820. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3821. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3822. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3823. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3824. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3825. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3826. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3827. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3828. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3829. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3830. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3831. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3832. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3833. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3834. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3835. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3836. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3837. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3838. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3839. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3840. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3841. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3842. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3843. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3844. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3845. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3846. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3847. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3848. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3849. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3850. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3851. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3852. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3853. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3854. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3855. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3856. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3857. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3858. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3859. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3860. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3861. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3862. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3863. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3864. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3865. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3866. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3867. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3868. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3869. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3870. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3871. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3872. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3873. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3874. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3875. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3876. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3877. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3878. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3879. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3880. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3881. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3882. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3883. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3884. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3885. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3886. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3887. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3888. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3889. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3890. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3891. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3892. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3893. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3894. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3895. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3896. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3897. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3898. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3899. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3900. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3901. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3902. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3903. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3904. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3905. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3906. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3907. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3908. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3909. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3910. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3911. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3912. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3913. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3914. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3915. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3916. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3917. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3918. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3919. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3920. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3921. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3922. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3923. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3924. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3925. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3926. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3927. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3928. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3929. };
  3930. OcspEntry entry[1];
  3931. CertStatus status[1];
  3932. OcspRequest* request = NULL;
  3933. #ifndef NO_FILESYSTEM
  3934. const char* ca_cert = "./certs/ca-cert.pem";
  3935. #endif
  3936. byte serial[] = {0x05};
  3937. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3938. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3939. XMEMSET(entry, 0, sizeof(OcspEntry));
  3940. XMEMSET(status, 0, sizeof(CertStatus));
  3941. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3942. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3943. DYNAMIC_TYPE_OCSP_REQUEST));
  3944. if ((request != NULL) && (request->serial != NULL)) {
  3945. request->serialSz = sizeof(serial);
  3946. XMEMCPY(request->serial, serial, sizeof(serial));
  3947. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3948. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3949. }
  3950. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3951. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3952. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3953. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3954. /* Response should be valid. */
  3955. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3956. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3957. /* Flip a byte in the request serial number, response should be invalid
  3958. * now. */
  3959. if ((request != NULL) && (request->serial != NULL))
  3960. request->serial[0] ^= request->serial[0];
  3961. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3962. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3963. #ifndef NO_FILESYSTEM
  3964. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3965. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3966. ExpectIntEQ(WOLFSSL_SUCCESS,
  3967. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3968. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3969. sizeof(server_cert_der_2048)), 1);
  3970. #endif
  3971. wolfSSL_OCSP_REQUEST_free(request);
  3972. wolfSSL_CertManagerFree(cm);
  3973. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3974. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3975. #endif /* HAVE_OCSP */
  3976. return EXPECT_RESULT();
  3977. }
  3978. static int test_wolfSSL_CheckOCSPResponse(void)
  3979. {
  3980. EXPECT_DECLS;
  3981. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3982. !defined(NO_RSA) && !defined(NO_SHA)
  3983. const char* responseFile = "./certs/ocsp/test-response.der";
  3984. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3985. const char* responseNoInternFile =
  3986. "./certs/ocsp/test-response-nointern.der";
  3987. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3988. OcspResponse* res = NULL;
  3989. byte data[4096];
  3990. const unsigned char* pt;
  3991. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3992. * gcc sanitizer with --enable-heapmath.
  3993. */
  3994. XFILE f = XBADFILE;
  3995. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3996. WOLFSSL_X509_STORE* st = NULL;
  3997. WOLFSSL_X509* issuer = NULL;
  3998. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  3999. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4000. if (f != XBADFILE) {
  4001. XFCLOSE(f);
  4002. f = XBADFILE;
  4003. }
  4004. pt = data;
  4005. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4006. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4007. SSL_FILETYPE_PEM));
  4008. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4009. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4010. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4011. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  4012. wolfSSL_OCSP_BASICRESP_free(bs);
  4013. bs = NULL;
  4014. wolfSSL_OCSP_RESPONSE_free(res);
  4015. res = NULL;
  4016. wolfSSL_X509_STORE_free(st);
  4017. st = NULL;
  4018. wolfSSL_X509_free(issuer);
  4019. issuer = NULL;
  4020. /* check loading a response with optional certs */
  4021. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  4022. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4023. if (f != XBADFILE)
  4024. XFCLOSE(f);
  4025. f = XBADFILE;
  4026. pt = data;
  4027. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4028. wolfSSL_OCSP_RESPONSE_free(res);
  4029. res = NULL;
  4030. /* check loading a response with multiple certs */
  4031. {
  4032. WOLFSSL_CERT_MANAGER* cm = NULL;
  4033. OcspEntry *entry = NULL;
  4034. CertStatus* status = NULL;
  4035. OcspRequest* request = NULL;
  4036. byte serial1[] = {0x01};
  4037. byte serial[] = {0x02};
  4038. byte issuerHash[] = {
  4039. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  4040. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  4041. 0x37, 0x15, 0x8A, 0x88
  4042. };
  4043. byte issuerKeyHash[] = {
  4044. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  4045. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  4046. 0x7E, 0x72, 0x15, 0x21
  4047. };
  4048. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  4049. DYNAMIC_TYPE_OPENSSL));
  4050. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  4051. DYNAMIC_TYPE_OPENSSL));
  4052. if (entry != NULL)
  4053. XMEMSET(entry, 0, sizeof(OcspEntry));
  4054. if (status != NULL)
  4055. XMEMSET(status, 0, sizeof(CertStatus));
  4056. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  4057. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  4058. DYNAMIC_TYPE_OCSP_REQUEST));
  4059. if (request != NULL && request->serial != NULL) {
  4060. request->serialSz = sizeof(serial);
  4061. XMEMCPY(request->serial, serial, sizeof(serial));
  4062. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  4063. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  4064. sizeof(issuerKeyHash));
  4065. }
  4066. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  4067. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  4068. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  4069. WOLFSSL_SUCCESS);
  4070. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  4071. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4072. if (f != XBADFILE)
  4073. XFCLOSE(f);
  4074. f = XBADFILE;
  4075. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4076. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4077. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4078. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4079. ExpectNotNull(entry->status);
  4080. if (request != NULL && request->serial != NULL)
  4081. XMEMCPY(request->serial, serial1, sizeof(serial1));
  4082. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4083. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4084. /* store both status's in the entry to check that "next" is not
  4085. * overwritten */
  4086. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  4087. status->next = entry->status;
  4088. entry->status = status;
  4089. }
  4090. if (request != NULL && request->serial != NULL)
  4091. XMEMCPY(request->serial, serial, sizeof(serial));
  4092. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4093. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4094. ExpectNotNull(entry->status->next);
  4095. /* compare the status found */
  4096. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  4097. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  4098. status->serialSz), 0);
  4099. if (status != NULL && entry != NULL && entry->status != status) {
  4100. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  4101. }
  4102. wolfSSL_OCSP_CERTID_free(entry);
  4103. wolfSSL_OCSP_REQUEST_free(request);
  4104. wolfSSL_CertManagerFree(cm);
  4105. }
  4106. #if defined(WC_RSA_PSS)
  4107. {
  4108. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  4109. /* check loading a response with RSA-PSS signature */
  4110. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  4111. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4112. if (f != XBADFILE)
  4113. XFCLOSE(f);
  4114. pt = data;
  4115. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4116. /* try to verify the response */
  4117. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4118. SSL_FILETYPE_PEM));
  4119. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4120. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4121. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4122. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  4123. WOLFSSL_SUCCESS);
  4124. wolfSSL_OCSP_BASICRESP_free(bs);
  4125. wolfSSL_OCSP_RESPONSE_free(res);
  4126. wolfSSL_X509_STORE_free(st);
  4127. wolfSSL_X509_free(issuer);
  4128. }
  4129. #endif
  4130. #endif /* HAVE_OCSP */
  4131. return EXPECT_RESULT();
  4132. }
  4133. static int test_wolfSSL_FPKI(void)
  4134. {
  4135. EXPECT_DECLS;
  4136. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4137. XFILE f = XBADFILE;
  4138. const char* fpkiCert = "./certs/fpki-cert.der";
  4139. DecodedCert cert;
  4140. byte buf[4096];
  4141. byte* uuid = NULL;
  4142. byte* fascn = NULL;
  4143. word32 fascnSz;
  4144. word32 uuidSz;
  4145. int bytes = 0;
  4146. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  4147. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4148. if (f != XBADFILE)
  4149. XFCLOSE(f);
  4150. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4151. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4152. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4153. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  4154. DYNAMIC_TYPE_TMP_BUFFER));
  4155. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  4156. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4157. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4158. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  4159. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  4160. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4161. wc_FreeDecodedCert(&cert);
  4162. #endif
  4163. return EXPECT_RESULT();
  4164. }
  4165. /* use RID in confuncture with other names to test parsing of unknown other
  4166. * names */
  4167. static int test_wolfSSL_OtherName(void)
  4168. {
  4169. EXPECT_DECLS;
  4170. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4171. XFILE f = XBADFILE;
  4172. const char* ridCert = "./certs/rid-cert.der";
  4173. DecodedCert cert;
  4174. byte buf[4096];
  4175. int bytes = 0;
  4176. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  4177. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4178. if (f != XBADFILE)
  4179. XFCLOSE(f);
  4180. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4181. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4182. wc_FreeDecodedCert(&cert);
  4183. #endif
  4184. return EXPECT_RESULT();
  4185. }
  4186. #ifdef HAVE_CERT_CHAIN_VALIDATION
  4187. static int test_wolfSSL_CertRsaPss(void)
  4188. {
  4189. EXPECT_DECLS;
  4190. /* FIPS v2 and below don't support long salts. */
  4191. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  4192. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  4193. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  4194. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  4195. XFILE f = XBADFILE;
  4196. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  4197. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  4198. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4199. RSA_MAX_SIZE >= 3072
  4200. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  4201. #endif
  4202. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4203. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  4204. #endif
  4205. DecodedCert cert;
  4206. byte buf[4096];
  4207. int bytes = 0;
  4208. WOLFSSL_CERT_MANAGER* cm = NULL;
  4209. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  4210. ExpectIntEQ(WOLFSSL_SUCCESS,
  4211. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  4212. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4213. ExpectIntEQ(WOLFSSL_SUCCESS,
  4214. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4215. #endif
  4216. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4217. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4218. if (f != XBADFILE) {
  4219. XFCLOSE(f);
  4220. f = XBADFILE;
  4221. }
  4222. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4223. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4224. wc_FreeDecodedCert(&cert);
  4225. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4226. RSA_MAX_SIZE >= 3072
  4227. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4228. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4229. if (f != XBADFILE)
  4230. XFCLOSE(f);
  4231. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4232. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4233. wc_FreeDecodedCert(&cert);
  4234. #endif
  4235. wolfSSL_CertManagerFree(cm);
  4236. #endif
  4237. return EXPECT_RESULT();
  4238. }
  4239. #endif
  4240. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4241. {
  4242. EXPECT_DECLS;
  4243. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4244. !defined(NO_WOLFSSL_CLIENT)
  4245. WOLFSSL_CTX* ctx = NULL;
  4246. const char* ca_cert = "./certs/ca-cert.pem";
  4247. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4248. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4249. /* test good CA */
  4250. ExpectTrue(WOLFSSL_SUCCESS ==
  4251. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4252. WOLFSSL_LOAD_FLAG_NONE));
  4253. /* test expired CA */
  4254. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4255. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4256. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4257. #else
  4258. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4259. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4260. #endif
  4261. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4262. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4263. wolfSSL_CTX_free(ctx);
  4264. #endif
  4265. return EXPECT_RESULT();
  4266. }
  4267. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4268. {
  4269. EXPECT_DECLS;
  4270. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4271. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4272. WOLFSSL_CTX* ctx;
  4273. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4274. byte ca_expired_cert[TWOK_BUF];
  4275. word32 sizeof_ca_expired_cert = 0;
  4276. XFILE fp = XBADFILE;
  4277. #ifndef NO_WOLFSSL_CLIENT
  4278. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4279. #else
  4280. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4281. #endif
  4282. ExpectNotNull(ctx);
  4283. #if defined(USE_CERT_BUFFERS_2048)
  4284. /* test good CA */
  4285. ExpectTrue(WOLFSSL_SUCCESS ==
  4286. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4287. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4288. WOLFSSL_LOAD_FLAG_NONE));
  4289. #endif
  4290. /* load expired CA */
  4291. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4292. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4293. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4294. sizeof(ca_expired_cert), fp), 0);
  4295. if (fp != XBADFILE)
  4296. XFCLOSE(fp);
  4297. /* test expired CA failure */
  4298. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4299. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4300. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4301. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4302. #else
  4303. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4304. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4305. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4306. #endif
  4307. /* test expired CA success */
  4308. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4309. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4310. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4311. /* Fail when ctx is NULL. */
  4312. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4313. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4314. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4315. /* Load as modified cert - bad initial length. */
  4316. ca_expired_cert[2] = 0x7f;
  4317. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4318. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4319. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4320. wolfSSL_CTX_free(ctx);
  4321. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4322. #endif
  4323. return EXPECT_RESULT();
  4324. }
  4325. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4326. {
  4327. EXPECT_DECLS;
  4328. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4329. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4330. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4331. WOLFSSL_CTX* ctx = NULL;
  4332. #ifndef NO_WOLFSSL_CLIENT
  4333. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4334. #else
  4335. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4336. #endif
  4337. /* Public key 140 bytes??? */
  4338. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4339. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4340. WOLFSSL_SUCCESS);
  4341. wolfSSL_CTX_free(ctx);
  4342. #endif
  4343. return EXPECT_RESULT();
  4344. }
  4345. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4346. {
  4347. EXPECT_DECLS;
  4348. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4349. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4350. WOLFSSL_CTX* ctx;
  4351. WOLFSSL* ssl = NULL;
  4352. const char *certChain[] = {
  4353. "./certs/intermediate/client-int-cert.pem",
  4354. "./certs/intermediate/ca-int2-cert.pem",
  4355. "./certs/intermediate/ca-int-cert.pem",
  4356. "./certs/ca-cert.pem",
  4357. NULL
  4358. };
  4359. const char** cert;
  4360. WOLFSSL_X509* x509 = NULL;
  4361. WOLF_STACK_OF(X509)* chain = NULL;
  4362. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4363. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4364. ExpectNotNull(x509 = wolfSSL_X509_new());
  4365. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4366. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4367. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4368. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4369. wolfSSL_X509_free(x509);
  4370. x509 = NULL;
  4371. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4372. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4373. WOLFSSL_FILETYPE_PEM));
  4374. /* Do negative tests once */
  4375. if (cert == certChain) {
  4376. /* Negative tests. */
  4377. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4378. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4379. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4380. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4381. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4382. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4383. }
  4384. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4385. X509_free(x509);
  4386. x509 = NULL;
  4387. }
  4388. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4389. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4390. WOLFSSL_FILETYPE_PEM));
  4391. /* Do negative tests once */
  4392. if (cert == certChain) {
  4393. /* Negative tests. */
  4394. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4395. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4396. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4397. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4398. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4399. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4400. }
  4401. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4402. X509_free(x509);
  4403. x509 = NULL;
  4404. }
  4405. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4406. ExpectIntEQ(sk_X509_num(chain), 3);
  4407. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4408. ExpectIntEQ(sk_X509_num(chain), 3);
  4409. SSL_free(ssl);
  4410. SSL_CTX_free(ctx);
  4411. #endif
  4412. return EXPECT_RESULT();
  4413. }
  4414. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4415. {
  4416. EXPECT_DECLS;
  4417. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4418. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4419. WOLFSSL_CTX* ctx = NULL;
  4420. WOLFSSL* ssl = NULL;
  4421. const char* cert = "./certs/server-cert.pem";
  4422. unsigned char* buf = NULL;
  4423. size_t len;
  4424. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4425. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4426. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4427. /* Invalid parameters. */
  4428. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4429. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4430. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4431. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4432. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4433. server_cert_der_2048, sizeof_server_cert_der_2048,
  4434. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4435. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4436. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4437. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4438. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4439. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (long)len),
  4440. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4441. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4443. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4444. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4445. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (long)len),
  4446. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4447. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4448. server_cert_der_2048, sizeof_server_cert_der_2048,
  4449. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4450. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4451. (long)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4452. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (long)len),
  4453. WOLFSSL_SUCCESS);
  4454. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4455. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4456. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (long)len),
  4457. WOLFSSL_SUCCESS);
  4458. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4459. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4460. wolfSSL_free(ssl);
  4461. wolfSSL_CTX_free(ctx);
  4462. if (buf != NULL) {
  4463. free(buf);
  4464. }
  4465. #endif
  4466. return EXPECT_RESULT();
  4467. }
  4468. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4469. {
  4470. EXPECT_DECLS;
  4471. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4472. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4473. const char* server_chain_der = "./certs/server-cert-chain.der";
  4474. const char* client_single_pem = "./certs/client-cert.pem";
  4475. WOLFSSL_CTX* ctx = NULL;
  4476. (void)server_chain_der;
  4477. (void)client_single_pem;
  4478. (void)ctx;
  4479. #ifndef NO_WOLFSSL_CLIENT
  4480. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4481. #else
  4482. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4483. #endif
  4484. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4485. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4486. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4487. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4488. wolfSSL_CTX_free(ctx);
  4489. #endif
  4490. return EXPECT_RESULT();
  4491. }
  4492. static int test_wolfSSL_use_certificate_chain_file(void)
  4493. {
  4494. EXPECT_DECLS;
  4495. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4496. !defined(NO_WOLFSSL_CLIENT)
  4497. const char* server_chain_der = "./certs/server-cert-chain.der";
  4498. const char* client_single_pem = "./certs/client-cert.pem";
  4499. WOLFSSL_CTX* ctx = NULL;
  4500. WOLFSSL* ssl = NULL;
  4501. (void)server_chain_der;
  4502. (void)client_single_pem;
  4503. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4504. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4505. /* Invalid parameters. */
  4506. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4507. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4508. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4509. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4510. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4511. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4512. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4513. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4514. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4515. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4516. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4517. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4518. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4519. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4520. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4521. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4522. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4523. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4524. WOLFSSL_SUCCESS);
  4525. wolfSSL_free(ssl);
  4526. wolfSSL_CTX_free(ctx);
  4527. #endif
  4528. return EXPECT_RESULT();
  4529. }
  4530. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4531. {
  4532. EXPECT_DECLS;
  4533. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4534. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4535. WOLFSSL_CTX *ctx = NULL;
  4536. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4537. const char* dsaParamFile = "./certs/dsaparams.pem";
  4538. #endif
  4539. (void)ctx;
  4540. #ifndef NO_WOLFSSL_CLIENT
  4541. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4542. #else
  4543. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4544. #endif
  4545. /* invalid context */
  4546. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4547. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4548. /* invalid dhParamFile file */
  4549. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4550. NULL, WOLFSSL_FILETYPE_PEM));
  4551. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4552. bogusFile, WOLFSSL_FILETYPE_PEM));
  4553. /* success */
  4554. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4555. WOLFSSL_FILETYPE_PEM));
  4556. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4557. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4558. WOLFSSL_FILETYPE_PEM));
  4559. #endif
  4560. wolfSSL_CTX_free(ctx);
  4561. #endif
  4562. return EXPECT_RESULT();
  4563. }
  4564. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4565. {
  4566. EXPECT_DECLS;
  4567. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4568. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4569. WOLFSSL_CTX *ctx = NULL;
  4570. #ifndef NO_WOLFSSL_CLIENT
  4571. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4572. #else
  4573. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4574. #endif
  4575. /* invalid context */
  4576. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4577. dh_key_der_2048, sizeof_dh_key_der_2048,
  4578. WOLFSSL_FILETYPE_ASN1));
  4579. /* invalid dhParamFile file */
  4580. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4581. 0, WOLFSSL_FILETYPE_ASN1));
  4582. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4583. 0, WOLFSSL_FILETYPE_ASN1));
  4584. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4585. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4586. WOLFSSL_FILETYPE_ASN1));
  4587. /* invalid file format */
  4588. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4589. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4590. /* success */
  4591. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4592. dh_key_der_2048, sizeof_dh_key_der_2048,
  4593. WOLFSSL_FILETYPE_ASN1));
  4594. wolfSSL_CTX_free(ctx);
  4595. #endif
  4596. return EXPECT_RESULT();
  4597. }
  4598. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4599. {
  4600. EXPECT_DECLS;
  4601. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4602. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4603. WOLFSSL_CTX *ctx;
  4604. (void)ctx;
  4605. #ifndef NO_WOLFSSL_CLIENT
  4606. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4607. #else
  4608. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4609. #endif
  4610. ExpectNotNull(ctx);
  4611. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4612. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4613. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4614. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4615. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4616. dh_key_der_2048, sizeof_dh_key_der_2048,
  4617. WOLFSSL_FILETYPE_ASN1));
  4618. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4619. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4620. dh_key_der_2048, sizeof_dh_key_der_2048,
  4621. WOLFSSL_FILETYPE_ASN1));
  4622. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 2048));
  4623. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4624. dh_key_der_2048, sizeof_dh_key_der_2048,
  4625. WOLFSSL_FILETYPE_ASN1));
  4626. wolfSSL_CTX_free(ctx);
  4627. #endif
  4628. return EXPECT_RESULT();
  4629. }
  4630. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4631. {
  4632. EXPECT_DECLS;
  4633. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4634. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4635. WOLFSSL_CTX* ctx = NULL;
  4636. const char* derCert = "./certs/server-cert.der";
  4637. const char* nullPath = NULL;
  4638. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4639. const char* emptyPath = "";
  4640. /* der load Case 1 ctx NULL */
  4641. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4642. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4643. #ifndef NO_WOLFSSL_CLIENT
  4644. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4645. #else
  4646. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4647. #endif
  4648. /* Case 2 filePath NULL */
  4649. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4650. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4651. /* Case 3 invalid format */
  4652. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4653. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4654. /* Case 4 filePath not valid */
  4655. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4656. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4657. /* Case 5 filePath empty */
  4658. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4659. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4660. #ifndef NO_RSA
  4661. /* Case 6 success case */
  4662. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4663. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4664. #endif
  4665. wolfSSL_CTX_free(ctx);
  4666. #endif
  4667. return EXPECT_RESULT();
  4668. }
  4669. static int test_wolfSSL_CTX_enable_disable(void)
  4670. {
  4671. EXPECT_DECLS;
  4672. #ifndef NO_CERTS
  4673. WOLFSSL_CTX* ctx = NULL;
  4674. #ifdef HAVE_CRL
  4675. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4676. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4677. #endif
  4678. #ifdef HAVE_OCSP
  4679. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4680. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4681. #endif
  4682. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4683. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4684. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4685. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4686. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4687. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4688. #endif
  4689. #ifndef NO_WOLFSSL_CLIENT
  4690. #ifdef HAVE_EXTENDED_MASTER
  4691. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4692. #endif
  4693. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4694. #ifdef HAVE_EXTENDED_MASTER
  4695. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4696. #endif
  4697. #elif !defined(NO_WOLFSSL_SERVER)
  4698. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4699. #endif
  4700. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4701. #ifdef HAVE_CRL
  4702. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4703. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4704. #endif
  4705. #ifdef HAVE_OCSP
  4706. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4707. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4708. WOLFSSL_SUCCESS);
  4709. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4710. WOLFSSL_SUCCESS);
  4711. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4712. WOLFSSL_SUCCESS);
  4713. #endif
  4714. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4715. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4716. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4717. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4718. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4719. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4720. #endif
  4721. wolfSSL_CTX_free(ctx);
  4722. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4723. #endif /* NO_CERTS */
  4724. return EXPECT_RESULT();
  4725. }
  4726. static int test_wolfSSL_CTX_ticket_API(void)
  4727. {
  4728. EXPECT_DECLS;
  4729. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4730. WOLFSSL_CTX* ctx = NULL;
  4731. void *userCtx = (void*)"this is my ctx";
  4732. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4733. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4734. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4735. wolfSSL_CTX_free(ctx);
  4736. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4737. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4738. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4739. return EXPECT_RESULT();
  4740. }
  4741. static int test_wolfSSL_set_minmax_proto_version(void)
  4742. {
  4743. EXPECT_DECLS;
  4744. #ifdef OPENSSL_EXTRA
  4745. WOLFSSL_CTX *ctx = NULL;
  4746. WOLFSSL *ssl = NULL;
  4747. (void)ssl;
  4748. #ifndef NO_WOLFSSL_CLIENT
  4749. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4750. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4751. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4752. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4753. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4754. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4755. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4756. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4757. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4758. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4759. wolfSSL_free(ssl);
  4760. wolfSSL_CTX_free(ctx);
  4761. ctx = NULL;
  4762. #endif
  4763. #ifndef NO_WOLFSSL_SERVER
  4764. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4765. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4766. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4767. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4768. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4769. wolfSSL_CTX_free(ctx);
  4770. #endif
  4771. #endif
  4772. return EXPECT_RESULT();
  4773. }
  4774. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4775. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4776. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4777. {
  4778. EXPECT_DECLS;
  4779. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4780. return EXPECT_RESULT();
  4781. }
  4782. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4783. {
  4784. EXPECT_DECLS;
  4785. /* Set TLS 1.2 */
  4786. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4787. WOLFSSL_SUCCESS);
  4788. return EXPECT_RESULT();
  4789. }
  4790. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4791. * what was set at ctx creation. */
  4792. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4793. {
  4794. EXPECT_DECLS;
  4795. test_ssl_cbf client_cbs;
  4796. test_ssl_cbf server_cbs;
  4797. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4798. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4799. client_cbs.method = wolfTLS_client_method;
  4800. server_cbs.method = wolfTLS_server_method;
  4801. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4802. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4803. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4804. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4805. &server_cbs, NULL), TEST_SUCCESS);
  4806. return EXPECT_RESULT();
  4807. }
  4808. #else
  4809. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4810. {
  4811. return TEST_SKIPPED;
  4812. }
  4813. #endif
  4814. /*----------------------------------------------------------------------------*
  4815. | SSL
  4816. *----------------------------------------------------------------------------*/
  4817. static int test_server_wolfSSL_new(void)
  4818. {
  4819. EXPECT_DECLS;
  4820. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4821. !defined(NO_WOLFSSL_SERVER)
  4822. WOLFSSL_CTX *ctx = NULL;
  4823. WOLFSSL_CTX *ctx_nocert = NULL;
  4824. WOLFSSL *ssl = NULL;
  4825. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4826. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4827. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4828. WOLFSSL_FILETYPE_PEM));
  4829. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4830. WOLFSSL_FILETYPE_PEM));
  4831. /* invalid context */
  4832. ExpectNull(ssl = wolfSSL_new(NULL));
  4833. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4834. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4835. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4836. #endif
  4837. /* success */
  4838. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4839. wolfSSL_free(ssl);
  4840. wolfSSL_CTX_free(ctx);
  4841. wolfSSL_CTX_free(ctx_nocert);
  4842. #endif
  4843. return EXPECT_RESULT();
  4844. }
  4845. static int test_client_wolfSSL_new(void)
  4846. {
  4847. EXPECT_DECLS;
  4848. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4849. !defined(NO_WOLFSSL_CLIENT)
  4850. WOLFSSL_CTX *ctx = NULL;
  4851. WOLFSSL_CTX *ctx_nocert = NULL;
  4852. WOLFSSL *ssl = NULL;
  4853. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4854. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4855. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4856. /* invalid context */
  4857. ExpectNull(ssl = wolfSSL_new(NULL));
  4858. /* success */
  4859. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4860. wolfSSL_free(ssl);
  4861. ssl = NULL;
  4862. /* success */
  4863. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4864. wolfSSL_free(ssl);
  4865. wolfSSL_CTX_free(ctx);
  4866. wolfSSL_CTX_free(ctx_nocert);
  4867. #endif
  4868. return EXPECT_RESULT();
  4869. }
  4870. static int test_wolfSSL_SetTmpDH_file(void)
  4871. {
  4872. EXPECT_DECLS;
  4873. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4874. !defined(NO_WOLFSSL_SERVER)
  4875. WOLFSSL_CTX *ctx = NULL;
  4876. WOLFSSL *ssl = NULL;
  4877. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4878. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4879. const char* dsaParamFile = "./certs/dsaparams.pem";
  4880. #endif
  4881. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4882. #ifndef NO_RSA
  4883. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4884. WOLFSSL_FILETYPE_PEM));
  4885. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4886. WOLFSSL_FILETYPE_PEM));
  4887. #elif defined(HAVE_ECC)
  4888. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4889. WOLFSSL_FILETYPE_PEM));
  4890. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4891. WOLFSSL_FILETYPE_PEM));
  4892. #elif defined(HAVE_ED25519)
  4893. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4894. WOLFSSL_FILETYPE_PEM));
  4895. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4896. WOLFSSL_FILETYPE_PEM));
  4897. #elif defined(HAVE_ED448)
  4898. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4899. WOLFSSL_FILETYPE_PEM));
  4900. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4901. WOLFSSL_FILETYPE_PEM));
  4902. #endif
  4903. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4904. /* invalid ssl */
  4905. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4906. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4907. /* invalid dhParamFile file */
  4908. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4909. NULL, WOLFSSL_FILETYPE_PEM));
  4910. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4911. bogusFile, WOLFSSL_FILETYPE_PEM));
  4912. /* success */
  4913. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4914. WOLFSSL_FILETYPE_PEM));
  4915. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4916. WOLFSSL_FILETYPE_PEM));
  4917. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4918. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4919. WOLFSSL_FILETYPE_PEM));
  4920. #endif
  4921. wolfSSL_free(ssl);
  4922. wolfSSL_CTX_free(ctx);
  4923. #endif
  4924. return EXPECT_RESULT();
  4925. }
  4926. static int test_wolfSSL_SetTmpDH_buffer(void)
  4927. {
  4928. EXPECT_DECLS;
  4929. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4930. WOLFSSL_CTX *ctx = NULL;
  4931. WOLFSSL *ssl = NULL;
  4932. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4933. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4934. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4935. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4936. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4937. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4938. /* invalid ssl */
  4939. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4940. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4941. /* invalid dhParamFile file */
  4942. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4943. 0, WOLFSSL_FILETYPE_ASN1));
  4944. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4945. WOLFSSL_FILETYPE_ASN1));
  4946. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4947. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4948. /* success */
  4949. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4950. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4951. wolfSSL_free(ssl);
  4952. wolfSSL_CTX_free(ctx);
  4953. #endif
  4954. return EXPECT_RESULT();
  4955. }
  4956. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4957. {
  4958. EXPECT_DECLS;
  4959. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4960. WOLFSSL_CTX *ctx = NULL;
  4961. WOLFSSL_CTX *ctx2 = NULL;
  4962. WOLFSSL *ssl = NULL;
  4963. WOLFSSL *ssl2 = NULL;
  4964. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4965. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4966. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4967. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4968. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4969. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4970. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4971. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4972. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4973. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4974. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4975. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4976. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4977. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4978. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4979. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4980. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4981. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4982. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4983. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4984. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4985. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4986. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4987. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4988. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4989. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4990. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4991. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4992. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4993. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4994. wolfSSL_free(ssl2);
  4995. wolfSSL_CTX_free(ctx2);
  4996. wolfSSL_free(ssl);
  4997. wolfSSL_CTX_free(ctx);
  4998. #endif
  4999. return EXPECT_RESULT();
  5000. }
  5001. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  5002. * allowed.
  5003. * POST: return 1 on success.
  5004. */
  5005. static int test_wolfSSL_SetMinVersion(void)
  5006. {
  5007. int res = TEST_SKIPPED;
  5008. #ifndef NO_WOLFSSL_CLIENT
  5009. int failFlag = WOLFSSL_SUCCESS;
  5010. WOLFSSL_CTX* ctx = NULL;
  5011. WOLFSSL* ssl = NULL;
  5012. int itr;
  5013. #ifndef NO_OLD_TLS
  5014. const int versions[] = {
  5015. #ifdef WOLFSSL_ALLOW_TLSV10
  5016. WOLFSSL_TLSV1,
  5017. #endif
  5018. WOLFSSL_TLSV1_1,
  5019. WOLFSSL_TLSV1_2};
  5020. #elif !defined(WOLFSSL_NO_TLS12)
  5021. const int versions[] = { WOLFSSL_TLSV1_2 };
  5022. #else
  5023. const int versions[] = { WOLFSSL_TLSV1_3 };
  5024. #endif
  5025. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  5026. ssl = wolfSSL_new(ctx);
  5027. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  5028. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  5029. failFlag = WOLFSSL_FAILURE;
  5030. }
  5031. }
  5032. wolfSSL_free(ssl);
  5033. wolfSSL_CTX_free(ctx);
  5034. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  5035. #endif
  5036. return res;
  5037. } /* END test_wolfSSL_SetMinVersion */
  5038. #ifdef OPENSSL_EXTRA
  5039. static int test_EC25519(void)
  5040. {
  5041. EXPECT_DECLS;
  5042. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  5043. byte priv[CURVE25519_KEYSIZE];
  5044. unsigned int privSz = CURVE25519_KEYSIZE;
  5045. byte pub[CURVE25519_KEYSIZE];
  5046. unsigned int pubSz = CURVE25519_KEYSIZE;
  5047. byte priv2[CURVE25519_KEYSIZE];
  5048. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  5049. byte pub2[CURVE25519_KEYSIZE];
  5050. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  5051. byte shared[CURVE25519_KEYSIZE];
  5052. unsigned int sharedSz = CURVE25519_KEYSIZE;
  5053. byte shared2[CURVE25519_KEYSIZE];
  5054. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  5055. /* Bad parameter testing of key generation. */
  5056. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5057. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5058. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5059. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5060. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5061. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  5062. /* Bad length */
  5063. privSz = 1;
  5064. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5065. privSz = CURVE25519_KEYSIZE;
  5066. pubSz = 1;
  5067. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5068. pubSz = CURVE25519_KEYSIZE;
  5069. /* Good case of generating key. */
  5070. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  5071. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  5072. 1);
  5073. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  5074. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  5075. /* Bad parameter testing of shared key. */
  5076. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  5077. NULL, pubSz), 0);
  5078. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  5079. NULL, pubSz), 0);
  5080. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5081. pub, pubSz), 0);
  5082. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5083. pub, pubSz), 0);
  5084. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5085. NULL, pubSz), 0);
  5086. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5087. pub, pubSz), 0);
  5088. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  5089. pub, pubSz), 0);
  5090. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5091. pub, pubSz), 0);
  5092. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5093. NULL, pubSz), 0);
  5094. /* Bad length. */
  5095. sharedSz = 1;
  5096. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5097. pub, pubSz), 0);
  5098. sharedSz = CURVE25519_KEYSIZE;
  5099. privSz = 1;
  5100. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5101. pub, pubSz), 0);
  5102. privSz = CURVE25519_KEYSIZE;
  5103. pubSz = 1;
  5104. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5105. pub, pubSz), 0);
  5106. pubSz = CURVE25519_KEYSIZE;
  5107. /* Good case of shared key. */
  5108. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5109. pub2, pub2Sz), 1);
  5110. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5111. pub, pubSz), 1);
  5112. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  5113. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  5114. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5115. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  5116. return EXPECT_RESULT();
  5117. }
  5118. static int test_ED25519(void)
  5119. {
  5120. EXPECT_DECLS;
  5121. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  5122. defined(WOLFSSL_KEY_GEN)
  5123. byte priv[ED25519_PRV_KEY_SIZE];
  5124. unsigned int privSz = (unsigned int)sizeof(priv);
  5125. byte pub[ED25519_PUB_KEY_SIZE];
  5126. unsigned int pubSz = (unsigned int)sizeof(pub);
  5127. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5128. const char* msg = TEST_STRING;
  5129. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5130. byte sig[ED25519_SIG_SIZE];
  5131. unsigned int sigSz = (unsigned int)sizeof(sig);
  5132. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5133. /* Bad parameter testing of key generation. */
  5134. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5135. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  5136. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  5137. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  5138. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5139. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5140. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5141. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5142. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  5143. /* Bad length. */
  5144. privSz = 1;
  5145. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5146. privSz = ED25519_PRV_KEY_SIZE;
  5147. pubSz = 1;
  5148. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5149. pubSz = ED25519_PUB_KEY_SIZE;
  5150. /* Good case of generating key. */
  5151. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  5152. 1);
  5153. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  5154. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  5155. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5156. /* Bad parameter testing of signing. */
  5157. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5158. NULL), 0);
  5159. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5160. NULL), 0);
  5161. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  5162. NULL), 0);
  5163. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  5164. NULL), 0);
  5165. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5166. &sigSz), 0);
  5167. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  5168. &sigSz), 0);
  5169. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  5170. &sigSz), 0);
  5171. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  5172. &sigSz), 0);
  5173. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5174. NULL), 0);
  5175. /* Bad length. */
  5176. privSz = 1;
  5177. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5178. &sigSz), 0);
  5179. privSz = ED25519_PRV_KEY_SIZE;
  5180. sigSz = 1;
  5181. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5182. &sigSz), 0);
  5183. sigSz = ED25519_SIG_SIZE;
  5184. /* Good case of signing. */
  5185. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5186. &sigSz), 1);
  5187. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  5188. #ifdef HAVE_ED25519_VERIFY
  5189. /* Bad parameter testing of verification. */
  5190. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  5191. sigSz), 0);
  5192. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5193. sigSz), 0);
  5194. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  5195. sigSz), 0);
  5196. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  5197. sigSz), 0);
  5198. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  5199. sigSz), 0);
  5200. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5201. sigSz), 0);
  5202. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5203. sigSz), 0);
  5204. /* Bad length. */
  5205. pubSz = 1;
  5206. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5207. sigSz), 0);
  5208. pubSz = ED25519_PUB_KEY_SIZE;
  5209. sigSz = 1;
  5210. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5211. sigSz), 0);
  5212. sigSz = ED25519_SIG_SIZE;
  5213. /* Good case of verification. */
  5214. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5215. sigSz), 1);
  5216. /* Bad signature. */
  5217. if (EXPECT_SUCCESS()) {
  5218. sig[1] ^= 0x80;
  5219. }
  5220. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5221. sigSz), 0);
  5222. #endif /* HAVE_ED25519_VERIFY */
  5223. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5224. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5225. return EXPECT_RESULT();
  5226. }
  5227. static int test_EC448(void)
  5228. {
  5229. EXPECT_DECLS;
  5230. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5231. byte priv[CURVE448_KEY_SIZE];
  5232. unsigned int privSz = CURVE448_KEY_SIZE;
  5233. byte pub[CURVE448_KEY_SIZE];
  5234. unsigned int pubSz = CURVE448_KEY_SIZE;
  5235. byte priv2[CURVE448_KEY_SIZE];
  5236. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5237. byte pub2[CURVE448_KEY_SIZE];
  5238. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5239. byte shared[CURVE448_KEY_SIZE];
  5240. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5241. byte shared2[CURVE448_KEY_SIZE];
  5242. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5243. /* Bad parameter testing of key generation. */
  5244. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5245. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5246. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5247. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5248. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5249. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5250. /* Bad length. */
  5251. privSz = 1;
  5252. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5253. privSz = CURVE448_KEY_SIZE;
  5254. pubSz = 1;
  5255. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5256. pubSz = CURVE448_KEY_SIZE;
  5257. /* Good case of generating key. */
  5258. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5259. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5260. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5261. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5262. /* Bad parameter testing of shared key. */
  5263. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5264. NULL, pubSz), 0);
  5265. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5266. NULL, pubSz), 0);
  5267. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5268. pub, pubSz), 0);
  5269. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5270. pub, pubSz), 0);
  5271. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5272. NULL, pubSz), 0);
  5273. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5274. pub, pubSz), 0);
  5275. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5276. pub, pubSz), 0);
  5277. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5278. pub, pubSz), 0);
  5279. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5280. NULL, pubSz), 0);
  5281. /* Bad length. */
  5282. sharedSz = 1;
  5283. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5284. pub, pubSz), 0);
  5285. sharedSz = CURVE448_KEY_SIZE;
  5286. privSz = 1;
  5287. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5288. pub, pubSz), 0);
  5289. privSz = CURVE448_KEY_SIZE;
  5290. pubSz = 1;
  5291. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5292. pub, pubSz), 0);
  5293. pubSz = CURVE448_KEY_SIZE;
  5294. /* Good case of shared key. */
  5295. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5296. pub2, pub2Sz), 1);
  5297. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5298. pub, pubSz), 1);
  5299. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5300. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5301. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5302. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5303. return EXPECT_RESULT();
  5304. }
  5305. static int test_ED448(void)
  5306. {
  5307. EXPECT_DECLS;
  5308. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5309. defined(WOLFSSL_KEY_GEN)
  5310. byte priv[ED448_PRV_KEY_SIZE];
  5311. unsigned int privSz = (unsigned int)sizeof(priv);
  5312. byte pub[ED448_PUB_KEY_SIZE];
  5313. unsigned int pubSz = (unsigned int)sizeof(pub);
  5314. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5315. const char* msg = TEST_STRING;
  5316. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5317. byte sig[ED448_SIG_SIZE];
  5318. unsigned int sigSz = (unsigned int)sizeof(sig);
  5319. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5320. /* Bad parameter testing of key generation. */
  5321. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5322. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5323. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5324. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5325. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5326. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5327. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5328. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5329. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5330. /* Bad length. */
  5331. privSz = 1;
  5332. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5333. privSz = ED448_PRV_KEY_SIZE;
  5334. pubSz = 1;
  5335. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5336. pubSz = ED448_PUB_KEY_SIZE;
  5337. /* Good case of generating key. */
  5338. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5339. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5340. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5341. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5342. /* Bad parameter testing of signing. */
  5343. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5344. NULL), 0);
  5345. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5346. NULL), 0);
  5347. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5348. NULL), 0);
  5349. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5350. NULL), 0);
  5351. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5352. &sigSz), 0);
  5353. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5354. &sigSz), 0);
  5355. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5356. &sigSz), 0);
  5357. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5358. &sigSz), 0);
  5359. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5360. NULL), 0);
  5361. /* Bad length. */
  5362. privSz = 1;
  5363. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5364. &sigSz), 0);
  5365. privSz = ED448_PRV_KEY_SIZE;
  5366. sigSz = 1;
  5367. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5368. &sigSz), 0);
  5369. sigSz = ED448_SIG_SIZE;
  5370. /* Good case of signing. */
  5371. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5372. &sigSz), 1);
  5373. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5374. #ifdef HAVE_ED448_VERIFY
  5375. /* Bad parameter testing of verification. */
  5376. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5377. sigSz), 0);
  5378. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5379. sigSz), 0);
  5380. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5381. sigSz), 0);
  5382. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5383. sigSz), 0);
  5384. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5385. sigSz), 0);
  5386. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5387. sigSz), 0);
  5388. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5389. sigSz), 0);
  5390. /* Bad length. */
  5391. pubSz = 1;
  5392. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5393. sigSz), 0);
  5394. pubSz = ED448_PUB_KEY_SIZE;
  5395. sigSz = 1;
  5396. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5397. sigSz), 0);
  5398. sigSz = ED448_SIG_SIZE;
  5399. /* Good case of verification. */
  5400. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5401. sigSz), 1);
  5402. /* Bad signature. */
  5403. if (EXPECT_SUCCESS()) {
  5404. sig[1] ^= 0x80;
  5405. }
  5406. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5407. sigSz), 0);
  5408. #endif /* HAVE_ED448_VERIFY */
  5409. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5410. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5411. return EXPECT_RESULT();
  5412. }
  5413. #endif /* OPENSSL_EXTRA */
  5414. #include <wolfssl/openssl/pem.h>
  5415. /*----------------------------------------------------------------------------*
  5416. | EVP
  5417. *----------------------------------------------------------------------------*/
  5418. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5419. {
  5420. EXPECT_DECLS;
  5421. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5422. WOLFSSL_BIO* rbio = NULL;
  5423. WOLFSSL_BIO* wbio = NULL;
  5424. WOLFSSL_EVP_PKEY* pkey = NULL;
  5425. char line[256] = { 0 };
  5426. char line1[256] = { 0 };
  5427. int i = 0;
  5428. /* test error cases */
  5429. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5430. /*
  5431. * test RSA public key print
  5432. * in this test, pass '3' for indent
  5433. */
  5434. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5435. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5436. sizeof_client_keypub_der_1024));
  5437. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5438. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5439. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5440. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5441. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5442. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5443. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5444. strcpy(line1, " Modulus:\n");
  5445. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5446. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5447. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5448. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5449. /* skip to the end of modulus element*/
  5450. for (i = 0; i < 8 ;i++) {
  5451. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5452. }
  5453. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5454. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5455. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5456. /* should reach EOF */
  5457. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5458. EVP_PKEY_free(pkey);
  5459. pkey = NULL;
  5460. BIO_free(rbio);
  5461. BIO_free(wbio);
  5462. rbio = NULL;
  5463. wbio = NULL;
  5464. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5465. /*
  5466. * test DSA public key print
  5467. */
  5468. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5469. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5470. sizeof_dsa_pub_key_der_2048));
  5471. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5472. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5473. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5474. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5475. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5476. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5477. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5478. strcpy(line1, "pub:\n");
  5479. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5480. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5481. strcpy(line1,
  5482. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5483. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5484. /* skip to the end of pub element*/
  5485. for (i = 0; i < 17 ;i++) {
  5486. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5487. }
  5488. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5489. strcpy(line1, "P:\n");
  5490. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5491. /* skip to the end of P element*/
  5492. for (i = 0; i < 18 ;i++) {
  5493. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5494. }
  5495. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5496. strcpy(line1, "Q:\n");
  5497. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5498. /* skip to the end of Q element*/
  5499. for (i = 0; i < 3 ;i++) {
  5500. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5501. }
  5502. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5503. strcpy(line1, "G:\n");
  5504. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5505. /* skip to the end of G element*/
  5506. for (i = 0; i < 18 ;i++) {
  5507. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5508. }
  5509. /* should reach EOF */
  5510. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5511. EVP_PKEY_free(pkey);
  5512. pkey = NULL;
  5513. BIO_free(rbio);
  5514. BIO_free(wbio);
  5515. rbio = NULL;
  5516. wbio = NULL;
  5517. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5518. /*
  5519. * test ECC public key print
  5520. */
  5521. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5522. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5523. sizeof_ecc_clikeypub_der_256));
  5524. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5525. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5526. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5527. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5528. strcpy(line1, "Public-Key: (256 bit)\n");
  5529. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5530. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5531. strcpy(line1, "pub:\n");
  5532. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5533. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5534. strcpy(line1,
  5535. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5536. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5537. /* skip to the end of pub element*/
  5538. for (i = 0; i < 4 ;i++) {
  5539. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5540. }
  5541. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5542. strcpy(line1, "ASN1 OID: prime256v1\n");
  5543. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5544. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5545. strcpy(line1, "NIST CURVE: P-256\n");
  5546. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5547. /* should reach EOF */
  5548. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5549. EVP_PKEY_free(pkey);
  5550. pkey = NULL;
  5551. BIO_free(rbio);
  5552. BIO_free(wbio);
  5553. rbio = NULL;
  5554. wbio = NULL;
  5555. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5556. /*
  5557. * test DH public key print
  5558. */
  5559. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5560. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5561. sizeof_dh_pub_key_der_2048));
  5562. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5563. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5564. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5565. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5566. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5567. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5568. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5569. strcpy(line1, "public-key:\n");
  5570. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5571. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5572. strcpy(line1,
  5573. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5574. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5575. /* skip to the end of public-key element*/
  5576. for (i = 0; i < 17 ;i++) {
  5577. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5578. }
  5579. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5580. strcpy(line1, "prime:\n");
  5581. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5582. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5583. strcpy(line1,
  5584. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5585. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5586. /* skip to the end of prime element*/
  5587. for (i = 0; i < 17 ;i++) {
  5588. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5589. }
  5590. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5591. strcpy(line1, "generator: 2 (0x02)\n");
  5592. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5593. /* should reach EOF */
  5594. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5595. EVP_PKEY_free(pkey);
  5596. pkey = NULL;
  5597. BIO_free(rbio);
  5598. BIO_free(wbio);
  5599. rbio = NULL;
  5600. wbio = NULL;
  5601. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5602. /* to prevent "unused variable" warning */
  5603. (void)pkey;
  5604. (void)wbio;
  5605. (void)rbio;
  5606. (void)line;
  5607. (void)line1;
  5608. (void)i;
  5609. #endif /* OPENSSL_EXTRA */
  5610. return EXPECT_RESULT();
  5611. }
  5612. /* Test functions for base64 encode/decode */
  5613. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5614. {
  5615. EXPECT_DECLS;
  5616. #if defined(OPENSSL_EXTRA) && \
  5617. ( defined(WOLFSSL_BASE64_ENCODE) || 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. EVP_ENCODE_CTX_free(ctx);
  5624. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5625. return EXPECT_RESULT();
  5626. }
  5627. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5628. {
  5629. EXPECT_DECLS;
  5630. #if defined(OPENSSL_EXTRA) && \
  5631. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5632. EVP_ENCODE_CTX* ctx = NULL;
  5633. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5634. EVP_ENCODE_CTX_free(ctx);
  5635. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5636. return EXPECT_RESULT();
  5637. }
  5638. static int test_wolfSSL_EVP_EncodeInit(void)
  5639. {
  5640. EXPECT_DECLS;
  5641. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5642. EVP_ENCODE_CTX* ctx = NULL;
  5643. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5644. ExpectIntEQ(ctx->remaining, 0);
  5645. ExpectIntEQ(ctx->data[0], 0);
  5646. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5647. if (ctx != NULL) {
  5648. /* make ctx dirty */
  5649. ctx->remaining = 10;
  5650. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5651. }
  5652. EVP_EncodeInit(ctx);
  5653. ExpectIntEQ(ctx->remaining, 0);
  5654. ExpectIntEQ(ctx->data[0], 0);
  5655. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5656. EVP_ENCODE_CTX_free(ctx);
  5657. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5658. return EXPECT_RESULT();
  5659. }
  5660. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5661. {
  5662. EXPECT_DECLS;
  5663. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5664. int outl;
  5665. int total;
  5666. const unsigned char plain0[] = {"Th"};
  5667. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5668. const unsigned char plain2[] = {"This is additional data."};
  5669. const unsigned char encBlock0[] = {"VGg="};
  5670. const unsigned char enc0[] = {"VGg=\n"};
  5671. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5672. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5673. const unsigned char enc2[] =
  5674. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5675. unsigned char encOutBuff[300];
  5676. EVP_ENCODE_CTX* ctx = NULL;
  5677. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5678. EVP_EncodeInit(ctx);
  5679. /* illegal parameter test */
  5680. ExpectIntEQ(
  5681. EVP_EncodeUpdate(
  5682. NULL, /* pass NULL as ctx */
  5683. encOutBuff,
  5684. &outl,
  5685. plain1,
  5686. sizeof(plain1)-1),
  5687. 0 /* expected result code 0: fail */
  5688. );
  5689. ExpectIntEQ(
  5690. EVP_EncodeUpdate(
  5691. ctx,
  5692. NULL, /* pass NULL as out buff */
  5693. &outl,
  5694. plain1,
  5695. sizeof(plain1)-1),
  5696. 0 /* expected result code 0: fail */
  5697. );
  5698. ExpectIntEQ(
  5699. EVP_EncodeUpdate(
  5700. ctx,
  5701. encOutBuff,
  5702. NULL, /* pass NULL as outl */
  5703. plain1,
  5704. sizeof(plain1)-1),
  5705. 0 /* expected result code 0: fail */
  5706. );
  5707. ExpectIntEQ(
  5708. EVP_EncodeUpdate(
  5709. ctx,
  5710. encOutBuff,
  5711. &outl,
  5712. NULL, /* pass NULL as in */
  5713. sizeof(plain1)-1),
  5714. 0 /* expected result code 0: fail */
  5715. );
  5716. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5717. /* meaningless parameter test */
  5718. ExpectIntEQ(
  5719. EVP_EncodeUpdate(
  5720. ctx,
  5721. encOutBuff,
  5722. &outl,
  5723. plain1,
  5724. 0), /* pass zero input */
  5725. 1 /* expected result code 1: success */
  5726. );
  5727. /* very small data encoding test */
  5728. EVP_EncodeInit(ctx);
  5729. ExpectIntEQ(
  5730. EVP_EncodeUpdate(
  5731. ctx,
  5732. encOutBuff,
  5733. &outl,
  5734. plain0,
  5735. sizeof(plain0)-1),
  5736. 1 /* expected result code 1: success */
  5737. );
  5738. ExpectIntEQ(outl,0);
  5739. if (EXPECT_SUCCESS()) {
  5740. EVP_EncodeFinal(
  5741. ctx,
  5742. encOutBuff + outl,
  5743. &outl);
  5744. }
  5745. ExpectIntEQ( outl, sizeof(enc0)-1);
  5746. ExpectIntEQ(
  5747. XSTRNCMP(
  5748. (const char*)encOutBuff,
  5749. (const char*)enc0,sizeof(enc0) ),
  5750. 0);
  5751. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5752. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5753. sizeof(encBlock0)-1);
  5754. ExpectStrEQ(encOutBuff, encBlock0);
  5755. /* pass small size( < 48bytes ) input, then make sure they are not
  5756. * encoded and just stored in ctx
  5757. */
  5758. EVP_EncodeInit(ctx);
  5759. total = 0;
  5760. outl = 0;
  5761. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5762. ExpectIntEQ(
  5763. EVP_EncodeUpdate(
  5764. ctx,
  5765. encOutBuff, /* buffer for output */
  5766. &outl, /* size of output */
  5767. plain1, /* input */
  5768. sizeof(plain1)-1), /* size of input */
  5769. 1); /* expected result code 1:success */
  5770. total += outl;
  5771. ExpectIntEQ(outl, 0); /* no output expected */
  5772. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5773. ExpectTrue(
  5774. XSTRNCMP((const char*)(ctx->data),
  5775. (const char*)plain1,
  5776. ctx->remaining) ==0 );
  5777. ExpectTrue(encOutBuff[0] == 0);
  5778. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5779. * the stored data and the new input together
  5780. */
  5781. ExpectIntEQ(
  5782. EVP_EncodeUpdate(
  5783. ctx,
  5784. encOutBuff + outl, /* buffer for output */
  5785. &outl, /* size of output */
  5786. plain2, /* additional input */
  5787. sizeof(plain2) -1), /* size of additional input */
  5788. 1); /* expected result code 1:success */
  5789. total += outl;
  5790. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5791. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5792. ExpectIntEQ(
  5793. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5794. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5795. EVP_EncodeFinal(
  5796. ctx,
  5797. encOutBuff + outl,
  5798. &outl);
  5799. total += outl;
  5800. ExpectIntNE(total,0);
  5801. ExpectIntNE(outl,0);
  5802. ExpectIntEQ(XSTRNCMP(
  5803. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5804. /* test with illeagal parameters */
  5805. outl = 1;
  5806. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5807. ExpectIntEQ(outl, 0);
  5808. outl = 1;
  5809. EVP_EncodeFinal(ctx, NULL, &outl);
  5810. ExpectIntEQ(outl, 0);
  5811. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5812. EVP_EncodeFinal(NULL, NULL, NULL);
  5813. EVP_ENCODE_CTX_free(ctx);
  5814. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5815. return EXPECT_RESULT();
  5816. }
  5817. static int test_wolfSSL_EVP_EncodeFinal(void)
  5818. {
  5819. int res = TEST_SKIPPED;
  5820. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5821. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5822. * test_wolfSSL_EVP_EncodeUpdate
  5823. */
  5824. res = TEST_SUCCESS;
  5825. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5826. return res;
  5827. }
  5828. static int test_wolfSSL_EVP_DecodeInit(void)
  5829. {
  5830. EXPECT_DECLS;
  5831. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5832. EVP_ENCODE_CTX* ctx = NULL;
  5833. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5834. ExpectIntEQ( ctx->remaining,0);
  5835. ExpectIntEQ( ctx->data[0],0);
  5836. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5837. if (ctx != NULL) {
  5838. /* make ctx dirty */
  5839. ctx->remaining = 10;
  5840. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5841. }
  5842. EVP_DecodeInit(ctx);
  5843. ExpectIntEQ( ctx->remaining,0);
  5844. ExpectIntEQ( ctx->data[0],0);
  5845. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5846. EVP_ENCODE_CTX_free(ctx);
  5847. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5848. return EXPECT_RESULT();
  5849. }
  5850. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5851. {
  5852. EXPECT_DECLS;
  5853. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5854. int outl;
  5855. unsigned char decOutBuff[300];
  5856. EVP_ENCODE_CTX* ctx = NULL;
  5857. static const unsigned char enc1[] =
  5858. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5859. /* const unsigned char plain1[] =
  5860. {"This is a base64 decoding test."} */
  5861. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5862. EVP_DecodeInit(ctx);
  5863. /* illegal parameter tests */
  5864. /* pass NULL as ctx */
  5865. ExpectIntEQ(
  5866. EVP_DecodeUpdate(
  5867. NULL, /* pass NULL as ctx */
  5868. decOutBuff,
  5869. &outl,
  5870. enc1,
  5871. sizeof(enc1)-1),
  5872. -1 /* expected result code -1: fail */
  5873. );
  5874. ExpectIntEQ( outl, 0);
  5875. /* pass NULL as output */
  5876. ExpectIntEQ(
  5877. EVP_DecodeUpdate(
  5878. ctx,
  5879. NULL, /* pass NULL as out buff */
  5880. &outl,
  5881. enc1,
  5882. sizeof(enc1)-1),
  5883. -1 /* expected result code -1: fail */
  5884. );
  5885. ExpectIntEQ( outl, 0);
  5886. /* pass NULL as outl */
  5887. ExpectIntEQ(
  5888. EVP_DecodeUpdate(
  5889. ctx,
  5890. decOutBuff,
  5891. NULL, /* pass NULL as outl */
  5892. enc1,
  5893. sizeof(enc1)-1),
  5894. -1 /* expected result code -1: fail */
  5895. );
  5896. /* pass NULL as input */
  5897. ExpectIntEQ(
  5898. EVP_DecodeUpdate(
  5899. ctx,
  5900. decOutBuff,
  5901. &outl,
  5902. NULL, /* pass NULL as in */
  5903. sizeof(enc1)-1),
  5904. -1 /* expected result code -1: fail */
  5905. );
  5906. ExpectIntEQ( outl, 0);
  5907. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5908. /* pass zero length input */
  5909. ExpectIntEQ(
  5910. EVP_DecodeUpdate(
  5911. ctx,
  5912. decOutBuff,
  5913. &outl,
  5914. enc1,
  5915. 0), /* pass zero as input len */
  5916. 1 /* expected result code 1: success */
  5917. );
  5918. /* decode correct base64 string */
  5919. {
  5920. static const unsigned char enc2[] =
  5921. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5922. static const unsigned char plain2[] =
  5923. {"This is a base64 decoding test."};
  5924. EVP_EncodeInit(ctx);
  5925. ExpectIntEQ(
  5926. EVP_DecodeUpdate(
  5927. ctx,
  5928. decOutBuff,
  5929. &outl,
  5930. enc2,
  5931. sizeof(enc2)-1),
  5932. 0 /* expected result code 0: success */
  5933. );
  5934. ExpectIntEQ(outl,sizeof(plain2) -1);
  5935. ExpectIntEQ(
  5936. EVP_DecodeFinal(
  5937. ctx,
  5938. decOutBuff + outl,
  5939. &outl),
  5940. 1 /* expected result code 1: success */
  5941. );
  5942. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5943. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5944. sizeof(plain2) -1 ),0);
  5945. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5946. sizeof(plain2)-1);
  5947. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5948. sizeof(plain2) -1 ),0);
  5949. }
  5950. /* decode correct base64 string which does not have '\n' in its last*/
  5951. {
  5952. static const unsigned char enc3[] =
  5953. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5954. static const unsigned char plain3[] =
  5955. {"This is a base64 decoding test."}; /* 31 chars */
  5956. EVP_EncodeInit(ctx);
  5957. ExpectIntEQ(
  5958. EVP_DecodeUpdate(
  5959. ctx,
  5960. decOutBuff,
  5961. &outl,
  5962. enc3,
  5963. sizeof(enc3)-1),
  5964. 0 /* expected result code 0: success */
  5965. );
  5966. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5967. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5968. sizeof(plain3) -1 ),0);
  5969. ExpectIntEQ(
  5970. EVP_DecodeFinal(
  5971. ctx,
  5972. decOutBuff + outl,
  5973. &outl),
  5974. 1 /* expected result code 1: success */
  5975. );
  5976. ExpectIntEQ(outl,0 );
  5977. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5978. sizeof(plain3)-1);
  5979. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5980. sizeof(plain3) -1 ),0);
  5981. }
  5982. /* decode string which has a padding char ('=') in the illegal position*/
  5983. {
  5984. static const unsigned char enc4[] =
  5985. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5986. EVP_EncodeInit(ctx);
  5987. ExpectIntEQ(
  5988. EVP_DecodeUpdate(
  5989. ctx,
  5990. decOutBuff,
  5991. &outl,
  5992. enc4,
  5993. sizeof(enc4)-1),
  5994. -1 /* expected result code -1: error */
  5995. );
  5996. ExpectIntEQ(outl,0);
  5997. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  5998. }
  5999. /* small data decode test */
  6000. {
  6001. static const unsigned char enc00[] = {"VG"};
  6002. static const unsigned char enc01[] = {"g=\n"};
  6003. static const unsigned char plain4[] = {"Th"};
  6004. EVP_EncodeInit(ctx);
  6005. ExpectIntEQ(
  6006. EVP_DecodeUpdate(
  6007. ctx,
  6008. decOutBuff,
  6009. &outl,
  6010. enc00,
  6011. sizeof(enc00)-1),
  6012. 1 /* expected result code 1: success */
  6013. );
  6014. ExpectIntEQ(outl,0);
  6015. ExpectIntEQ(
  6016. EVP_DecodeUpdate(
  6017. ctx,
  6018. decOutBuff + outl,
  6019. &outl,
  6020. enc01,
  6021. sizeof(enc01)-1),
  6022. 0 /* expected result code 0: success */
  6023. );
  6024. ExpectIntEQ(outl,sizeof(plain4)-1);
  6025. /* test with illegal parameters */
  6026. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  6027. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  6028. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  6029. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  6030. if (EXPECT_SUCCESS()) {
  6031. EVP_DecodeFinal(
  6032. ctx,
  6033. decOutBuff + outl,
  6034. &outl);
  6035. }
  6036. ExpectIntEQ( outl, 0);
  6037. ExpectIntEQ(
  6038. XSTRNCMP(
  6039. (const char*)decOutBuff,
  6040. (const char*)plain4,sizeof(plain4)-1 ),
  6041. 0);
  6042. }
  6043. EVP_ENCODE_CTX_free(ctx);
  6044. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6045. return EXPECT_RESULT();
  6046. }
  6047. static int test_wolfSSL_EVP_DecodeFinal(void)
  6048. {
  6049. int res = TEST_SKIPPED;
  6050. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  6051. /* tests for wolfSSL_EVP_DecodeFinal are included in
  6052. * test_wolfSSL_EVP_DecodeUpdate
  6053. */
  6054. res = TEST_SUCCESS;
  6055. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6056. return res;
  6057. }
  6058. /* Test function for wolfSSL_EVP_get_cipherbynid.
  6059. */
  6060. #ifdef OPENSSL_EXTRA
  6061. static int test_wolfSSL_EVP_get_cipherbynid(void)
  6062. {
  6063. EXPECT_DECLS;
  6064. #ifndef NO_AES
  6065. const WOLFSSL_EVP_CIPHER* c;
  6066. c = wolfSSL_EVP_get_cipherbynid(419);
  6067. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6068. defined(WOLFSSL_AES_128)
  6069. ExpectNotNull(c);
  6070. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  6071. #else
  6072. ExpectNull(c);
  6073. #endif
  6074. c = wolfSSL_EVP_get_cipherbynid(423);
  6075. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6076. defined(WOLFSSL_AES_192)
  6077. ExpectNotNull(c);
  6078. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  6079. #else
  6080. ExpectNull(c);
  6081. #endif
  6082. c = wolfSSL_EVP_get_cipherbynid(427);
  6083. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6084. defined(WOLFSSL_AES_256)
  6085. ExpectNotNull(c);
  6086. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  6087. #else
  6088. ExpectNull(c);
  6089. #endif
  6090. c = wolfSSL_EVP_get_cipherbynid(904);
  6091. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  6092. ExpectNotNull(c);
  6093. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  6094. #else
  6095. ExpectNull(c);
  6096. #endif
  6097. c = wolfSSL_EVP_get_cipherbynid(905);
  6098. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  6099. ExpectNotNull(c);
  6100. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  6101. #else
  6102. ExpectNull(c);
  6103. #endif
  6104. c = wolfSSL_EVP_get_cipherbynid(906);
  6105. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  6106. ExpectNotNull(c);
  6107. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  6108. #else
  6109. ExpectNull(c);
  6110. #endif
  6111. c = wolfSSL_EVP_get_cipherbynid(418);
  6112. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  6113. ExpectNotNull(c);
  6114. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  6115. #else
  6116. ExpectNull(c);
  6117. #endif
  6118. c = wolfSSL_EVP_get_cipherbynid(422);
  6119. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  6120. ExpectNotNull(c);
  6121. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  6122. #else
  6123. ExpectNull(c);
  6124. #endif
  6125. c = wolfSSL_EVP_get_cipherbynid(426);
  6126. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  6127. ExpectNotNull(c);
  6128. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  6129. #else
  6130. ExpectNull(c);
  6131. #endif
  6132. #endif /* !NO_AES */
  6133. #ifndef NO_DES3
  6134. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  6135. #ifdef WOLFSSL_DES_ECB
  6136. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  6137. #endif
  6138. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  6139. #ifdef WOLFSSL_DES_ECB
  6140. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  6141. #endif
  6142. #endif /* !NO_DES3 */
  6143. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  6144. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  6145. #endif
  6146. /* test for nid is out of range */
  6147. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  6148. return EXPECT_RESULT();
  6149. }
  6150. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  6151. {
  6152. EXPECT_DECLS;
  6153. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  6154. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  6155. const EVP_CIPHER *init = EVP_aes_128_cbc();
  6156. const EVP_CIPHER *test;
  6157. byte key[AES_BLOCK_SIZE] = {0};
  6158. byte iv[AES_BLOCK_SIZE] = {0};
  6159. ExpectNotNull(ctx);
  6160. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  6161. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  6162. test = EVP_CIPHER_CTX_cipher(ctx);
  6163. ExpectTrue(init == test);
  6164. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  6165. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  6166. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  6167. EVP_CIPHER_CTX_free(ctx);
  6168. /* test EVP_CIPHER_CTX_cleanup with NULL */
  6169. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  6170. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  6171. return EXPECT_RESULT();
  6172. }
  6173. #endif /* OPENSSL_EXTRA */
  6174. /*----------------------------------------------------------------------------*
  6175. | IO
  6176. *----------------------------------------------------------------------------*/
  6177. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  6178. defined(HAVE_IO_TESTS_DEPENDENCIES)
  6179. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6180. #ifdef WC_SHA512_DIGEST_SIZE
  6181. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  6182. #else
  6183. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  6184. #endif
  6185. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  6186. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  6187. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  6188. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  6189. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6190. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  6191. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  6192. defined(HAVE_AES_CBC)
  6193. typedef struct openssl_key_ctx {
  6194. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  6195. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  6196. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  6197. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  6198. } openssl_key_ctx;
  6199. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  6200. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  6201. static WC_INLINE int OpenSSLTicketInit(void)
  6202. {
  6203. int ret = wc_InitRng(&myOpenSSLKey_rng);
  6204. if (ret != 0) return ret;
  6205. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  6206. sizeof(myOpenSSLKey_ctx.name));
  6207. if (ret != 0) return ret;
  6208. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  6209. sizeof(myOpenSSLKey_ctx.key));
  6210. if (ret != 0) return ret;
  6211. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  6212. sizeof(myOpenSSLKey_ctx.hmacKey));
  6213. if (ret != 0) return ret;
  6214. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6215. sizeof(myOpenSSLKey_ctx.iv));
  6216. if (ret != 0) return ret;
  6217. return 0;
  6218. }
  6219. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6220. byte name[WOLFSSL_TICKET_NAME_SZ],
  6221. byte iv[WOLFSSL_TICKET_IV_SZ],
  6222. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6223. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6224. (void)ssl;
  6225. if (enc) {
  6226. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6227. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6228. }
  6229. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6230. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6231. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6232. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6233. return 0;
  6234. }
  6235. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6236. if (enc)
  6237. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6238. else
  6239. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6240. return 1;
  6241. }
  6242. static WC_INLINE void OpenSSLTicketCleanup(void)
  6243. {
  6244. wc_FreeRng(&myOpenSSLKey_rng);
  6245. }
  6246. #endif
  6247. #endif
  6248. /* helper functions */
  6249. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6250. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6251. void *ctx)
  6252. {
  6253. struct test_ssl_memio_ctx *test_ctx;
  6254. byte *buf;
  6255. int *len;
  6256. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6257. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6258. buf = test_ctx->c_buff;
  6259. len = &test_ctx->c_len;
  6260. }
  6261. else {
  6262. buf = test_ctx->s_buff;
  6263. len = &test_ctx->s_len;
  6264. }
  6265. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6266. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6267. XMEMCPY(buf + *len, data, sz);
  6268. *len += sz;
  6269. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6270. {
  6271. /* This can be imported into Wireshark by transforming the file with
  6272. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6273. * And then loading test_output.dump.hex into Wireshark using the
  6274. * "Import from Hex Dump..." option ion and selecting the TCP
  6275. * encapsulation option. */
  6276. char dump_file_name[64];
  6277. WOLFSSL_BIO *dump_file;
  6278. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6279. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6280. if (dump_file != NULL) {
  6281. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6282. wolfSSL_BIO_free(dump_file);
  6283. }
  6284. }
  6285. #endif
  6286. return sz;
  6287. }
  6288. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6289. void *ctx)
  6290. {
  6291. struct test_ssl_memio_ctx *test_ctx;
  6292. int read_sz;
  6293. byte *buf;
  6294. int *len;
  6295. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6296. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6297. buf = test_ctx->s_buff;
  6298. len = &test_ctx->s_len;
  6299. }
  6300. else {
  6301. buf = test_ctx->c_buff;
  6302. len = &test_ctx->c_len;
  6303. }
  6304. if (*len == 0)
  6305. return WOLFSSL_CBIO_ERR_WANT_READ;
  6306. read_sz = sz < *len ? sz : *len;
  6307. XMEMCPY(data, buf, read_sz);
  6308. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6309. *len -= read_sz;
  6310. return read_sz;
  6311. }
  6312. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6313. {
  6314. EXPECT_DECLS_NO_MSGS(-2000);
  6315. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6316. int c_sharedCtx = 0;
  6317. int s_sharedCtx = 0;
  6318. #endif
  6319. const char* clientCertFile = cliCertFile;
  6320. const char* clientKeyFile = cliKeyFile;
  6321. const char* serverCertFile = svrCertFile;
  6322. const char* serverKeyFile = svrKeyFile;
  6323. /********************************
  6324. * Create WOLFSSL_CTX for client.
  6325. ********************************/
  6326. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6327. if (ctx->c_ctx != NULL) {
  6328. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6329. }
  6330. else
  6331. #endif
  6332. {
  6333. WOLFSSL_METHOD* method = NULL;
  6334. if (ctx->c_cb.method != NULL) {
  6335. method = ctx->c_cb.method();
  6336. }
  6337. else {
  6338. method = wolfSSLv23_client_method();
  6339. }
  6340. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6341. }
  6342. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6343. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6344. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6345. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6346. #endif
  6347. if (ctx->c_cb.caPemFile != NULL)
  6348. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6349. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6350. else
  6351. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6352. caCertFile, 0), WOLFSSL_SUCCESS);
  6353. if (ctx->c_cb.certPemFile != NULL) {
  6354. clientCertFile = ctx->c_cb.certPemFile;
  6355. }
  6356. if (ctx->c_cb.keyPemFile != NULL) {
  6357. clientKeyFile = ctx->c_cb.keyPemFile;
  6358. }
  6359. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6360. if (!c_sharedCtx)
  6361. #endif
  6362. {
  6363. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6364. clientCertFile), WOLFSSL_SUCCESS);
  6365. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6366. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6367. }
  6368. #ifdef HAVE_CRL
  6369. if (ctx->c_cb.crlPemFile != NULL) {
  6370. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6371. WOLFSSL_SUCCESS);
  6372. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6373. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6374. }
  6375. #endif
  6376. if (ctx->c_ciphers != NULL) {
  6377. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6378. WOLFSSL_SUCCESS);
  6379. }
  6380. if (ctx->c_cb.ctx_ready != NULL) {
  6381. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6382. }
  6383. /********************************
  6384. * Create WOLFSSL_CTX for server.
  6385. ********************************/
  6386. if (ctx->s_ctx != NULL) {
  6387. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6388. s_sharedCtx = 1;
  6389. #endif
  6390. ctx->s_cb.isSharedCtx = 1;
  6391. }
  6392. else
  6393. {
  6394. WOLFSSL_METHOD* method = NULL;
  6395. if (ctx->s_cb.method != NULL) {
  6396. method = ctx->s_cb.method();
  6397. }
  6398. else {
  6399. method = wolfSSLv23_server_method();
  6400. }
  6401. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6402. ctx->s_cb.isSharedCtx = 0;
  6403. }
  6404. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6405. #if defined(HAVE_SESSION_TICKET) && \
  6406. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6407. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6408. OpenSSLTicketInit();
  6409. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6410. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6411. TicketInit();
  6412. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6413. #endif
  6414. #endif
  6415. }
  6416. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6417. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6418. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6419. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6420. if (ctx->s_cb.caPemFile != NULL)
  6421. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6422. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6423. else
  6424. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6425. cliCertFile, 0), WOLFSSL_SUCCESS);
  6426. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6427. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6428. #endif
  6429. if (ctx->s_cb.certPemFile != NULL) {
  6430. serverCertFile = ctx->s_cb.certPemFile;
  6431. }
  6432. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6433. if (!s_sharedCtx)
  6434. #endif
  6435. {
  6436. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6437. serverCertFile), WOLFSSL_SUCCESS);
  6438. }
  6439. if (ctx->s_cb.keyPemFile != NULL) {
  6440. serverKeyFile = ctx->s_cb.keyPemFile;
  6441. }
  6442. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6443. if (!s_sharedCtx)
  6444. #endif
  6445. {
  6446. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6447. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6448. }
  6449. if (ctx->s_ciphers != NULL) {
  6450. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6451. WOLFSSL_SUCCESS);
  6452. }
  6453. if (ctx->s_cb.ctx_ready != NULL) {
  6454. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6455. }
  6456. /****************************
  6457. * Create WOLFSSL for client.
  6458. ****************************/
  6459. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6460. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6461. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6462. if (0
  6463. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6464. || c_sharedCtx
  6465. #endif
  6466. )
  6467. {
  6468. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6469. clientCertFile), WOLFSSL_SUCCESS);
  6470. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6471. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6472. }
  6473. if (ctx->c_cb.ssl_ready != NULL) {
  6474. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6475. }
  6476. /****************************
  6477. * Create WOLFSSL for server.
  6478. ****************************/
  6479. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6480. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6481. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6482. if (0
  6483. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6484. || s_sharedCtx
  6485. #endif
  6486. )
  6487. {
  6488. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6489. serverCertFile), WOLFSSL_SUCCESS);
  6490. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6491. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6492. }
  6493. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6494. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6495. #elif !defined(NO_DH)
  6496. /* will repick suites with DHE, higher priority than PSK */
  6497. SetDH(ctx->s_ssl);
  6498. #endif
  6499. if (ctx->s_cb.ssl_ready != NULL) {
  6500. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6501. }
  6502. return EXPECT_RESULT();
  6503. }
  6504. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6505. int* rounds)
  6506. {
  6507. int handshake_complete = 0;
  6508. int hs_c = 0;
  6509. int hs_s = 0;
  6510. int failing_s = 0;
  6511. int failing_c = 0;
  6512. int ret;
  6513. int err;
  6514. if (rounds != NULL) {
  6515. *rounds = 0;
  6516. }
  6517. while ((!handshake_complete) && (max_rounds > 0)) {
  6518. if (!hs_c) {
  6519. wolfSSL_SetLoggingPrefix("client");
  6520. ret = wolfSSL_connect(ctx->c_ssl);
  6521. wolfSSL_SetLoggingPrefix(NULL);
  6522. if (ret == WOLFSSL_SUCCESS) {
  6523. hs_c = 1;
  6524. }
  6525. else {
  6526. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6527. if (err != WOLFSSL_ERROR_WANT_READ &&
  6528. err != WOLFSSL_ERROR_WANT_WRITE) {
  6529. char buff[WOLFSSL_MAX_ERROR_SZ];
  6530. fprintf(stderr, "error = %d, %s\n", err,
  6531. wolfSSL_ERR_error_string(err, buff));
  6532. failing_c = 1;
  6533. hs_c = 1;
  6534. if (failing_c && failing_s) {
  6535. break;
  6536. }
  6537. }
  6538. }
  6539. }
  6540. if (!hs_s) {
  6541. wolfSSL_SetLoggingPrefix("server");
  6542. ret = wolfSSL_accept(ctx->s_ssl);
  6543. wolfSSL_SetLoggingPrefix(NULL);
  6544. if (ret == WOLFSSL_SUCCESS) {
  6545. hs_s = 1;
  6546. }
  6547. else {
  6548. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6549. if (err != WOLFSSL_ERROR_WANT_READ &&
  6550. err != WOLFSSL_ERROR_WANT_WRITE) {
  6551. char buff[WOLFSSL_MAX_ERROR_SZ];
  6552. fprintf(stderr, "error = %d, %s\n", err,
  6553. wolfSSL_ERR_error_string(err, buff));
  6554. failing_s = 1;
  6555. hs_s = 1;
  6556. if (failing_c && failing_s) {
  6557. break;
  6558. }
  6559. }
  6560. }
  6561. }
  6562. handshake_complete = hs_c && hs_s;
  6563. max_rounds--;
  6564. if (rounds != NULL) {
  6565. *rounds += 1;
  6566. }
  6567. }
  6568. if (!handshake_complete || failing_c || failing_s) {
  6569. return TEST_FAIL;
  6570. }
  6571. return TEST_SUCCESS;
  6572. }
  6573. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6574. {
  6575. EXPECT_DECLS_NO_MSGS(-3000);
  6576. char input[1024];
  6577. int idx = 0;
  6578. const char* msg_c = "hello wolfssl!";
  6579. int msglen_c = (int)XSTRLEN(msg_c);
  6580. const char* msg_s = "I hear you fa shizzle!";
  6581. int msglen_s = (int)XSTRLEN(msg_s);
  6582. if (ctx->c_msg != NULL) {
  6583. msg_c = ctx->c_msg;
  6584. msglen_c = ctx->c_msglen;
  6585. }
  6586. if (ctx->s_msg != NULL) {
  6587. msg_s = ctx->s_msg;
  6588. msglen_s = ctx->s_msglen;
  6589. }
  6590. wolfSSL_SetLoggingPrefix("client");
  6591. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6592. wolfSSL_SetLoggingPrefix("server");
  6593. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6594. if (idx >= 0) {
  6595. input[idx] = '\0';
  6596. }
  6597. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6598. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6599. ctx->s_cb.return_code = EXPECT_RESULT();
  6600. wolfSSL_SetLoggingPrefix("client");
  6601. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6602. wolfSSL_SetLoggingPrefix(NULL);
  6603. if (idx >= 0) {
  6604. input[idx] = '\0';
  6605. }
  6606. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6607. ctx->c_cb.return_code = EXPECT_RESULT();
  6608. if (ctx->c_cb.on_result != NULL) {
  6609. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6610. }
  6611. if (ctx->s_cb.on_result != NULL) {
  6612. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6613. }
  6614. return EXPECT_RESULT();
  6615. }
  6616. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6617. {
  6618. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6619. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6620. if (ctx->c_cb.on_cleanup != NULL) {
  6621. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6622. }
  6623. if (ctx->s_cb.on_cleanup != NULL) {
  6624. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6625. }
  6626. wolfSSL_shutdown(ctx->s_ssl);
  6627. wolfSSL_shutdown(ctx->c_ssl);
  6628. wolfSSL_free(ctx->s_ssl);
  6629. wolfSSL_free(ctx->c_ssl);
  6630. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6631. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6632. }
  6633. if (!ctx->c_cb.isSharedCtx) {
  6634. wolfSSL_CTX_free(ctx->c_ctx);
  6635. ctx->c_ctx = NULL;
  6636. }
  6637. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6638. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6639. }
  6640. if (!ctx->s_cb.isSharedCtx) {
  6641. wolfSSL_CTX_free(ctx->s_ctx);
  6642. ctx->s_ctx = NULL;
  6643. }
  6644. if (!ctx->s_cb.ticNoInit) {
  6645. #if defined(HAVE_SESSION_TICKET) && \
  6646. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6647. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6648. OpenSSLTicketCleanup();
  6649. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6650. TicketCleanup();
  6651. #endif
  6652. #endif
  6653. }
  6654. }
  6655. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6656. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6657. {
  6658. /* We use EXPECT_DECLS_NO_MSGS() here because this helper routine is used
  6659. * for numerous but varied expected-to-fail scenarios that should not emit
  6660. * error messages on the expected failures. Instead, we return a distinct
  6661. * code for each failure point, allowing the caller to assert on a
  6662. * particular mode of expected failure. On success, the usual TEST_SUCCESS
  6663. * is returned.
  6664. */
  6665. EXPECT_DECLS_NO_MSGS(-1000);
  6666. struct test_ssl_memio_ctx test_ctx;
  6667. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6668. size_t msg_len;
  6669. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6670. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6671. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6672. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6673. test_ctx.c_ctx = client_cb->ctx;
  6674. test_ctx.s_ctx = server_cb->ctx;
  6675. test_ctx.c_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6676. test_ctx.s_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6677. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6678. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6679. if (client_on_handshake != NULL) {
  6680. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6681. TEST_SUCCESS);
  6682. }
  6683. if (client_cb->on_handshake != NULL) {
  6684. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6685. TEST_SUCCESS);
  6686. }
  6687. if (server_cb->on_handshake != NULL) {
  6688. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6689. TEST_SUCCESS);
  6690. }
  6691. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6692. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6693. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6694. MD_MAX_SIZE);
  6695. ExpectIntGE(msg_len, 0);
  6696. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6697. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6698. MD_MAX_SIZE);
  6699. ExpectIntGE(msg_len, 0);
  6700. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6701. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6702. test_ssl_memio_cleanup(&test_ctx);
  6703. client_cb->return_code = test_ctx.c_cb.return_code;
  6704. client_cb->last_err = test_ctx.c_cb.last_err;
  6705. server_cb->return_code = test_ctx.s_cb.return_code;
  6706. server_cb->last_err = test_ctx.s_cb.last_err;
  6707. return EXPECT_RESULT();
  6708. }
  6709. #endif
  6710. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6711. #ifdef WOLFSSL_SESSION_EXPORT
  6712. #ifdef WOLFSSL_DTLS
  6713. /* set up function for sending session information */
  6714. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6715. {
  6716. WOLFSSL_CTX* ctx = NULL;
  6717. WOLFSSL* ssl = NULL;
  6718. AssertNotNull(inSsl);
  6719. AssertNotNull(buf);
  6720. AssertIntNE(0, sz);
  6721. /* Set ctx to DTLS 1.2 */
  6722. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6723. AssertNotNull(ctx);
  6724. ssl = wolfSSL_new(ctx);
  6725. AssertNotNull(ssl);
  6726. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6727. wolfSSL_free(ssl);
  6728. wolfSSL_CTX_free(ctx);
  6729. (void)userCtx;
  6730. return 0;
  6731. }
  6732. #endif
  6733. /* returns negative value on fail and positive (including 0) on success */
  6734. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6735. {
  6736. int ret, err, loop_count, count, timeout = 10;
  6737. char msg[] = "I hear you fa shizzle!";
  6738. char input[1024];
  6739. loop_count = ((func_args*)args)->argc;
  6740. #ifdef WOLFSSL_ASYNC_CRYPT
  6741. err = 0; /* Reset error */
  6742. #endif
  6743. do {
  6744. #ifdef WOLFSSL_ASYNC_CRYPT
  6745. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6746. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6747. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6748. }
  6749. #endif
  6750. ret = wolfSSL_accept(ssl);
  6751. err = wolfSSL_get_error(ssl, 0);
  6752. if (err == WOLFSSL_ERROR_WANT_READ ||
  6753. err == WOLFSSL_ERROR_WANT_WRITE) {
  6754. int select_ret;
  6755. err = WC_PENDING_E;
  6756. select_ret = tcp_select(*sockfd, timeout);
  6757. if (select_ret == TEST_TIMEOUT) {
  6758. return WOLFSSL_FATAL_ERROR;
  6759. }
  6760. }
  6761. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6762. if (ret != WOLFSSL_SUCCESS) {
  6763. char buff[WOLFSSL_MAX_ERROR_SZ];
  6764. fprintf(stderr, "error = %d, %s\n", err,
  6765. wolfSSL_ERR_error_string(err, buff));
  6766. return ret;
  6767. }
  6768. for (count = 0; count < loop_count; count++) {
  6769. int select_ret;
  6770. select_ret = tcp_select(*sockfd, timeout);
  6771. if (select_ret == TEST_TIMEOUT) {
  6772. ret = WOLFSSL_FATAL_ERROR;
  6773. break;
  6774. }
  6775. do {
  6776. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6777. if (ret > 0) {
  6778. input[ret] = '\0';
  6779. fprintf(stderr, "Client message: %s\n", input);
  6780. }
  6781. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6782. do {
  6783. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6784. return WOLFSSL_FATAL_ERROR;
  6785. }
  6786. err = wolfSSL_get_error(ssl, ret);
  6787. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6788. }
  6789. return ret;
  6790. }
  6791. #endif /* WOLFSSL_SESSION_EXPORT */
  6792. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6793. {
  6794. SOCKET_T sockfd = 0;
  6795. SOCKET_T clientfd = 0;
  6796. word16 port;
  6797. callback_functions* cbf;
  6798. WOLFSSL_CTX* ctx = NULL;
  6799. WOLFSSL* ssl = NULL;
  6800. func_args* opts = (func_args*)args;
  6801. char msg[] = "I hear you fa shizzle!";
  6802. char input[1024];
  6803. int idx;
  6804. int ret, err = 0;
  6805. int sharedCtx = 0;
  6806. int doUdp = 0;
  6807. SOCKADDR_IN_T cliAddr;
  6808. socklen_t cliLen;
  6809. const char* certFile = svrCertFile;
  6810. const char* keyFile = svrKeyFile;
  6811. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6812. size_t msg_len = 0;
  6813. #endif
  6814. wolfSSL_SetLoggingPrefix("server");
  6815. #ifdef WOLFSSL_TIRTOS
  6816. fdOpenSession(Task_self());
  6817. #endif
  6818. opts->return_code = TEST_FAIL;
  6819. cbf = opts->callbacks;
  6820. if (cbf != NULL && cbf->ctx) {
  6821. ctx = cbf->ctx;
  6822. sharedCtx = 1;
  6823. }
  6824. else
  6825. {
  6826. WOLFSSL_METHOD* method = NULL;
  6827. if (cbf != NULL && cbf->method != NULL) {
  6828. method = cbf->method();
  6829. }
  6830. else {
  6831. method = wolfSSLv23_server_method();
  6832. }
  6833. ctx = wolfSSL_CTX_new(method);
  6834. }
  6835. if (ctx == NULL) {
  6836. /* Release the wait for TCP ready. */
  6837. signal_ready(opts->signal);
  6838. goto done;
  6839. }
  6840. if (cbf == NULL || !cbf->ticNoInit) {
  6841. #if defined(HAVE_SESSION_TICKET) && \
  6842. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6843. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6844. OpenSSLTicketInit();
  6845. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6846. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6847. TicketInit();
  6848. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6849. #endif
  6850. #endif
  6851. }
  6852. #if defined(USE_WINDOWS_API)
  6853. port = opts->signal->port;
  6854. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6855. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6856. /* Let tcp_listen assign port */
  6857. port = 0;
  6858. #else
  6859. /* Use default port */
  6860. port = wolfSSLPort;
  6861. #endif
  6862. if (cbf != NULL)
  6863. doUdp = cbf->doUdp;
  6864. /* do it here to detect failure */
  6865. tcp_accept(
  6866. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6867. if (doUdp) {
  6868. cliLen = sizeof(cliAddr);
  6869. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6870. (struct sockaddr*)&cliAddr, &cliLen);
  6871. AssertIntGT(idx, 0);
  6872. }
  6873. else {
  6874. CloseSocket(sockfd);
  6875. }
  6876. wolfSSL_CTX_set_verify(ctx,
  6877. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6878. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6879. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6880. #endif
  6881. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6882. != WOLFSSL_SUCCESS) {
  6883. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6884. goto done;
  6885. }
  6886. if (cbf != NULL && cbf->certPemFile != NULL)
  6887. certFile = cbf->certPemFile;
  6888. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6889. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6890. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6891. #else
  6892. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6893. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6894. #endif
  6895. /*err_sys("can't load server cert chain file, "
  6896. "Please run from wolfSSL home dir");*/
  6897. goto done;
  6898. }
  6899. if (cbf != NULL && cbf->keyPemFile != NULL)
  6900. keyFile = cbf->keyPemFile;
  6901. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6902. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6903. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6904. #else
  6905. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6906. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6907. #endif
  6908. /*err_sys("can't load server key file, "
  6909. "Please run from wolfSSL home dir");*/
  6910. goto done;
  6911. }
  6912. #ifdef HAVE_CRL
  6913. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6914. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6915. goto done;
  6916. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6917. != WOLFSSL_SUCCESS)
  6918. goto done;
  6919. }
  6920. #endif
  6921. /* call ctx setup callback */
  6922. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6923. cbf->ctx_ready(ctx);
  6924. }
  6925. ssl = wolfSSL_new(ctx);
  6926. if (ssl == NULL) {
  6927. goto done;
  6928. }
  6929. if (doUdp) {
  6930. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6931. if (err != WOLFSSL_SUCCESS)
  6932. goto done;
  6933. }
  6934. #ifdef WOLFSSL_SESSION_EXPORT
  6935. /* only add in more complex nonblocking case with session export tests */
  6936. if (args && opts->argc > 0) {
  6937. /* set as nonblock and time out for waiting on read/write */
  6938. tcp_set_nonblocking(&clientfd);
  6939. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6940. }
  6941. #endif
  6942. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6943. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6944. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6945. #else
  6946. if (wolfSSL_use_certificate_file(ssl, certFile,
  6947. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6948. #endif
  6949. /*err_sys("can't load server cert chain file, "
  6950. "Please run from wolfSSL home dir");*/
  6951. goto done;
  6952. }
  6953. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6954. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6955. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6956. #else
  6957. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6958. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6959. #endif
  6960. /*err_sys("can't load server key file, "
  6961. "Please run from wolfSSL home dir");*/
  6962. goto done;
  6963. }
  6964. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6965. /*err_sys("SSL_set_fd failed");*/
  6966. goto done;
  6967. }
  6968. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6969. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6970. #elif !defined(NO_DH)
  6971. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6972. #endif
  6973. /* call ssl setup callback */
  6974. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6975. cbf->ssl_ready(ssl);
  6976. }
  6977. #ifdef WOLFSSL_SESSION_EXPORT
  6978. /* only add in more complex nonblocking case with session export tests */
  6979. if (opts->argc > 0) {
  6980. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6981. if (ret >= 0) {
  6982. opts->return_code = TEST_SUCCESS;
  6983. }
  6984. #ifdef WOLFSSL_TIRTOS
  6985. Task_yield();
  6986. #endif
  6987. goto done;
  6988. }
  6989. #endif
  6990. #ifdef WOLFSSL_ASYNC_CRYPT
  6991. err = 0; /* Reset error */
  6992. #endif
  6993. do {
  6994. #ifdef WOLFSSL_ASYNC_CRYPT
  6995. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6996. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6997. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6998. }
  6999. #endif
  7000. ret = wolfSSL_negotiate(ssl);
  7001. err = wolfSSL_get_error(ssl, 0);
  7002. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7003. if (ret != WOLFSSL_SUCCESS) {
  7004. char buff[WOLFSSL_MAX_ERROR_SZ];
  7005. fprintf(stderr, "error = %d, %s\n", err,
  7006. wolfSSL_ERR_error_string(err, buff));
  7007. /*err_sys("SSL_accept failed");*/
  7008. goto done;
  7009. }
  7010. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  7011. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  7012. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  7013. AssertIntGE(msg_len, 0);
  7014. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  7015. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  7016. AssertIntGE(msg_len, 0);
  7017. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  7018. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7019. if (idx > 0) {
  7020. input[idx] = '\0';
  7021. fprintf(stderr, "Client message: %s\n", input);
  7022. }
  7023. else if (idx < 0) {
  7024. goto done;
  7025. }
  7026. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7027. /*err_sys("SSL_write failed");*/
  7028. goto done;
  7029. }
  7030. if (cbf != NULL && cbf->on_result != NULL)
  7031. cbf->on_result(ssl);
  7032. #ifdef WOLFSSL_TIRTOS
  7033. Task_yield();
  7034. #endif
  7035. opts->return_code = TEST_SUCCESS;
  7036. done:
  7037. if (cbf != NULL)
  7038. cbf->last_err = err;
  7039. if (cbf != NULL && cbf->on_cleanup != NULL)
  7040. cbf->on_cleanup(ssl);
  7041. wolfSSL_shutdown(ssl);
  7042. wolfSSL_free(ssl);
  7043. if (!sharedCtx)
  7044. wolfSSL_CTX_free(ctx);
  7045. CloseSocket(clientfd);
  7046. #ifdef WOLFSSL_TIRTOS
  7047. fdCloseSession(Task_self());
  7048. #endif
  7049. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7050. && defined(HAVE_THREAD_LS)
  7051. wc_ecc_fp_free(); /* free per thread cache */
  7052. #endif
  7053. if (cbf == NULL || !cbf->ticNoInit) {
  7054. #if defined(HAVE_SESSION_TICKET) && \
  7055. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  7056. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  7057. OpenSSLTicketCleanup();
  7058. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  7059. TicketCleanup();
  7060. #endif
  7061. #endif
  7062. }
  7063. wolfSSL_SetLoggingPrefix(NULL);
  7064. WOLFSSL_RETURN_FROM_THREAD(0);
  7065. }
  7066. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7067. !defined(WOLFSSL_NO_TLS12)
  7068. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  7069. {
  7070. SOCKET_T sockfd;
  7071. SOCKET_T clientfd = -1;
  7072. word16 port;
  7073. callback_functions* cbf;
  7074. WOLFSSL_CTX* ctx = 0;
  7075. WOLFSSL* ssl = 0;
  7076. char msg[] = "I hear you fa shizzle!";
  7077. char input[1024];
  7078. int idx;
  7079. int ret, err = 0;
  7080. int sharedCtx = 0;
  7081. func_args* opts = (func_args*)args;
  7082. int loop_count = opts->argc;
  7083. int count = 0;
  7084. #ifdef WOLFSSL_TIRTOS
  7085. fdOpenSession(Task_self());
  7086. #endif
  7087. opts->return_code = TEST_FAIL;
  7088. cbf = opts->callbacks;
  7089. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7090. if (cbf != NULL && cbf->ctx) {
  7091. ctx = cbf->ctx;
  7092. sharedCtx = 1;
  7093. }
  7094. else
  7095. #endif
  7096. {
  7097. WOLFSSL_METHOD* method = NULL;
  7098. if (cbf != NULL && cbf->method != NULL) {
  7099. method = cbf->method();
  7100. }
  7101. else {
  7102. method = wolfSSLv23_server_method();
  7103. }
  7104. ctx = wolfSSL_CTX_new(method);
  7105. }
  7106. #if defined(USE_WINDOWS_API)
  7107. port = opts->signal->port;
  7108. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7109. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7110. /* Let tcp_listen assign port */
  7111. port = 0;
  7112. #else
  7113. /* Use default port */
  7114. port = wolfSSLPort;
  7115. #endif
  7116. wolfSSL_CTX_set_verify(ctx,
  7117. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7118. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7119. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7120. #endif
  7121. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  7122. != WOLFSSL_SUCCESS) {
  7123. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7124. /* Release the wait for TCP ready. */
  7125. signal_ready(opts->signal);
  7126. goto done;
  7127. }
  7128. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  7129. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7130. /*err_sys("can't load server cert chain file, "
  7131. "Please run from wolfSSL home dir");*/
  7132. /* Release the wait for TCP ready. */
  7133. signal_ready(opts->signal);
  7134. goto done;
  7135. }
  7136. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  7137. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7138. /*err_sys("can't load server key file, "
  7139. "Please run from wolfSSL home dir");*/
  7140. /* Release the wait for TCP ready. */
  7141. signal_ready(opts->signal);
  7142. goto done;
  7143. }
  7144. /* call ctx setup callback */
  7145. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7146. cbf->ctx_ready(ctx);
  7147. }
  7148. while (count != loop_count) {
  7149. ssl = wolfSSL_new(ctx);
  7150. if (ssl == NULL) {
  7151. signal_ready(opts->signal);
  7152. goto done;
  7153. }
  7154. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  7155. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7156. /*err_sys("can't load server cert chain file, "
  7157. "Please run from wolfSSL home dir");*/
  7158. /* Release the wait for TCP ready. */
  7159. signal_ready(opts->signal);
  7160. goto done;
  7161. }
  7162. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  7163. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7164. /*err_sys("can't load server key file, "
  7165. "Please run from wolfSSL home dir");*/
  7166. /* Release the wait for TCP ready. */
  7167. signal_ready(opts->signal);
  7168. goto done;
  7169. }
  7170. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7171. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7172. #elif !defined(NO_DH)
  7173. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7174. #endif
  7175. /* call ssl setup callback */
  7176. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7177. cbf->ssl_ready(ssl);
  7178. }
  7179. /* do it here to detect failure */
  7180. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  7181. 0);
  7182. CloseSocket(sockfd);
  7183. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  7184. /*err_sys("SSL_set_fd failed");*/
  7185. goto done;
  7186. }
  7187. #ifdef WOLFSSL_ASYNC_CRYPT
  7188. err = 0; /* Reset error */
  7189. #endif
  7190. do {
  7191. #ifdef WOLFSSL_ASYNC_CRYPT
  7192. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7193. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7194. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7195. }
  7196. #endif
  7197. ret = wolfSSL_accept(ssl);
  7198. err = wolfSSL_get_error(ssl, 0);
  7199. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7200. if (ret != WOLFSSL_SUCCESS) {
  7201. char buff[WOLFSSL_MAX_ERROR_SZ];
  7202. fprintf(stderr, "error = %d, %s\n", err,
  7203. wolfSSL_ERR_error_string(err, buff));
  7204. /*err_sys("SSL_accept failed");*/
  7205. goto done;
  7206. }
  7207. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7208. if (idx > 0) {
  7209. input[idx] = '\0';
  7210. fprintf(stderr, "Client message: %s\n", input);
  7211. }
  7212. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7213. /*err_sys("SSL_write failed");*/
  7214. goto done;
  7215. }
  7216. /* free ssl for this connection */
  7217. wolfSSL_shutdown(ssl);
  7218. wolfSSL_free(ssl); ssl = NULL;
  7219. CloseSocket(clientfd);
  7220. clientfd = -1;
  7221. count++;
  7222. }
  7223. #ifdef WOLFSSL_TIRTOS
  7224. Task_yield();
  7225. #endif
  7226. opts->return_code = TEST_SUCCESS;
  7227. done:
  7228. if (ssl != NULL) {
  7229. wolfSSL_shutdown(ssl);
  7230. wolfSSL_free(ssl);
  7231. }
  7232. if (!sharedCtx)
  7233. wolfSSL_CTX_free(ctx);
  7234. if (clientfd >= 0)
  7235. CloseSocket(clientfd);
  7236. #ifdef WOLFSSL_TIRTOS
  7237. fdCloseSession(Task_self());
  7238. #endif
  7239. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7240. && defined(HAVE_THREAD_LS)
  7241. wc_ecc_fp_free(); /* free per thread cache */
  7242. #endif
  7243. WOLFSSL_RETURN_FROM_THREAD(0);
  7244. }
  7245. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7246. static int test_client_nofail(void* args, cbType cb)
  7247. {
  7248. #if !defined(NO_WOLFSSL_CLIENT)
  7249. SOCKET_T sockfd = 0;
  7250. callback_functions* cbf;
  7251. WOLFSSL_CTX* ctx = 0;
  7252. WOLFSSL* ssl = 0;
  7253. WOLFSSL_CIPHER* cipher;
  7254. char msg[64] = "hello wolfssl!";
  7255. char reply[1024];
  7256. int input;
  7257. int msgSz = (int)XSTRLEN(msg);
  7258. int ret, err = 0;
  7259. int cipherSuite;
  7260. int sharedCtx = 0;
  7261. int doUdp = 0;
  7262. const char* cipherName1, *cipherName2;
  7263. wolfSSL_SetLoggingPrefix("client");
  7264. #ifdef WOLFSSL_TIRTOS
  7265. fdOpenSession(Task_self());
  7266. #endif
  7267. ((func_args*)args)->return_code = TEST_FAIL;
  7268. cbf = ((func_args*)args)->callbacks;
  7269. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7270. if (cbf != NULL && cbf->ctx) {
  7271. ctx = cbf->ctx;
  7272. sharedCtx = cbf->isSharedCtx;
  7273. }
  7274. else
  7275. #endif
  7276. {
  7277. WOLFSSL_METHOD* method = NULL;
  7278. if (cbf != NULL && cbf->method != NULL) {
  7279. method = cbf->method();
  7280. }
  7281. else {
  7282. method = wolfSSLv23_client_method();
  7283. }
  7284. ctx = wolfSSL_CTX_new(method);
  7285. }
  7286. if (cbf != NULL)
  7287. doUdp = cbf->doUdp;
  7288. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7289. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7290. #endif
  7291. /* Do connect here so server detects failures */
  7292. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7293. doUdp, 0, NULL);
  7294. /* Connect the socket so that we don't have to set the peer later on */
  7295. if (doUdp)
  7296. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7297. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7298. {
  7299. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7300. goto done;
  7301. }
  7302. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7303. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7304. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7305. #else
  7306. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7307. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7308. #endif
  7309. /*err_sys("can't load client cert file, "
  7310. "Please run from wolfSSL home dir");*/
  7311. goto done;
  7312. }
  7313. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7314. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7315. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7316. #else
  7317. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7318. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7319. #endif
  7320. /*err_sys("can't load client key file, "
  7321. "Please run from wolfSSL home dir");*/
  7322. goto done;
  7323. }
  7324. #ifdef HAVE_CRL
  7325. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7326. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7327. goto done;
  7328. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7329. != WOLFSSL_SUCCESS)
  7330. goto done;
  7331. }
  7332. #endif
  7333. /* call ctx setup callback */
  7334. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7335. cbf->ctx_ready(ctx);
  7336. }
  7337. ssl = wolfSSL_new(ctx);
  7338. if (ssl == NULL) {
  7339. goto done;
  7340. }
  7341. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7342. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7343. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7344. #else
  7345. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7346. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7347. #endif
  7348. /*err_sys("can't load client cert file, "
  7349. "Please run from wolfSSL home dir");*/
  7350. goto done;
  7351. }
  7352. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7353. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7354. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7355. #else
  7356. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7357. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7358. #endif
  7359. /*err_sys("can't load client key file, "
  7360. "Please run from wolfSSL home dir");*/
  7361. goto done;
  7362. }
  7363. if (!doUdp) {
  7364. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7365. /*err_sys("SSL_set_fd failed");*/
  7366. goto done;
  7367. }
  7368. }
  7369. else {
  7370. #ifdef WOLFSSL_DTLS
  7371. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7372. /*err_sys("SSL_set_fd failed");*/
  7373. goto done;
  7374. }
  7375. #else
  7376. goto done;
  7377. #endif
  7378. }
  7379. /* call ssl setup callback */
  7380. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7381. cbf->ssl_ready(ssl);
  7382. }
  7383. #ifdef WOLFSSL_ASYNC_CRYPT
  7384. err = 0; /* Reset error */
  7385. #endif
  7386. do {
  7387. #ifdef WOLFSSL_ASYNC_CRYPT
  7388. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7389. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7390. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7391. }
  7392. #endif
  7393. ret = wolfSSL_negotiate(ssl);
  7394. err = wolfSSL_get_error(ssl, 0);
  7395. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7396. if (ret != WOLFSSL_SUCCESS) {
  7397. char buff[WOLFSSL_MAX_ERROR_SZ];
  7398. fprintf(stderr, "error = %d, %s\n", err,
  7399. wolfSSL_ERR_error_string(err, buff));
  7400. /*err_sys("SSL_connect failed");*/
  7401. goto done;
  7402. }
  7403. /* test the various get cipher methods */
  7404. /* Internal cipher suite names */
  7405. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7406. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7407. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7408. (cipherSuite >> 8), cipherSuite & 0xFF);
  7409. AssertStrEQ(cipherName1, cipherName2);
  7410. /* IANA Cipher Suites Names */
  7411. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7412. then it's the internal cipher suite name */
  7413. cipher = wolfSSL_get_current_cipher(ssl);
  7414. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7415. cipherName2 = wolfSSL_get_cipher(ssl);
  7416. AssertStrEQ(cipherName1, cipherName2);
  7417. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7418. !defined(WOLFSSL_QT)
  7419. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7420. (cipherSuite >> 8), cipherSuite & 0xFF);
  7421. AssertStrEQ(cipherName1, cipherName2);
  7422. #endif
  7423. if (cb != NULL)
  7424. (cb)(ctx, ssl);
  7425. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7426. /*err_sys("SSL_write failed");*/
  7427. goto done;
  7428. }
  7429. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7430. if (input > 0) {
  7431. reply[input] = '\0';
  7432. fprintf(stderr, "Server response: %s\n", reply);
  7433. }
  7434. if (cbf != NULL && cbf->on_result != NULL)
  7435. cbf->on_result(ssl);
  7436. ((func_args*)args)->return_code = TEST_SUCCESS;
  7437. done:
  7438. if (cbf != NULL)
  7439. cbf->last_err = err;
  7440. if (cbf != NULL && cbf->on_cleanup != NULL)
  7441. cbf->on_cleanup(ssl);
  7442. wolfSSL_free(ssl);
  7443. if (!sharedCtx)
  7444. wolfSSL_CTX_free(ctx);
  7445. CloseSocket(sockfd);
  7446. #ifdef WOLFSSL_TIRTOS
  7447. fdCloseSession(Task_self());
  7448. #endif
  7449. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7450. && defined(HAVE_THREAD_LS)
  7451. wc_ecc_fp_free(); /* free per thread cache */
  7452. #endif
  7453. #else
  7454. (void)args;
  7455. (void)cb;
  7456. #endif /* !NO_WOLFSSL_CLIENT */
  7457. wolfSSL_SetLoggingPrefix(NULL);
  7458. return 0;
  7459. }
  7460. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7461. callback_functions* server_cb, cbType client_on_handshake)
  7462. {
  7463. func_args client_args;
  7464. func_args server_args;
  7465. tcp_ready ready;
  7466. THREAD_TYPE serverThread;
  7467. XMEMSET(&client_args, 0, sizeof(func_args));
  7468. XMEMSET(&server_args, 0, sizeof(func_args));
  7469. #ifdef WOLFSSL_TIRTOS
  7470. fdOpenSession(Task_self());
  7471. #endif
  7472. StartTCP();
  7473. InitTcpReady(&ready);
  7474. #if defined(USE_WINDOWS_API)
  7475. /* use RNG to get random port if using windows */
  7476. ready.port = GetRandomPort();
  7477. #endif
  7478. server_args.signal = &ready;
  7479. server_args.callbacks = server_cb;
  7480. client_args.signal = &ready;
  7481. client_args.callbacks = client_cb;
  7482. start_thread(test_server_nofail, &server_args, &serverThread);
  7483. wait_tcp_ready(&server_args);
  7484. test_client_nofail(&client_args, client_on_handshake);
  7485. join_thread(serverThread);
  7486. client_cb->return_code = client_args.return_code;
  7487. server_cb->return_code = server_args.return_code;
  7488. FreeTcpReady(&ready);
  7489. #ifdef WOLFSSL_TIRTOS
  7490. fdOpenSession(Task_self());
  7491. #endif
  7492. }
  7493. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7494. callback_functions* server_cb)
  7495. {
  7496. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7497. }
  7498. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7499. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7500. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7501. void* server_args)
  7502. {
  7503. SOCKET_T sockfd = 0;
  7504. callback_functions* cbf;
  7505. WOLFSSL_CTX* ctx = 0;
  7506. WOLFSSL* ssl = 0;
  7507. WOLFSSL_SESSION* session = NULL;
  7508. char msg[64] = "hello wolfssl!";
  7509. char reply[1024];
  7510. int input;
  7511. int msgSz = (int)XSTRLEN(msg);
  7512. int ret, err = 0;
  7513. int sharedCtx = 0;
  7514. #ifdef WOLFSSL_TIRTOS
  7515. fdOpenSession(Task_self());
  7516. #endif
  7517. ((func_args*)args)->return_code = TEST_FAIL;
  7518. cbf = ((func_args*)args)->callbacks;
  7519. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7520. if (cbf != NULL && cbf->ctx) {
  7521. ctx = cbf->ctx;
  7522. sharedCtx = 1;
  7523. }
  7524. else
  7525. #endif
  7526. {
  7527. WOLFSSL_METHOD* method = NULL;
  7528. if (cbf != NULL && cbf->method != NULL) {
  7529. method = cbf->method();
  7530. }
  7531. else {
  7532. method = wolfSSLv23_client_method();
  7533. }
  7534. ctx = wolfSSL_CTX_new(method);
  7535. }
  7536. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7537. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7538. #endif
  7539. /* Do connect here so server detects failures */
  7540. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7541. 0, 0, NULL);
  7542. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7543. WOLFSSL_SUCCESS) {
  7544. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7545. goto done;
  7546. }
  7547. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7548. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7549. /*err_sys("can't load client cert file, "
  7550. "Please run from wolfSSL home dir");*/
  7551. goto done;
  7552. }
  7553. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7554. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7555. /*err_sys("can't load client key file, "
  7556. "Please run from wolfSSL home dir");*/
  7557. goto done;
  7558. }
  7559. /* call ctx setup callback */
  7560. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7561. cbf->ctx_ready(ctx);
  7562. }
  7563. ssl = wolfSSL_new(ctx);
  7564. if (ssl == NULL) {
  7565. goto done;
  7566. }
  7567. /* keep handshake resources for re-using WOLFSSL obj */
  7568. wolfSSL_KeepArrays(ssl);
  7569. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7570. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7571. goto done;
  7572. }
  7573. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7574. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7575. /*err_sys("can't load client cert file, "
  7576. "Please run from wolfSSL home dir");*/
  7577. goto done;
  7578. }
  7579. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7580. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7581. /*err_sys("can't load client key file, "
  7582. "Please run from wolfSSL home dir");*/
  7583. goto done;
  7584. }
  7585. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7586. /*err_sys("SSL_set_fd failed");*/
  7587. goto done;
  7588. }
  7589. /* call ssl setup callback */
  7590. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7591. cbf->ssl_ready(ssl);
  7592. }
  7593. #ifdef WOLFSSL_ASYNC_CRYPT
  7594. err = 0; /* Reset error */
  7595. #endif
  7596. do {
  7597. #ifdef WOLFSSL_ASYNC_CRYPT
  7598. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7599. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7600. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7601. }
  7602. #endif
  7603. ret = wolfSSL_connect(ssl);
  7604. err = wolfSSL_get_error(ssl, 0);
  7605. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7606. if (ret != WOLFSSL_SUCCESS) {
  7607. char buff[WOLFSSL_MAX_ERROR_SZ];
  7608. fprintf(stderr, "error = %d, %s\n", err,
  7609. wolfSSL_ERR_error_string(err, buff));
  7610. /*err_sys("SSL_connect failed");*/
  7611. goto done;
  7612. }
  7613. /* Build first session */
  7614. if (cb != NULL)
  7615. cb(ctx, ssl);
  7616. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7617. /*err_sys("SSL_write failed");*/
  7618. goto done;
  7619. }
  7620. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7621. if (input > 0) {
  7622. reply[input] = '\0';
  7623. fprintf(stderr, "Server response: %s\n", reply);
  7624. }
  7625. /* Session Resumption by re-using WOLFSSL object */
  7626. wolfSSL_set_quiet_shutdown(ssl, 1);
  7627. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7628. /* err_sys ("SSL shutdown failed"); */
  7629. goto done;
  7630. }
  7631. session = wolfSSL_get1_session(ssl);
  7632. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7633. wolfSSL_SESSION_free(session);
  7634. /* err_sys ("SSL_clear failed"); */
  7635. goto done;
  7636. }
  7637. wolfSSL_set_session(ssl, session);
  7638. wolfSSL_SESSION_free(session);
  7639. session = NULL;
  7640. /* close socket once */
  7641. CloseSocket(sockfd);
  7642. sockfd = 0;
  7643. /* wait until server ready */
  7644. wait_tcp_ready((func_args*)server_args);
  7645. fprintf(stderr, "session resumption\n");
  7646. /* Do re-connect */
  7647. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7648. 0, 0, NULL);
  7649. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7650. /*err_sys("SSL_set_fd failed");*/
  7651. goto done;
  7652. }
  7653. #ifdef WOLFSSL_ASYNC_CRYPT
  7654. err = 0; /* Reset error */
  7655. #endif
  7656. do {
  7657. #ifdef WOLFSSL_ASYNC_CRYPT
  7658. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7659. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7660. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7661. }
  7662. #endif
  7663. ret = wolfSSL_connect(ssl);
  7664. err = wolfSSL_get_error(ssl, 0);
  7665. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7666. if (ret != WOLFSSL_SUCCESS) {
  7667. char buff[WOLFSSL_MAX_ERROR_SZ];
  7668. fprintf(stderr, "error = %d, %s\n", err,
  7669. wolfSSL_ERR_error_string(err, buff));
  7670. /*err_sys("SSL_connect failed");*/
  7671. goto done;
  7672. }
  7673. /* Build first session */
  7674. if (cb != NULL)
  7675. cb(ctx, ssl);
  7676. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7677. /*err_sys("SSL_write failed");*/
  7678. goto done;
  7679. }
  7680. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7681. if (input > 0) {
  7682. reply[input] = '\0';
  7683. fprintf(stderr, "Server response: %s\n", reply);
  7684. }
  7685. ((func_args*)args)->return_code = TEST_SUCCESS;
  7686. done:
  7687. wolfSSL_free(ssl);
  7688. if (!sharedCtx)
  7689. wolfSSL_CTX_free(ctx);
  7690. CloseSocket(sockfd);
  7691. #ifdef WOLFSSL_TIRTOS
  7692. fdCloseSession(Task_self());
  7693. #endif
  7694. return;
  7695. }
  7696. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7697. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7698. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7699. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7700. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7701. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7702. #define HAVE_ALPN_PROTOS_SUPPORT
  7703. #endif
  7704. /* Generic TLS client / server with callbacks for API unit tests
  7705. * Used by SNI / ALPN / crypto callback helper functions */
  7706. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7707. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7708. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7709. #define ENABLE_TLS_CALLBACK_TEST
  7710. #endif
  7711. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7712. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7713. /* TLS server for API unit testing - generic */
  7714. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7715. {
  7716. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7717. WOLFSSL_CTX* ctx = NULL;
  7718. WOLFSSL* ssl = NULL;
  7719. SOCKET_T sfd = 0;
  7720. SOCKET_T cfd = 0;
  7721. word16 port;
  7722. char msg[] = "I hear you fa shizzle!";
  7723. int len = (int) XSTRLEN(msg);
  7724. char input[1024];
  7725. int idx;
  7726. int ret, err = 0;
  7727. ((func_args*)args)->return_code = TEST_FAIL;
  7728. #if defined(USE_WINDOWS_API)
  7729. port = ((func_args*)args)->signal->port;
  7730. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7731. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7732. /* Let tcp_listen assign port */
  7733. port = 0;
  7734. #else
  7735. /* Use default port */
  7736. port = wolfSSLPort;
  7737. #endif
  7738. #ifdef WOLFSSL_DTLS
  7739. if (callbacks->method == wolfDTLS_server_method
  7740. #ifdef WOLFSSL_STATIC_MEMORY
  7741. || callbacks->method_ex == wolfDTLS_server_method_ex
  7742. #endif
  7743. #ifndef NO_OLD_TLS
  7744. || callbacks->method == wolfDTLSv1_server_method
  7745. #ifdef WOLFSSL_STATIC_MEMORY
  7746. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7747. #endif
  7748. #endif
  7749. #ifndef WOLFSSL_NO_TLS12
  7750. || callbacks->method == wolfDTLSv1_2_server_method
  7751. #ifdef WOLFSSL_STATIC_MEMORY
  7752. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7753. #endif
  7754. #endif
  7755. #ifdef WOLFSSL_DTLS13
  7756. || callbacks->method == wolfDTLSv1_3_server_method
  7757. #ifdef WOLFSSL_STATIC_MEMORY
  7758. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7759. #endif
  7760. #endif
  7761. ) {
  7762. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7763. }
  7764. else
  7765. #endif
  7766. {
  7767. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7768. }
  7769. #ifdef WOLFSSL_STATIC_MEMORY
  7770. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7771. callbacks->memSz > 0) {
  7772. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7773. callbacks->mem, callbacks->memSz, 0, 1);
  7774. if (ret != WOLFSSL_SUCCESS) {
  7775. fprintf(stderr, "CTX static new failed %d\n", ret);
  7776. goto cleanup;
  7777. }
  7778. }
  7779. #else
  7780. ctx = wolfSSL_CTX_new(callbacks->method());
  7781. #endif
  7782. if (ctx == NULL) {
  7783. fprintf(stderr, "CTX new failed\n");
  7784. goto cleanup;
  7785. }
  7786. /* set defaults */
  7787. if (callbacks->caPemFile == NULL)
  7788. callbacks->caPemFile = cliCertFile;
  7789. if (callbacks->certPemFile == NULL)
  7790. callbacks->certPemFile = svrCertFile;
  7791. if (callbacks->keyPemFile == NULL)
  7792. callbacks->keyPemFile = svrKeyFile;
  7793. #ifdef WOLFSSL_TIRTOS
  7794. fdOpenSession(Task_self());
  7795. #endif
  7796. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7797. wolfSSL_CTX_set_verify(ctx,
  7798. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7799. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7800. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7801. #endif
  7802. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7803. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7804. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7805. goto cleanup;
  7806. }
  7807. #endif
  7808. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7809. WOLFSSL_SUCCESS) {
  7810. goto cleanup;
  7811. }
  7812. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7813. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7814. goto cleanup;
  7815. }
  7816. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7817. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7818. goto cleanup;
  7819. }
  7820. #ifdef HAVE_CRL
  7821. if (callbacks->crlPemFile != NULL) {
  7822. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7823. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7824. goto cleanup;
  7825. }
  7826. }
  7827. #endif
  7828. if (callbacks->ctx_ready)
  7829. callbacks->ctx_ready(ctx);
  7830. ssl = wolfSSL_new(ctx);
  7831. if (ssl == NULL) {
  7832. fprintf(stderr, "SSL new failed\n");
  7833. goto cleanup;
  7834. }
  7835. if (wolfSSL_dtls(ssl)) {
  7836. SOCKADDR_IN_T cliAddr;
  7837. socklen_t cliLen;
  7838. cliLen = sizeof(cliAddr);
  7839. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7840. (struct sockaddr*)&cliAddr, &cliLen);
  7841. if (idx <= 0) {
  7842. goto cleanup;
  7843. }
  7844. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7845. }
  7846. else {
  7847. CloseSocket(sfd);
  7848. }
  7849. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7850. goto cleanup;
  7851. }
  7852. if (callbacks->loadToSSL) {
  7853. wolfSSL_SetDevId(ssl, callbacks->devId);
  7854. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7855. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7856. goto cleanup;
  7857. }
  7858. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7859. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7860. goto cleanup;
  7861. }
  7862. }
  7863. #ifdef NO_PSK
  7864. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7865. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7866. #elif !defined(NO_DH)
  7867. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7868. #endif
  7869. #endif
  7870. if (callbacks->ssl_ready)
  7871. callbacks->ssl_ready(ssl);
  7872. #ifdef WOLFSSL_ASYNC_CRYPT
  7873. err = 0; /* Reset error */
  7874. #endif
  7875. do {
  7876. #ifdef WOLFSSL_ASYNC_CRYPT
  7877. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7878. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7879. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7880. }
  7881. #endif
  7882. ret = wolfSSL_accept(ssl);
  7883. err = wolfSSL_get_error(ssl, ret);
  7884. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7885. if (ret != WOLFSSL_SUCCESS) {
  7886. char buff[WOLFSSL_MAX_ERROR_SZ];
  7887. fprintf(stderr, "accept error = %d, %s\n", err,
  7888. wolfSSL_ERR_error_string(err, buff));
  7889. /*err_sys("SSL_accept failed");*/
  7890. }
  7891. else {
  7892. #ifdef WOLFSSL_ASYNC_CRYPT
  7893. err = 0; /* Reset error */
  7894. #endif
  7895. do {
  7896. #ifdef WOLFSSL_ASYNC_CRYPT
  7897. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7898. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7899. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7900. }
  7901. #endif
  7902. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7903. err = wolfSSL_get_error(ssl, idx);
  7904. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7905. if (idx > 0) {
  7906. input[idx] = 0;
  7907. fprintf(stderr, "Client message: %s\n", input);
  7908. }
  7909. #ifdef WOLFSSL_ASYNC_CRYPT
  7910. err = 0; /* Reset error */
  7911. #endif
  7912. do {
  7913. #ifdef WOLFSSL_ASYNC_CRYPT
  7914. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7915. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7916. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7917. }
  7918. #endif
  7919. ret = wolfSSL_write(ssl, msg, len);
  7920. err = wolfSSL_get_error(ssl, ret);
  7921. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7922. if (len != ret) {
  7923. goto cleanup;
  7924. }
  7925. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7926. defined(WOLFSSL_DTLS)
  7927. if (wolfSSL_dtls(ssl)) {
  7928. byte* import;
  7929. word32 sz;
  7930. wolfSSL_dtls_export(ssl, NULL, &sz);
  7931. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7932. if (import == NULL) {
  7933. goto cleanup;
  7934. }
  7935. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7936. if (idx < 0) {
  7937. goto cleanup;
  7938. }
  7939. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7940. goto cleanup;
  7941. }
  7942. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7943. }
  7944. #endif
  7945. #ifdef WOLFSSL_TIRTOS
  7946. Task_yield();
  7947. #endif
  7948. ((func_args*)args)->return_code = TEST_SUCCESS;
  7949. }
  7950. if (callbacks->on_result)
  7951. callbacks->on_result(ssl);
  7952. wolfSSL_shutdown(ssl);
  7953. cleanup:
  7954. wolfSSL_free(ssl);
  7955. wolfSSL_CTX_free(ctx);
  7956. CloseSocket(cfd);
  7957. #ifdef WOLFSSL_TIRTOS
  7958. fdCloseSession(Task_self());
  7959. #endif
  7960. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7961. && defined(HAVE_THREAD_LS)
  7962. wc_ecc_fp_free(); /* free per thread cache */
  7963. #endif
  7964. WOLFSSL_RETURN_FROM_THREAD(0);
  7965. }
  7966. /* TLS Client for API unit testing - generic */
  7967. static void run_wolfssl_client(void* args)
  7968. {
  7969. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7970. WOLFSSL_CTX* ctx = NULL;
  7971. WOLFSSL* ssl = NULL;
  7972. SOCKET_T sfd = 0;
  7973. char msg[] = "hello wolfssl server!";
  7974. int len = (int) XSTRLEN(msg);
  7975. char input[1024];
  7976. int ret, err = 0;
  7977. ((func_args*)args)->return_code = TEST_FAIL;
  7978. /* set defaults */
  7979. if (callbacks->caPemFile == NULL)
  7980. callbacks->caPemFile = caCertFile;
  7981. if (callbacks->certPemFile == NULL)
  7982. callbacks->certPemFile = cliCertFile;
  7983. if (callbacks->keyPemFile == NULL)
  7984. callbacks->keyPemFile = cliKeyFile;
  7985. #ifdef WOLFSSL_STATIC_MEMORY
  7986. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7987. callbacks->memSz > 0) {
  7988. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7989. callbacks->mem, callbacks->memSz, 0, 1);
  7990. if (ret != WOLFSSL_SUCCESS) {
  7991. fprintf(stderr, "CTX static new failed %d\n", ret);
  7992. goto cleanup;
  7993. }
  7994. }
  7995. #else
  7996. ctx = wolfSSL_CTX_new(callbacks->method());
  7997. #endif
  7998. if (ctx == NULL) {
  7999. fprintf(stderr, "CTX new failed\n");
  8000. goto cleanup;
  8001. }
  8002. #ifdef WOLFSSL_TIRTOS
  8003. fdOpenSession(Task_self());
  8004. #endif
  8005. if (!callbacks->loadToSSL) {
  8006. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  8007. }
  8008. #ifdef WOLFSSL_ENCRYPTED_KEYS
  8009. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  8010. #endif
  8011. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  8012. WOLFSSL_SUCCESS) {
  8013. goto cleanup;
  8014. }
  8015. if (!callbacks->loadToSSL) {
  8016. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  8017. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8018. goto cleanup;
  8019. }
  8020. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  8021. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8022. goto cleanup;
  8023. }
  8024. }
  8025. #ifdef HAVE_CRL
  8026. if (callbacks->crlPemFile != NULL) {
  8027. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  8028. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8029. goto cleanup;
  8030. }
  8031. }
  8032. #endif
  8033. if (callbacks->ctx_ready)
  8034. callbacks->ctx_ready(ctx);
  8035. ssl = wolfSSL_new(ctx);
  8036. if (wolfSSL_dtls(ssl)) {
  8037. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8038. 1, 0, ssl);
  8039. }
  8040. else {
  8041. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8042. 0, 0, ssl);
  8043. }
  8044. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  8045. goto cleanup;
  8046. }
  8047. if (callbacks->loadToSSL) {
  8048. wolfSSL_SetDevId(ssl, callbacks->devId);
  8049. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  8050. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8051. goto cleanup;
  8052. }
  8053. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  8054. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8055. goto cleanup;
  8056. }
  8057. }
  8058. if (callbacks->ssl_ready)
  8059. callbacks->ssl_ready(ssl);
  8060. #ifdef WOLFSSL_ASYNC_CRYPT
  8061. err = 0; /* Reset error */
  8062. #endif
  8063. do {
  8064. #ifdef WOLFSSL_ASYNC_CRYPT
  8065. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8066. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8067. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8068. }
  8069. #endif
  8070. ret = wolfSSL_connect(ssl);
  8071. err = wolfSSL_get_error(ssl, ret);
  8072. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8073. if (ret != WOLFSSL_SUCCESS) {
  8074. char buff[WOLFSSL_MAX_ERROR_SZ];
  8075. fprintf(stderr, "error = %d, %s\n", err,
  8076. wolfSSL_ERR_error_string(err, buff));
  8077. /*err_sys("SSL_connect failed");*/
  8078. }
  8079. else {
  8080. #ifdef WOLFSSL_ASYNC_CRYPT
  8081. err = 0; /* Reset error */
  8082. #endif
  8083. do {
  8084. #ifdef WOLFSSL_ASYNC_CRYPT
  8085. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8086. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8087. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8088. }
  8089. #endif
  8090. ret = wolfSSL_write(ssl, msg, len);
  8091. err = wolfSSL_get_error(ssl, ret);
  8092. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8093. if (len != ret)
  8094. goto cleanup;
  8095. #ifdef WOLFSSL_ASYNC_CRYPT
  8096. err = 0; /* Reset error */
  8097. #endif
  8098. do {
  8099. #ifdef WOLFSSL_ASYNC_CRYPT
  8100. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8101. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8102. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8103. }
  8104. #endif
  8105. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  8106. err = wolfSSL_get_error(ssl, ret);
  8107. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8108. if (ret > 0) {
  8109. input[ret] = '\0'; /* null term */
  8110. fprintf(stderr, "Server response: %s\n", input);
  8111. }
  8112. ((func_args*)args)->return_code = TEST_SUCCESS;
  8113. }
  8114. if (callbacks->on_result)
  8115. callbacks->on_result(ssl);
  8116. cleanup:
  8117. wolfSSL_free(ssl);
  8118. wolfSSL_CTX_free(ctx);
  8119. CloseSocket(sfd);
  8120. #ifdef WOLFSSL_TIRTOS
  8121. fdCloseSession(Task_self());
  8122. #endif
  8123. }
  8124. #endif /* ENABLE_TLS_CALLBACK_TEST */
  8125. static int test_wolfSSL_read_write(void)
  8126. {
  8127. /* The unit testing for read and write shall happen simultaneously, since
  8128. * one can't do anything with one without the other. (Except for a failure
  8129. * test case.) This function will call all the others that will set up,
  8130. * execute, and report their test findings.
  8131. *
  8132. * Set up the success case first. This function will become the template
  8133. * for the other tests. This should eventually be renamed
  8134. *
  8135. * The success case isn't interesting, how can this fail?
  8136. * - Do not give the client context a CA certificate. The connect should
  8137. * fail. Do not need server for this?
  8138. * - Using NULL for the ssl object on server. Do not need client for this.
  8139. * - Using NULL for the ssl object on client. Do not need server for this.
  8140. * - Good ssl objects for client and server. Client write() without server
  8141. * read().
  8142. * - Good ssl objects for client and server. Server write() without client
  8143. * read().
  8144. * - Forgetting the password callback?
  8145. */
  8146. tcp_ready ready;
  8147. func_args client_args;
  8148. func_args server_args;
  8149. THREAD_TYPE serverThread;
  8150. EXPECT_DECLS;
  8151. XMEMSET(&client_args, 0, sizeof(func_args));
  8152. XMEMSET(&server_args, 0, sizeof(func_args));
  8153. #ifdef WOLFSSL_TIRTOS
  8154. fdOpenSession(Task_self());
  8155. #endif
  8156. StartTCP();
  8157. InitTcpReady(&ready);
  8158. #if defined(USE_WINDOWS_API)
  8159. /* use RNG to get random port if using windows */
  8160. ready.port = GetRandomPort();
  8161. #endif
  8162. server_args.signal = &ready;
  8163. client_args.signal = &ready;
  8164. start_thread(test_server_nofail, &server_args, &serverThread);
  8165. wait_tcp_ready(&server_args);
  8166. test_client_nofail(&client_args, NULL);
  8167. join_thread(serverThread);
  8168. ExpectTrue(client_args.return_code);
  8169. ExpectTrue(server_args.return_code);
  8170. FreeTcpReady(&ready);
  8171. #ifdef WOLFSSL_TIRTOS
  8172. fdOpenSession(Task_self());
  8173. #endif
  8174. return EXPECT_RESULT();
  8175. }
  8176. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  8177. {
  8178. EXPECT_DECLS;
  8179. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  8180. !defined(WOLFSSL_NO_TLS12)
  8181. /* The unit test for session resumption by re-using WOLFSSL object.
  8182. * WOLFSSL object is not cleared after first session. It reuse the object
  8183. * for second connection.
  8184. */
  8185. tcp_ready ready;
  8186. func_args client_args;
  8187. func_args server_args;
  8188. THREAD_TYPE serverThread;
  8189. callback_functions client_cbf;
  8190. callback_functions server_cbf;
  8191. XMEMSET(&client_args, 0, sizeof(func_args));
  8192. XMEMSET(&server_args, 0, sizeof(func_args));
  8193. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  8194. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  8195. #ifdef WOLFSSL_TIRTOS
  8196. fdOpenSession(Task_self());
  8197. #endif
  8198. StartTCP();
  8199. InitTcpReady(&ready);
  8200. #if defined(USE_WINDOWS_API)
  8201. /* use RNG to get random port if using windows */
  8202. ready.port = GetRandomPort();
  8203. #endif
  8204. client_cbf.method = wolfTLSv1_2_client_method;
  8205. server_cbf.method = wolfTLSv1_2_server_method;
  8206. client_args.callbacks = &client_cbf;
  8207. server_args.callbacks = &server_cbf;
  8208. server_args.signal = &ready;
  8209. client_args.signal = &ready;
  8210. /* the var is used for loop number */
  8211. server_args.argc = 2;
  8212. start_thread(test_server_loop, &server_args, &serverThread);
  8213. wait_tcp_ready(&server_args);
  8214. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  8215. join_thread(serverThread);
  8216. ExpectTrue(client_args.return_code);
  8217. ExpectTrue(server_args.return_code);
  8218. FreeTcpReady(&ready);
  8219. #ifdef WOLFSSL_TIRTOS
  8220. fdOpenSession(Task_self());
  8221. #endif
  8222. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8223. * !defined(WOLFSSL_TLS13) */
  8224. return EXPECT_RESULT();
  8225. }
  8226. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8227. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8228. WOLFSSL_CTX* ctx)
  8229. {
  8230. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8231. myVerifyAction = VERIFY_USE_PREVERFIY;
  8232. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8233. return TEST_SUCCESS;
  8234. }
  8235. #endif
  8236. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8237. {
  8238. EXPECT_DECLS;
  8239. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8240. test_ssl_cbf client_cbf;
  8241. test_ssl_cbf server_cbf;
  8242. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8243. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8244. #ifdef WOLFSSL_TLS13
  8245. client_cbf.method = wolfTLSv1_3_client_method;
  8246. #endif /* WOLFSSL_TLS13 */
  8247. client_cbf.ctx_ready =
  8248. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8249. /* test case 1 verify depth is equal to peer chain */
  8250. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8251. &server_cbf, NULL), TEST_SUCCESS);
  8252. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8253. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8254. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8255. return EXPECT_RESULT();
  8256. }
  8257. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8258. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8259. WOLFSSL_CTX* ctx)
  8260. {
  8261. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8262. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8263. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8264. return TEST_SUCCESS;
  8265. }
  8266. #endif
  8267. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8268. {
  8269. EXPECT_DECLS;
  8270. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8271. test_ssl_cbf client_cbf;
  8272. test_ssl_cbf server_cbf;
  8273. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8274. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8275. #ifdef WOLFSSL_TLS13
  8276. client_cbf.method = wolfTLSv1_3_client_method;
  8277. #endif /* WOLFSSL_TLS13 */
  8278. client_cbf.ctx_ready =
  8279. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8280. /* test case 2
  8281. * verify depth is zero, number of peer's chain is 2.
  8282. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8283. * callback.
  8284. */
  8285. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8286. &server_cbf, NULL), TEST_SUCCESS);
  8287. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8288. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8289. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8290. return EXPECT_RESULT();
  8291. }
  8292. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8293. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8294. WOLFSSL_CTX* ctx)
  8295. {
  8296. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8297. myVerifyAction = VERIFY_USE_PREVERFIY;
  8298. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8299. return TEST_SUCCESS;
  8300. }
  8301. #endif
  8302. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8303. {
  8304. EXPECT_DECLS;
  8305. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8306. test_ssl_cbf client_cbf;
  8307. test_ssl_cbf server_cbf;
  8308. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8309. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8310. #ifdef WOLFSSL_TLS13
  8311. client_cbf.method = wolfTLSv1_3_client_method;
  8312. #endif /* WOLFSSL_TLS13 */
  8313. client_cbf.ctx_ready =
  8314. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8315. /* test case 3
  8316. * verify depth is zero, number of peer's chain is 2
  8317. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8318. * therefore, handshake becomes failure.
  8319. */
  8320. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8321. &server_cbf, NULL), -1001);
  8322. ExpectIntEQ(client_cbf.return_code, -1000);
  8323. ExpectIntEQ(server_cbf.return_code, -1000);
  8324. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8325. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8326. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8327. return EXPECT_RESULT();
  8328. }
  8329. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8330. !defined(WOLFSSL_NO_TLS12) && \
  8331. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8332. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8333. {
  8334. EXPECT_DECLS;
  8335. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8336. return EXPECT_RESULT();
  8337. }
  8338. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8339. {
  8340. EXPECT_DECLS;
  8341. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8342. return EXPECT_RESULT();
  8343. }
  8344. #endif
  8345. static int test_wolfSSL_CTX_set_cipher_list(void)
  8346. {
  8347. EXPECT_DECLS;
  8348. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8349. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8350. #if !defined(WOLFSSL_NO_TLS12)
  8351. WOLFSSL_CTX* ctxClient = NULL;
  8352. WOLFSSL* sslClient = NULL;
  8353. test_ssl_cbf client_cbf;
  8354. test_ssl_cbf server_cbf;
  8355. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8356. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8357. server_cbf.method = wolfTLSv1_2_server_method;
  8358. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8359. client_cbf.method = wolfTLSv1_2_client_method;
  8360. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8361. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8362. &server_cbf, NULL), TEST_SUCCESS);
  8363. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8364. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8365. /* check with cipher string that has '+' */
  8366. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8367. /* Use trailing : with nothing to test for ASAN */
  8368. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8369. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8370. /* check for the existence of an ECDHE ECDSA cipher suite */
  8371. if (EXPECT_SUCCESS()) {
  8372. int i = 0;
  8373. int found = 0;
  8374. const char* suite;
  8375. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8376. WOLFSSL_CIPHER* current;
  8377. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8378. do {
  8379. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8380. if (current) {
  8381. suite = wolfSSL_CIPHER_get_name(current);
  8382. if (suite && XSTRSTR(suite, "ECDSA")) {
  8383. found = 1;
  8384. break;
  8385. }
  8386. }
  8387. } while (current);
  8388. ExpectIntEQ(found, 1);
  8389. }
  8390. wolfSSL_free(sslClient);
  8391. wolfSSL_CTX_free(ctxClient);
  8392. #endif /* !WOLFSSL_NO_TLS12 */
  8393. #endif
  8394. return EXPECT_RESULT();
  8395. }
  8396. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8397. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8398. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8399. WOLFSSL* ssl)
  8400. {
  8401. EXPECT_DECLS;
  8402. size_t msg_len;
  8403. (void)ctx;
  8404. /* get_finished test */
  8405. /* 1. get own sent message */
  8406. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8407. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8408. ExpectIntGE(msg_len, 0);
  8409. /* 2. get peer message */
  8410. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8411. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8412. ExpectIntGE(msg_len, 0);
  8413. return EXPECT_RESULT();
  8414. }
  8415. #endif
  8416. static int test_wolfSSL_get_finished(void)
  8417. {
  8418. EXPECT_DECLS;
  8419. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8420. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8421. test_ssl_cbf client_cbf;
  8422. test_ssl_cbf server_cbf;
  8423. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8424. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8425. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8426. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8427. TEST_SUCCESS);
  8428. /* test received msg vs sent msg */
  8429. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8430. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8431. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8432. return EXPECT_RESULT();
  8433. }
  8434. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8435. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8436. !defined(NO_SESSION_CACHE)
  8437. /* Sessions to restore/store */
  8438. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8439. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8440. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8441. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8442. {
  8443. /* Don't store sessions. Lookup is still enabled. */
  8444. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8445. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8446. #ifdef OPENSSL_EXTRA
  8447. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8448. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8449. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8450. #endif
  8451. /* Require both peers to provide certs */
  8452. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8453. }
  8454. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8455. {
  8456. WOLFSSL_SESSION** sess;
  8457. if (wolfSSL_is_server(ssl))
  8458. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8459. else
  8460. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8461. if (*sess == NULL) {
  8462. #ifdef NO_SESSION_CACHE_REF
  8463. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8464. #else
  8465. /* Test for backwards compatibility */
  8466. if (wolfSSL_is_server(ssl)) {
  8467. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8468. }
  8469. else {
  8470. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8471. }
  8472. #endif
  8473. /* Now save the session in the internal store to make it available
  8474. * for lookup. For TLS 1.3, we can't save the session without
  8475. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8476. * session from cache. */
  8477. if (wolfSSL_is_server(ssl)
  8478. #ifndef WOLFSSL_TICKET_HAVE_ID
  8479. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8480. #endif
  8481. )
  8482. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8483. *sess), WOLFSSL_SUCCESS);
  8484. }
  8485. else {
  8486. /* If we have a session retrieved then remaining connections should be
  8487. * resuming on that session */
  8488. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8489. }
  8490. /* Save CTX to be able to decrypt tickets */
  8491. if (wolfSSL_is_server(ssl) &&
  8492. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8493. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8494. = wolfSSL_get_SSL_CTX(ssl));
  8495. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8496. WOLFSSL_SUCCESS);
  8497. }
  8498. #ifdef SESSION_CERTS
  8499. #ifndef WOLFSSL_TICKET_HAVE_ID
  8500. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8501. wolfSSL_session_reused(ssl))
  8502. #endif
  8503. {
  8504. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8505. * for all connections. TLS 1.3 only has tickets so if we don't
  8506. * include the session id in the ticket then the certificates
  8507. * will not be available on resumption. */
  8508. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8509. AssertNotNull(peer);
  8510. wolfSSL_X509_free(peer);
  8511. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8512. #ifdef OPENSSL_EXTRA
  8513. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8514. #endif
  8515. }
  8516. #endif /* SESSION_CERTS */
  8517. }
  8518. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8519. {
  8520. /* Set the session to reuse for the client */
  8521. AssertIntEQ(wolfSSL_set_session(ssl,
  8522. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8523. }
  8524. #endif
  8525. static int test_wolfSSL_CTX_add_session(void)
  8526. {
  8527. EXPECT_DECLS;
  8528. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8529. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8530. !defined(NO_SESSION_CACHE)
  8531. tcp_ready ready;
  8532. func_args client_args;
  8533. func_args server_args;
  8534. THREAD_TYPE serverThread;
  8535. callback_functions client_cb;
  8536. callback_functions server_cb;
  8537. method_provider methods[][2] = {
  8538. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8539. !defined(NO_DES3))
  8540. /* Without AES there are almost no ciphersuites available. This leads
  8541. * to no ciphersuites being available and an error. */
  8542. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8543. #endif
  8544. #ifndef WOLFSSL_NO_TLS12
  8545. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8546. #endif
  8547. /* Needs the default ticket callback since it is tied to the
  8548. * connection context and this makes it easy to carry over the ticket
  8549. * crypto context between connections */
  8550. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8551. defined(HAVE_SESSION_TICKET)
  8552. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8553. #endif
  8554. };
  8555. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8556. size_t i, j;
  8557. for (i = 0; i < methodsLen; i++) {
  8558. /* First run creates a connection while the second+ run will attempt
  8559. * to resume the connection. The trick is that the internal cache
  8560. * is turned off. wolfSSL_CTX_add_session should put the session in
  8561. * the cache anyway. */
  8562. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8563. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8564. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8565. #ifdef NO_SESSION_CACHE_REF
  8566. for (j = 0; j < 4; j++) {
  8567. #else
  8568. /* The session may be overwritten in this case. Do only one resumption
  8569. * to stop this test from failing intermittently. */
  8570. for (j = 0; j < 2; j++) {
  8571. #endif
  8572. #ifdef WOLFSSL_TIRTOS
  8573. fdOpenSession(Task_self());
  8574. #endif
  8575. StartTCP();
  8576. InitTcpReady(&ready);
  8577. XMEMSET(&client_args, 0, sizeof(func_args));
  8578. XMEMSET(&server_args, 0, sizeof(func_args));
  8579. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8580. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8581. client_cb.method = methods[i][0];
  8582. server_cb.method = methods[i][1];
  8583. server_args.signal = &ready;
  8584. server_args.callbacks = &server_cb;
  8585. client_args.signal = &ready;
  8586. client_args.callbacks = &client_cb;
  8587. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8588. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8589. server_cb.isSharedCtx = 1;
  8590. }
  8591. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8592. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8593. if (j != 0)
  8594. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8595. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8596. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8597. server_cb.ticNoInit = 1; /* Use default builtin */
  8598. start_thread(test_server_nofail, &server_args, &serverThread);
  8599. wait_tcp_ready(&server_args);
  8600. test_client_nofail(&client_args, NULL);
  8601. join_thread(serverThread);
  8602. ExpectTrue(client_args.return_code);
  8603. ExpectTrue(server_args.return_code);
  8604. FreeTcpReady(&ready);
  8605. if (EXPECT_FAIL())
  8606. break;
  8607. }
  8608. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8609. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8610. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8611. if (EXPECT_FAIL())
  8612. break;
  8613. }
  8614. #endif
  8615. return EXPECT_RESULT();
  8616. }
  8617. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8618. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8619. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8620. defined(HAVE_SESSION_TICKET) && \
  8621. !defined(TITAN_SESSION_CACHE) && \
  8622. !defined(HUGE_SESSION_CACHE) && \
  8623. !defined(BIG_SESSION_CACHE) && \
  8624. !defined(MEDIUM_SESSION_CACHE)
  8625. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8626. /* Sessions to restore/store */
  8627. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8628. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8629. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8630. static int twcase_new_session_called = 0;
  8631. static int twcase_remove_session_called = 0;
  8632. static int twcase_get_session_called = 0;
  8633. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8634. #define SESSION_CACHE_SIZE 33
  8635. typedef struct {
  8636. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8637. WOLFSSL_SESSION* value;
  8638. } hashTable_entry;
  8639. typedef struct {
  8640. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8641. size_t capacity; /* size of entries */
  8642. size_t length; /* number of items in the hash table */
  8643. wolfSSL_Mutex htLock; /* lock */
  8644. }hashTable;
  8645. static hashTable server_sessionCache;
  8646. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8647. {
  8648. int i;
  8649. unsigned int len;
  8650. (void)ssl;
  8651. /*
  8652. * This example uses a hash table.
  8653. * Steps you should take for a non-demo code:
  8654. * - acquire a lock for the file named according to the session id
  8655. * - open the file
  8656. * - encrypt and write the SSL_SESSION object to the file
  8657. * - release the lock
  8658. *
  8659. * Return:
  8660. * 0: The callback does not wish to hold a reference of the sess
  8661. * 1: The callback wants to hold a reference of the sess. The callback is
  8662. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8663. */
  8664. if (sess == NULL)
  8665. return 0;
  8666. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8667. return 0;
  8668. }
  8669. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8670. if (server_sessionCache.entries[i].value == NULL) {
  8671. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8672. server_sessionCache.entries[i].value = sess;
  8673. server_sessionCache.length++;
  8674. break;
  8675. }
  8676. }
  8677. ++twcase_new_session_called;
  8678. wc_UnLockMutex(&server_sessionCache.htLock);
  8679. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8680. twcase_new_session_called);
  8681. return 1;
  8682. }
  8683. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8684. {
  8685. int i;
  8686. (void)ctx;
  8687. (void)sess;
  8688. if (sess == NULL)
  8689. return;
  8690. /*
  8691. * This example uses a hash table.
  8692. * Steps you should take for a non-demo code:
  8693. * - acquire a lock for the file named according to the session id
  8694. * - remove the file
  8695. * - release the lock
  8696. */
  8697. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8698. return;
  8699. }
  8700. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8701. if (server_sessionCache.entries[i].key != NULL &&
  8702. XMEMCMP(server_sessionCache.entries[i].key,
  8703. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8704. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8705. server_sessionCache.entries[i].value = NULL;
  8706. server_sessionCache.entries[i].key = NULL;
  8707. server_sessionCache.length--;
  8708. break;
  8709. }
  8710. }
  8711. ++twcase_remove_session_called;
  8712. wc_UnLockMutex(&server_sessionCache.htLock);
  8713. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8714. twcase_remove_session_called);
  8715. }
  8716. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8717. const unsigned char *id, int len, int *ref)
  8718. {
  8719. int i;
  8720. (void)ssl;
  8721. (void)id;
  8722. (void)len;
  8723. /*
  8724. * This example uses a hash table.
  8725. * Steps you should take for a non-demo code:
  8726. * - acquire a lock for the file named according to the session id in the
  8727. * 2nd arg
  8728. * - read and decrypt contents of file and create a new SSL_SESSION
  8729. * - object release the lock
  8730. * - return the new session object
  8731. */
  8732. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8733. ++twcase_get_session_called);
  8734. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8735. * be responsible for the pointer then set to 0. */
  8736. *ref = 1;
  8737. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8738. if (server_sessionCache.entries[i].key != NULL &&
  8739. XMEMCMP(server_sessionCache.entries[i].key, id,
  8740. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8741. return server_sessionCache.entries[i].value;
  8742. }
  8743. }
  8744. return NULL;
  8745. }
  8746. static int twcase_get_sessionCb_cleanup(void)
  8747. {
  8748. int i;
  8749. int cnt = 0;
  8750. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8751. * for freeing sessions */
  8752. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8753. if (server_sessionCache.entries[i].value != NULL) {
  8754. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8755. cnt++;
  8756. }
  8757. }
  8758. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8759. cnt);
  8760. return TEST_SUCCESS;
  8761. }
  8762. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8763. {
  8764. EXPECT_DECLS;
  8765. /* off - Disable internal cache */
  8766. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8767. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8768. #ifdef OPENSSL_EXTRA
  8769. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8770. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8771. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8772. #endif
  8773. /* off - Do not setup external cache */
  8774. /* Require both peers to provide certs */
  8775. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8776. return EXPECT_RESULT();
  8777. }
  8778. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8779. {
  8780. /* on - internal cache is on by default */
  8781. /* off - Do not setup external cache */
  8782. /* Require both peers to provide certs */
  8783. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8784. return TEST_SUCCESS;
  8785. }
  8786. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8787. {
  8788. EXPECT_DECLS;
  8789. /* off - Disable internal cache */
  8790. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8791. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8792. #ifdef OPENSSL_EXTRA
  8793. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8794. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8795. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8796. #endif
  8797. /* on - Enable external cache */
  8798. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8799. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8800. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8801. /* Require both peers to provide certs */
  8802. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8803. return EXPECT_RESULT();
  8804. }
  8805. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8806. {
  8807. /* on - internal cache is on by default */
  8808. /* on - Enable external cache */
  8809. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8810. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8811. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8812. /* Require both peers to provide certs */
  8813. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8814. return TEST_SUCCESS;
  8815. }
  8816. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8817. {
  8818. /* on - internal cache is on by default */
  8819. /* on - Enable external cache */
  8820. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8821. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8822. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8823. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8824. /* Require both peers to provide certs */
  8825. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8826. return TEST_SUCCESS;
  8827. }
  8828. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8829. {
  8830. EXPECT_DECLS;
  8831. WOLFSSL_SESSION** sess;
  8832. if (wolfSSL_is_server(ssl))
  8833. sess = &twcase_server_first_session_ptr;
  8834. else
  8835. return TEST_SUCCESS;
  8836. if (*sess == NULL) {
  8837. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8838. /* Now save the session in the internal store to make it available
  8839. * for lookup. For TLS 1.3, we can't save the session without
  8840. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8841. * session from cache. */
  8842. if (wolfSSL_is_server(ssl)
  8843. #ifndef WOLFSSL_TICKET_HAVE_ID
  8844. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8845. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8846. #endif
  8847. ) {
  8848. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8849. *sess), WOLFSSL_SUCCESS);
  8850. }
  8851. }
  8852. /* Save CTX to be able to decrypt tickets */
  8853. if (twcase_server_current_ctx_ptr == NULL) {
  8854. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8855. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8856. WOLFSSL_SUCCESS);
  8857. }
  8858. #ifdef SESSION_CERTS
  8859. #ifndef WOLFSSL_TICKET_HAVE_ID
  8860. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8861. wolfSSL_session_reused(ssl))
  8862. #endif
  8863. {
  8864. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8865. * for all connections. TLS 1.3 only has tickets so if we don't
  8866. * include the session id in the ticket then the certificates
  8867. * will not be available on resumption. */
  8868. WOLFSSL_X509* peer = NULL;
  8869. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8870. wolfSSL_X509_free(peer);
  8871. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8872. }
  8873. #endif
  8874. return EXPECT_RESULT();
  8875. }
  8876. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8877. {
  8878. EXPECT_DECLS;
  8879. WOLFSSL_SESSION** sess;
  8880. sess = &twcase_client_first_session_ptr;
  8881. if (*sess == NULL) {
  8882. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8883. }
  8884. else {
  8885. /* If we have a session retrieved then remaining connections should be
  8886. * resuming on that session */
  8887. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8888. }
  8889. #ifdef SESSION_CERTS
  8890. #ifndef WOLFSSL_TICKET_HAVE_ID
  8891. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8892. wolfSSL_session_reused(ssl))
  8893. #endif
  8894. {
  8895. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8896. ExpectNotNull(peer);
  8897. wolfSSL_X509_free(peer);
  8898. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8899. #ifdef OPENSSL_EXTRA
  8900. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8901. #endif
  8902. }
  8903. #endif
  8904. return EXPECT_RESULT();
  8905. }
  8906. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8907. {
  8908. EXPECT_DECLS;
  8909. /* Set the session to reuse for the client */
  8910. ExpectNotNull(ssl);
  8911. ExpectNotNull(twcase_client_first_session_ptr);
  8912. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8913. WOLFSSL_SUCCESS);
  8914. return EXPECT_RESULT();
  8915. }
  8916. struct test_add_session_ext_params {
  8917. method_provider client_meth;
  8918. method_provider server_meth;
  8919. const char* tls_version;
  8920. };
  8921. static int test_wolfSSL_CTX_add_session_ext(
  8922. struct test_add_session_ext_params* param)
  8923. {
  8924. EXPECT_DECLS;
  8925. /* Test the default 33 sessions */
  8926. int j;
  8927. /* Clear cache before starting */
  8928. wolfSSL_CTX_flush_sessions(NULL, -1);
  8929. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8930. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8931. return BAD_MUTEX_E;
  8932. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8933. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8934. for (j = 0; j < 5; j++) {
  8935. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8936. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8937. test_ssl_cbf client_cb;
  8938. test_ssl_cbf server_cb;
  8939. (void)dtls;
  8940. /* Test five cache configurations */
  8941. twcase_client_first_session_ptr = NULL;
  8942. twcase_server_first_session_ptr = NULL;
  8943. twcase_server_current_ctx_ptr = NULL;
  8944. twcase_new_session_called = 0;
  8945. twcase_remove_session_called = 0;
  8946. twcase_get_session_called = 0;
  8947. /* connection 1 - first connection */
  8948. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8949. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8950. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8951. client_cb.method = param->client_meth;
  8952. server_cb.method = param->server_meth;
  8953. if (dtls)
  8954. client_cb.doUdp = server_cb.doUdp = 1;
  8955. /* Setup internal and external cache */
  8956. switch (j) {
  8957. case 0:
  8958. /* SSL_OP_NO_TICKET stateful ticket case */
  8959. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8960. break;
  8961. case 1:
  8962. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8963. break;
  8964. case 2:
  8965. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8966. break;
  8967. case 3:
  8968. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8969. break;
  8970. case 4:
  8971. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8972. break;
  8973. }
  8974. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8975. /* Add session to internal cache and save SSL session for testing */
  8976. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8977. /* Save client SSL session for testing */
  8978. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8979. server_cb.ticNoInit = 1; /* Use default builtin */
  8980. /* Don't free/release ctx */
  8981. server_cb.ctx = twcase_server_current_ctx_ptr;
  8982. server_cb.isSharedCtx = 1;
  8983. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8984. &server_cb, NULL), TEST_SUCCESS);
  8985. ExpectIntEQ(twcase_get_session_called, 0);
  8986. if (EXPECT_FAIL()) {
  8987. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8988. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8989. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8990. break;
  8991. }
  8992. switch (j) {
  8993. case 0:
  8994. case 1:
  8995. case 2:
  8996. /* cache cannot be searched with out a connection */
  8997. /* Add a new session */
  8998. ExpectIntEQ(twcase_new_session_called, 1);
  8999. /* In twcase_server_sess_ctx_pre_shutdown
  9000. * wolfSSL_CTX_add_session which evicts the existing session
  9001. * in cache and adds it back in */
  9002. ExpectIntLE(twcase_remove_session_called, 1);
  9003. break;
  9004. case 3:
  9005. case 4:
  9006. /* no external cache */
  9007. ExpectIntEQ(twcase_new_session_called, 0);
  9008. ExpectIntEQ(twcase_remove_session_called, 0);
  9009. break;
  9010. }
  9011. /* connection 2 - session resume */
  9012. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  9013. twcase_new_session_called = 0;
  9014. twcase_remove_session_called = 0;
  9015. twcase_get_session_called = 0;
  9016. server_cb.on_result = 0;
  9017. client_cb.on_result = 0;
  9018. server_cb.ticNoInit = 1; /* Use default builtin */
  9019. server_cb.ctx = twcase_server_current_ctx_ptr;
  9020. /* try session resumption */
  9021. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  9022. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  9023. &server_cb, NULL), TEST_SUCCESS);
  9024. /* Clear cache before checking */
  9025. wolfSSL_CTX_flush_sessions(NULL, -1);
  9026. switch (j) {
  9027. case 0:
  9028. if (tls13) {
  9029. /* (D)TLSv1.3 stateful case */
  9030. /* cache hit */
  9031. /* DTLS accesses cache once for stateless parsing and
  9032. * once for stateful parsing */
  9033. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9034. /* (D)TLSv1.3 creates a new ticket,
  9035. * updates both internal and external cache */
  9036. ExpectIntEQ(twcase_new_session_called, 1);
  9037. /* A new session ID is created for a new ticket */
  9038. ExpectIntEQ(twcase_remove_session_called, 2);
  9039. }
  9040. else {
  9041. /* non (D)TLSv1.3 case, no update */
  9042. /* DTLS accesses cache once for stateless parsing and
  9043. * once for stateful parsing */
  9044. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9045. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9046. #else
  9047. ExpectIntEQ(twcase_get_session_called, 1);
  9048. #endif
  9049. ExpectIntEQ(twcase_new_session_called, 0);
  9050. /* Called on session added in
  9051. * twcase_server_sess_ctx_pre_shutdown */
  9052. ExpectIntEQ(twcase_remove_session_called, 1);
  9053. }
  9054. break;
  9055. case 1:
  9056. if (tls13) {
  9057. /* (D)TLSv1.3 case */
  9058. /* cache hit */
  9059. ExpectIntEQ(twcase_get_session_called, 1);
  9060. /* (D)TLSv1.3 creates a new ticket,
  9061. * updates both internal and external cache */
  9062. ExpectIntEQ(twcase_new_session_called, 1);
  9063. /* Called on session added in
  9064. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9065. ExpectIntEQ(twcase_remove_session_called, 1);
  9066. }
  9067. else {
  9068. /* non (D)TLSv1.3 case */
  9069. /* cache hit */
  9070. /* DTLS accesses cache once for stateless parsing and
  9071. * once for stateful parsing */
  9072. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9073. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9074. #else
  9075. ExpectIntEQ(twcase_get_session_called, 1);
  9076. #endif
  9077. ExpectIntEQ(twcase_new_session_called, 0);
  9078. /* Called on session added in
  9079. * twcase_server_sess_ctx_pre_shutdown */
  9080. ExpectIntEQ(twcase_remove_session_called, 1);
  9081. }
  9082. break;
  9083. case 2:
  9084. if (tls13) {
  9085. /* (D)TLSv1.3 case */
  9086. /* cache hit */
  9087. ExpectIntEQ(twcase_get_session_called, 1);
  9088. /* (D)TLSv1.3 creates a new ticket,
  9089. * updates both internal and external cache */
  9090. ExpectIntEQ(twcase_new_session_called, 1);
  9091. /* Called on session added in
  9092. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9093. ExpectIntEQ(twcase_remove_session_called, 1);
  9094. }
  9095. else {
  9096. /* non (D)TLSv1.3 case */
  9097. /* cache hit */
  9098. /* DTLS accesses cache once for stateless parsing and
  9099. * once for stateful parsing */
  9100. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9101. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9102. #else
  9103. ExpectIntEQ(twcase_get_session_called, 1);
  9104. #endif
  9105. ExpectIntEQ(twcase_new_session_called, 0);
  9106. /* Called on session added in
  9107. * twcase_server_sess_ctx_pre_shutdown */
  9108. ExpectIntEQ(twcase_remove_session_called, 1);
  9109. }
  9110. break;
  9111. case 3:
  9112. case 4:
  9113. /* no external cache */
  9114. ExpectIntEQ(twcase_get_session_called, 0);
  9115. ExpectIntEQ(twcase_new_session_called, 0);
  9116. ExpectIntEQ(twcase_remove_session_called, 0);
  9117. break;
  9118. }
  9119. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  9120. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  9121. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  9122. if (EXPECT_FAIL())
  9123. break;
  9124. }
  9125. twcase_get_sessionCb_cleanup();
  9126. XMEMSET(&server_sessionCache.entries, 0,
  9127. sizeof(server_sessionCache.entries));
  9128. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  9129. wc_FreeMutex(&server_sessionCache.htLock);
  9130. return EXPECT_RESULT();
  9131. }
  9132. #endif
  9133. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  9134. {
  9135. EXPECT_DECLS;
  9136. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9137. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9138. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9139. defined(HAVE_SESSION_TICKET) && \
  9140. !defined(TITAN_SESSION_CACHE) && \
  9141. !defined(HUGE_SESSION_CACHE) && \
  9142. !defined(BIG_SESSION_CACHE) && \
  9143. !defined(MEDIUM_SESSION_CACHE)
  9144. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9145. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9146. struct test_add_session_ext_params param[1] = {
  9147. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  9148. };
  9149. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9150. #endif
  9151. #endif
  9152. return EXPECT_RESULT();
  9153. }
  9154. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  9155. {
  9156. EXPECT_DECLS;
  9157. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9158. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9159. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9160. defined(HAVE_SESSION_TICKET) && \
  9161. !defined(TITAN_SESSION_CACHE) && \
  9162. !defined(HUGE_SESSION_CACHE) && \
  9163. !defined(BIG_SESSION_CACHE) && \
  9164. !defined(MEDIUM_SESSION_CACHE)
  9165. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9166. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9167. #ifdef WOLFSSL_DTLS13
  9168. struct test_add_session_ext_params param[1] = {
  9169. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  9170. };
  9171. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9172. #endif
  9173. #endif
  9174. #endif
  9175. return EXPECT_RESULT();
  9176. }
  9177. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  9178. {
  9179. EXPECT_DECLS;
  9180. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9181. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9182. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9183. defined(HAVE_SESSION_TICKET) && \
  9184. !defined(TITAN_SESSION_CACHE) && \
  9185. !defined(HUGE_SESSION_CACHE) && \
  9186. !defined(BIG_SESSION_CACHE) && \
  9187. !defined(MEDIUM_SESSION_CACHE)
  9188. #ifndef WOLFSSL_NO_TLS12
  9189. struct test_add_session_ext_params param[1] = {
  9190. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  9191. };
  9192. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9193. #endif
  9194. #endif
  9195. return EXPECT_RESULT();
  9196. }
  9197. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  9198. {
  9199. EXPECT_DECLS;
  9200. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9201. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9202. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9203. defined(HAVE_SESSION_TICKET) && \
  9204. !defined(TITAN_SESSION_CACHE) && \
  9205. !defined(HUGE_SESSION_CACHE) && \
  9206. !defined(BIG_SESSION_CACHE) && \
  9207. !defined(MEDIUM_SESSION_CACHE)
  9208. #ifndef WOLFSSL_NO_TLS12
  9209. #ifdef WOLFSSL_DTLS
  9210. struct test_add_session_ext_params param[1] = {
  9211. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  9212. };
  9213. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9214. #endif
  9215. #endif
  9216. #endif
  9217. return EXPECT_RESULT();
  9218. }
  9219. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  9220. {
  9221. EXPECT_DECLS;
  9222. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9223. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9224. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9225. defined(HAVE_SESSION_TICKET) && \
  9226. !defined(TITAN_SESSION_CACHE) && \
  9227. !defined(HUGE_SESSION_CACHE) && \
  9228. !defined(BIG_SESSION_CACHE) && \
  9229. !defined(MEDIUM_SESSION_CACHE)
  9230. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9231. !defined(NO_DES3))
  9232. struct test_add_session_ext_params param[1] = {
  9233. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9234. };
  9235. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9236. #endif
  9237. #endif
  9238. return EXPECT_RESULT();
  9239. }
  9240. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9241. {
  9242. EXPECT_DECLS;
  9243. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9244. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9245. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9246. defined(HAVE_SESSION_TICKET) && \
  9247. !defined(TITAN_SESSION_CACHE) && \
  9248. !defined(HUGE_SESSION_CACHE) && \
  9249. !defined(BIG_SESSION_CACHE) && \
  9250. !defined(MEDIUM_SESSION_CACHE)
  9251. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9252. !defined(NO_DES3))
  9253. #ifdef WOLFSSL_DTLS
  9254. struct test_add_session_ext_params param[1] = {
  9255. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9256. };
  9257. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9258. #endif
  9259. #endif
  9260. #endif
  9261. return EXPECT_RESULT();
  9262. }
  9263. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9264. /* canned export of a session using older version 3 */
  9265. static unsigned char version_3[] = {
  9266. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9267. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9268. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9269. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9270. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9271. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9272. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9273. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9274. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9275. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9277. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9278. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9279. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9280. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9281. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9282. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9283. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9284. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9285. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9286. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9287. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9288. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9289. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9296. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9297. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05,
  9298. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9299. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9300. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9301. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9302. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9303. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9304. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9305. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9306. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9307. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9308. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9309. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9310. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9311. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9312. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9313. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9314. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9315. 0x2E, 0x31, 0xED, 0x4F
  9316. };
  9317. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9318. static int test_wolfSSL_dtls_export(void)
  9319. {
  9320. EXPECT_DECLS;
  9321. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9322. tcp_ready ready;
  9323. func_args client_args;
  9324. func_args server_args;
  9325. THREAD_TYPE serverThread;
  9326. callback_functions server_cbf;
  9327. callback_functions client_cbf;
  9328. #ifdef WOLFSSL_TIRTOS
  9329. fdOpenSession(Task_self());
  9330. #endif
  9331. InitTcpReady(&ready);
  9332. #if defined(USE_WINDOWS_API)
  9333. /* use RNG to get random port if using windows */
  9334. ready.port = GetRandomPort();
  9335. #endif
  9336. /* set using dtls */
  9337. XMEMSET(&client_args, 0, sizeof(func_args));
  9338. XMEMSET(&server_args, 0, sizeof(func_args));
  9339. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9340. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9341. server_cbf.method = wolfDTLSv1_2_server_method;
  9342. client_cbf.method = wolfDTLSv1_2_client_method;
  9343. server_args.callbacks = &server_cbf;
  9344. client_args.callbacks = &client_cbf;
  9345. server_args.signal = &ready;
  9346. client_args.signal = &ready;
  9347. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9348. wait_tcp_ready(&server_args);
  9349. run_wolfssl_client(&client_args);
  9350. join_thread(serverThread);
  9351. ExpectTrue(client_args.return_code);
  9352. ExpectTrue(server_args.return_code);
  9353. FreeTcpReady(&ready);
  9354. #ifdef WOLFSSL_TIRTOS
  9355. fdOpenSession(Task_self());
  9356. #endif
  9357. if (EXPECT_SUCCESS()) {
  9358. SOCKET_T sockfd = 0;
  9359. WOLFSSL_CTX* ctx = NULL;
  9360. WOLFSSL* ssl = NULL;
  9361. char msg[64] = "hello wolfssl!";
  9362. char reply[1024];
  9363. int msgSz = (int)XSTRLEN(msg);
  9364. byte *session, *window;
  9365. unsigned int sessionSz = 0;
  9366. unsigned int windowSz = 0;
  9367. #ifndef TEST_IPV6
  9368. struct sockaddr_in peerAddr;
  9369. #else
  9370. struct sockaddr_in6 peerAddr;
  9371. #endif /* TEST_IPV6 */
  9372. int i;
  9373. /* Set ctx to DTLS 1.2 */
  9374. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9375. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9376. /* test importing version 3 */
  9377. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9378. /* test importing bad length and bad version */
  9379. version_3[2] += 1;
  9380. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9381. version_3[2] -= 1; version_3[1] = 0XA0;
  9382. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9383. wolfSSL_free(ssl);
  9384. wolfSSL_CTX_free(ctx);
  9385. /* check storing client state after connection and storing window only */
  9386. #ifdef WOLFSSL_TIRTOS
  9387. fdOpenSession(Task_self());
  9388. #endif
  9389. InitTcpReady(&ready);
  9390. #if defined(USE_WINDOWS_API)
  9391. /* use RNG to get random port if using windows */
  9392. ready.port = GetRandomPort();
  9393. #endif
  9394. /* set using dtls */
  9395. XMEMSET(&server_args, 0, sizeof(func_args));
  9396. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9397. server_cbf.method = wolfDTLSv1_2_server_method;
  9398. server_cbf.doUdp = 1;
  9399. server_args.callbacks = &server_cbf;
  9400. server_args.argc = 3; /* set loop_count to 3 */
  9401. server_args.signal = &ready;
  9402. start_thread(test_server_nofail, &server_args, &serverThread);
  9403. wait_tcp_ready(&server_args);
  9404. /* create and connect with client */
  9405. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9406. ExpectIntEQ(WOLFSSL_SUCCESS,
  9407. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9408. ExpectIntEQ(WOLFSSL_SUCCESS,
  9409. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9410. ExpectIntEQ(WOLFSSL_SUCCESS,
  9411. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9412. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9413. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9414. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9415. /* store server information connected too */
  9416. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9417. #ifndef TEST_IPV6
  9418. peerAddr.sin_family = AF_INET;
  9419. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9420. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9421. #else
  9422. peerAddr.sin6_family = AF_INET6;
  9423. ExpectIntEQ(
  9424. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9425. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9426. #endif
  9427. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9428. WOLFSSL_SUCCESS);
  9429. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9430. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9431. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9432. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9433. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9434. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9435. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9436. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9437. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9438. wolfSSL_free(ssl);
  9439. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9440. /* restore state */
  9441. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9442. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9443. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9444. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9445. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9446. WOLFSSL_SUCCESS);
  9447. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9448. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9449. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9450. wolfSSL_free(ssl);
  9451. }
  9452. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9453. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9454. wolfSSL_CTX_free(ctx);
  9455. fprintf(stderr, "done and waiting for server\n");
  9456. join_thread(serverThread);
  9457. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9458. FreeTcpReady(&ready);
  9459. #ifdef WOLFSSL_TIRTOS
  9460. fdOpenSession(Task_self());
  9461. #endif
  9462. }
  9463. #endif
  9464. return EXPECT_RESULT();
  9465. }
  9466. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9467. #ifdef WOLFSSL_TLS13
  9468. static const byte canned_client_tls13_session[] = {
  9469. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9470. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9471. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9472. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9473. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9474. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9475. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9476. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9477. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9478. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9479. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9480. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9481. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9482. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9483. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9484. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9485. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9486. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9487. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9488. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9489. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9490. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9491. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9492. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9493. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9494. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9495. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9496. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9497. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9498. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9499. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9500. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9501. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9502. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9503. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9504. 0x00, 0x03
  9505. };
  9506. static const byte canned_server_tls13_session[] = {
  9507. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9508. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9509. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9510. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9511. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9512. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9513. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9514. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9515. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9516. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9517. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9518. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9519. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9520. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9521. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9522. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9523. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9524. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9525. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9526. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9527. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9528. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9529. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9530. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9531. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9532. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9533. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9534. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9535. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9536. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9537. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9538. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9539. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9540. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9541. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9542. 0x00, 0x04
  9543. };
  9544. #endif /* WOLFSSL_TLS13 */
  9545. static const byte canned_client_session[] = {
  9546. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9547. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9548. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9549. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9550. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9551. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9552. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9553. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9554. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9555. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9556. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9557. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9558. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9559. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9560. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9561. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9562. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9563. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9564. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9565. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9566. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9567. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9568. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9569. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9570. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9571. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9572. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9573. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9574. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9575. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9576. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9577. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9578. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9579. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9580. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9581. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9582. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9583. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9584. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9585. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9586. 0x00, 0x03
  9587. };
  9588. static const byte canned_server_session[] = {
  9589. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9590. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9591. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9592. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9593. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9594. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9595. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9596. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9597. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9598. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9599. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9600. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9601. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9602. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9603. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9604. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9605. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9606. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9607. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9608. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9609. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9610. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9611. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9612. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9613. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9614. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9615. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9616. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9617. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9618. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9619. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9620. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9621. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9622. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9623. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9624. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9625. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9626. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9627. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9628. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9629. 0x00, 0x04
  9630. };
  9631. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9632. {
  9633. SOCKET_T sockfd = 0;
  9634. SOCKET_T clientfd = 0;
  9635. word16 port;
  9636. callback_functions* cbf;
  9637. WOLFSSL_CTX* ctx = 0;
  9638. WOLFSSL* ssl = 0;
  9639. char msg[] = "I hear you fa shizzle!";
  9640. char input[1024];
  9641. int idx;
  9642. #ifdef WOLFSSL_TIRTOS
  9643. fdOpenSession(Task_self());
  9644. #endif
  9645. ((func_args*)args)->return_code = TEST_FAIL;
  9646. cbf = ((func_args*)args)->callbacks;
  9647. #if defined(USE_WINDOWS_API)
  9648. port = ((func_args*)args)->signal->port;
  9649. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9650. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9651. /* Let tcp_listen assign port */
  9652. port = 0;
  9653. #else
  9654. /* Use default port */
  9655. port = wolfSSLPort;
  9656. #endif
  9657. /* do it here to detect failure */
  9658. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9659. CloseSocket(sockfd);
  9660. {
  9661. WOLFSSL_METHOD* method = NULL;
  9662. if (cbf != NULL && cbf->method != NULL) {
  9663. method = cbf->method();
  9664. }
  9665. else {
  9666. method = wolfTLSv1_2_server_method();
  9667. }
  9668. ctx = wolfSSL_CTX_new(method);
  9669. }
  9670. if (ctx == NULL) {
  9671. goto done;
  9672. }
  9673. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9674. /* call ctx setup callback */
  9675. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9676. cbf->ctx_ready(ctx);
  9677. }
  9678. ssl = wolfSSL_new(ctx);
  9679. if (ssl == NULL) {
  9680. goto done;
  9681. }
  9682. wolfSSL_set_fd(ssl, clientfd);
  9683. /* call ssl setup callback */
  9684. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9685. cbf->ssl_ready(ssl);
  9686. }
  9687. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9688. if (idx > 0) {
  9689. input[idx] = '\0';
  9690. fprintf(stderr, "Client message export/import: %s\n", input);
  9691. }
  9692. else {
  9693. fprintf(stderr, "ret = %d error = %d\n", idx,
  9694. wolfSSL_get_error(ssl, idx));
  9695. goto done;
  9696. }
  9697. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9698. /*err_sys("SSL_write failed");*/
  9699. WOLFSSL_RETURN_FROM_THREAD(0);
  9700. }
  9701. #ifdef WOLFSSL_TIRTOS
  9702. Task_yield();
  9703. #endif
  9704. ((func_args*)args)->return_code = TEST_SUCCESS;
  9705. done:
  9706. wolfSSL_shutdown(ssl);
  9707. wolfSSL_free(ssl);
  9708. wolfSSL_CTX_free(ctx);
  9709. CloseSocket(clientfd);
  9710. #ifdef WOLFSSL_TIRTOS
  9711. fdCloseSession(Task_self());
  9712. #endif
  9713. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9714. && defined(HAVE_THREAD_LS)
  9715. wc_ecc_fp_free(); /* free per thread cache */
  9716. #endif
  9717. #if defined(HAVE_SESSION_TICKET) && \
  9718. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9719. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9720. OpenSSLTicketCleanup();
  9721. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9722. TicketCleanup();
  9723. #endif
  9724. #endif
  9725. WOLFSSL_RETURN_FROM_THREAD(0);
  9726. }
  9727. static void load_tls12_canned_server(WOLFSSL* ssl)
  9728. {
  9729. int clientfd = wolfSSL_get_fd(ssl);
  9730. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9731. sizeof(canned_server_session)), sizeof(canned_server_session));
  9732. wolfSSL_set_fd(ssl, clientfd);
  9733. }
  9734. #ifdef WOLFSSL_TLS13
  9735. static void load_tls13_canned_server(WOLFSSL* ssl)
  9736. {
  9737. int clientfd = wolfSSL_get_fd(ssl);
  9738. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9739. sizeof(canned_server_tls13_session)),
  9740. sizeof(canned_server_tls13_session));
  9741. wolfSSL_set_fd(ssl, clientfd);
  9742. }
  9743. #endif
  9744. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9745. static int test_wolfSSL_tls_export_run(int v)
  9746. {
  9747. EXPECT_DECLS;
  9748. SOCKET_T sockfd = 0;
  9749. WOLFSSL_CTX* ctx = 0;
  9750. WOLFSSL* ssl = 0;
  9751. char msg[64] = "hello wolfssl!";
  9752. char reply[1024];
  9753. word32 replySz;
  9754. int msgSz = (int)XSTRLEN(msg);
  9755. const byte* clientSession = NULL;
  9756. int clientSessionSz = 0;
  9757. tcp_ready ready;
  9758. func_args server_args;
  9759. THREAD_TYPE serverThread;
  9760. callback_functions server_cbf;
  9761. #ifdef WOLFSSL_TIRTOS
  9762. fdOpenSession(Task_self());
  9763. #endif
  9764. InitTcpReady(&ready);
  9765. #if defined(USE_WINDOWS_API)
  9766. /* use RNG to get random port if using windows */
  9767. ready.port = GetRandomPort();
  9768. #endif
  9769. XMEMSET(&server_args, 0, sizeof(func_args));
  9770. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9771. switch (v) {
  9772. case WOLFSSL_TLSV1_2:
  9773. server_cbf.method = wolfTLSv1_2_server_method;
  9774. server_cbf.ssl_ready = load_tls12_canned_server;
  9775. /* setup the client side */
  9776. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9777. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9778. clientSession = canned_client_session;
  9779. clientSessionSz = sizeof(canned_client_session);
  9780. break;
  9781. #ifdef WOLFSSL_TLS13
  9782. case WOLFSSL_TLSV1_3:
  9783. server_cbf.method = wolfTLSv1_3_server_method;
  9784. server_cbf.ssl_ready = load_tls13_canned_server;
  9785. /* setup the client side */
  9786. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9787. clientSession = canned_client_tls13_session;
  9788. clientSessionSz = sizeof(canned_client_tls13_session);
  9789. break;
  9790. #endif
  9791. }
  9792. server_args.callbacks = &server_cbf;
  9793. server_args.signal = &ready;
  9794. start_thread(tls_export_server, &server_args, &serverThread);
  9795. wait_tcp_ready(&server_args);
  9796. #ifdef WOLFSSL_TIRTOS
  9797. fdOpenSession(Task_self());
  9798. #endif
  9799. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9800. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9801. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9802. clientSessionSz);
  9803. replySz = sizeof(reply);
  9804. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9805. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9806. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9807. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9808. #endif
  9809. wolfSSL_set_fd(ssl, sockfd);
  9810. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9811. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9812. wolfSSL_free(ssl);
  9813. wolfSSL_CTX_free(ctx);
  9814. CloseSocket(sockfd);
  9815. #ifdef WOLFSSL_TIRTOS
  9816. fdCloseSession(Task_self());
  9817. #endif
  9818. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9819. && defined(HAVE_THREAD_LS)
  9820. wc_ecc_fp_free(); /* free per thread cache */
  9821. #endif
  9822. join_thread(serverThread);
  9823. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9824. FreeTcpReady(&ready);
  9825. #ifdef WOLFSSL_TIRTOS
  9826. fdOpenSession(Task_self());
  9827. #endif
  9828. return EXPECT_RESULT();
  9829. }
  9830. #endif
  9831. static int test_wolfSSL_tls_export(void)
  9832. {
  9833. int res = TEST_SKIPPED;
  9834. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9835. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9836. #ifdef WOLFSSL_TLS13
  9837. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9838. #endif
  9839. res = TEST_RES_CHECK(1);
  9840. #endif
  9841. return res;
  9842. }
  9843. /*----------------------------------------------------------------------------*
  9844. | TLS extensions tests
  9845. *----------------------------------------------------------------------------*/
  9846. #ifdef ENABLE_TLS_CALLBACK_TEST
  9847. /* Connection test runner - generic */
  9848. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9849. callback_functions* server_callbacks)
  9850. {
  9851. tcp_ready ready;
  9852. func_args client_args;
  9853. func_args server_args;
  9854. THREAD_TYPE serverThread;
  9855. XMEMSET(&client_args, 0, sizeof(func_args));
  9856. XMEMSET(&server_args, 0, sizeof(func_args));
  9857. StartTCP();
  9858. client_args.callbacks = client_callbacks;
  9859. server_args.callbacks = server_callbacks;
  9860. #ifdef WOLFSSL_TIRTOS
  9861. fdOpenSession(Task_self());
  9862. #endif
  9863. /* RUN Server side */
  9864. InitTcpReady(&ready);
  9865. #if defined(USE_WINDOWS_API)
  9866. /* use RNG to get random port if using windows */
  9867. ready.port = GetRandomPort();
  9868. #endif
  9869. server_args.signal = &ready;
  9870. client_args.signal = &ready;
  9871. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9872. wait_tcp_ready(&server_args);
  9873. /* RUN Client side */
  9874. run_wolfssl_client(&client_args);
  9875. join_thread(serverThread);
  9876. FreeTcpReady(&ready);
  9877. #ifdef WOLFSSL_TIRTOS
  9878. fdCloseSession(Task_self());
  9879. #endif
  9880. client_callbacks->return_code = client_args.return_code;
  9881. server_callbacks->return_code = server_args.return_code;
  9882. }
  9883. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9884. #ifdef HAVE_SNI
  9885. static int test_wolfSSL_UseSNI_params(void)
  9886. {
  9887. EXPECT_DECLS;
  9888. #if !defined(NO_WOLFSSL_CLIENT)
  9889. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9890. WOLFSSL *ssl = wolfSSL_new(ctx);
  9891. ExpectNotNull(ctx);
  9892. ExpectNotNull(ssl);
  9893. /* invalid [ctx|ssl] */
  9894. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9895. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9896. /* invalid type */
  9897. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, -1, "ctx", 3));
  9898. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, -1, "ssl", 3));
  9899. /* invalid data */
  9900. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9901. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9902. /* success case */
  9903. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9904. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9905. wolfSSL_free(ssl);
  9906. wolfSSL_CTX_free(ctx);
  9907. #endif /* !NO_WOLFSSL_CLIENT */
  9908. return EXPECT_RESULT();
  9909. }
  9910. /* BEGIN of connection tests callbacks */
  9911. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9912. {
  9913. AssertIntEQ(WOLFSSL_SUCCESS,
  9914. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9915. }
  9916. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9917. {
  9918. AssertIntEQ(WOLFSSL_SUCCESS,
  9919. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9920. }
  9921. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9922. {
  9923. AssertIntEQ(WOLFSSL_SUCCESS,
  9924. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9925. }
  9926. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9927. {
  9928. use_SNI_at_ssl(ssl);
  9929. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9930. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9931. }
  9932. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9933. {
  9934. use_SNI_at_ssl(ssl);
  9935. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9936. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9937. }
  9938. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9939. {
  9940. use_SNI_at_ctx(ctx);
  9941. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9942. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9943. }
  9944. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9945. {
  9946. use_SNI_at_ssl(ssl);
  9947. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9948. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9949. }
  9950. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9951. {
  9952. use_SNI_at_ctx(ctx);
  9953. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9954. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9955. }
  9956. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9957. {
  9958. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9959. wolfSSL_get_error(ssl, 0));
  9960. }
  9961. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9962. {
  9963. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9964. }
  9965. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9966. {
  9967. byte type = WOLFSSL_SNI_HOST_NAME;
  9968. void* request = (void*) &type; /* to be overwritten */
  9969. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9970. AssertNotNull(request);
  9971. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9972. AssertNull(request);
  9973. }
  9974. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9975. {
  9976. byte type = WOLFSSL_SNI_HOST_NAME;
  9977. void* request = NULL;
  9978. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9979. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9980. AssertNotNull(request);
  9981. AssertStrEQ("www.wolfssl.com", (char*)request);
  9982. }
  9983. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9984. {
  9985. byte type = WOLFSSL_SNI_HOST_NAME;
  9986. void* request = NULL;
  9987. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9988. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9989. AssertNotNull(request);
  9990. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9991. }
  9992. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9993. {
  9994. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9995. }
  9996. /* END of connection tests callbacks */
  9997. static int test_wolfSSL_UseSNI_connection(void)
  9998. {
  9999. int res = TEST_SKIPPED;
  10000. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10001. callback_functions client_cb;
  10002. callback_functions server_cb;
  10003. size_t i;
  10004. #ifdef WOLFSSL_STATIC_MEMORY
  10005. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  10006. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  10007. #endif
  10008. struct {
  10009. method_provider client_meth;
  10010. method_provider server_meth;
  10011. #ifdef WOLFSSL_STATIC_MEMORY
  10012. wolfSSL_method_func client_meth_ex;
  10013. wolfSSL_method_func server_meth_ex;
  10014. #endif
  10015. } methods[] = {
  10016. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  10017. {wolfSSLv23_client_method, wolfSSLv23_server_method
  10018. #ifdef WOLFSSL_STATIC_MEMORY
  10019. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  10020. #endif
  10021. },
  10022. #endif
  10023. #ifndef WOLFSSL_NO_TLS12
  10024. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  10025. #ifdef WOLFSSL_STATIC_MEMORY
  10026. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  10027. #endif
  10028. },
  10029. #endif
  10030. #ifdef WOLFSSL_TLS13
  10031. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  10032. #ifdef WOLFSSL_STATIC_MEMORY
  10033. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  10034. #endif
  10035. },
  10036. #endif
  10037. };
  10038. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  10039. for (i = 0; i < methodsSz; i++) {
  10040. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10041. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10042. client_cb.method = methods[i].client_meth;
  10043. server_cb.method = methods[i].server_meth;
  10044. client_cb.devId = testDevId;
  10045. server_cb.devId = testDevId;
  10046. #ifdef WOLFSSL_STATIC_MEMORY
  10047. client_cb.method_ex = methods[i].client_meth_ex;
  10048. server_cb.method_ex = methods[i].server_meth_ex;
  10049. client_cb.mem = cliMem;
  10050. client_cb.memSz = (word32)sizeof(cliMem);
  10051. server_cb.mem = svrMem;
  10052. server_cb.memSz = (word32)sizeof(svrMem);;
  10053. #endif
  10054. /* success case at ctx */
  10055. fprintf(stderr, "\n\tsuccess case at ctx\n");
  10056. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10057. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10058. test_wolfSSL_client_server(&client_cb, &server_cb);
  10059. /* success case at ssl */
  10060. fprintf(stderr, "\tsuccess case at ssl\n");
  10061. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  10062. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  10063. test_wolfSSL_client_server(&client_cb, &server_cb);
  10064. /* default mismatch behavior */
  10065. fprintf(stderr, "\tdefault mismatch behavior\n");
  10066. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10067. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  10068. test_wolfSSL_client_server(&client_cb, &server_cb);
  10069. /* continue on mismatch */
  10070. fprintf(stderr, "\tcontinue on mismatch\n");
  10071. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10072. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10073. test_wolfSSL_client_server(&client_cb, &server_cb);
  10074. /* fake answer on mismatch */
  10075. fprintf(stderr, "\tfake answer on mismatch\n");
  10076. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10077. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  10078. test_wolfSSL_client_server(&client_cb, &server_cb);
  10079. /* sni abort - success */
  10080. fprintf(stderr, "\tsni abort - success\n");
  10081. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10082. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10083. test_wolfSSL_client_server(&client_cb, &server_cb);
  10084. /* sni abort - abort when absent (ctx) */
  10085. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  10086. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10087. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10088. test_wolfSSL_client_server(&client_cb, &server_cb);
  10089. /* sni abort - abort when absent (ssl) */
  10090. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  10091. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10092. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10093. test_wolfSSL_client_server(&client_cb, &server_cb);
  10094. /* sni abort - success when overwritten */
  10095. fprintf(stderr, "\tsni abort - success when overwritten\n");
  10096. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10097. 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;
  10098. test_wolfSSL_client_server(&client_cb, &server_cb);
  10099. /* sni abort - success when allowing mismatches */
  10100. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  10101. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10102. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  10103. test_wolfSSL_client_server(&client_cb, &server_cb);
  10104. }
  10105. res = TEST_RES_CHECK(1);
  10106. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10107. return res;
  10108. }
  10109. static int test_wolfSSL_SNI_GetFromBuffer(void)
  10110. {
  10111. EXPECT_DECLS;
  10112. byte buff[] = { /* www.paypal.com */
  10113. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  10114. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  10115. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  10116. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10117. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10118. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  10119. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  10120. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  10121. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10122. };
  10123. byte buff2[] = { /* api.textmate.org */
  10124. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  10125. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  10126. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  10127. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  10128. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  10129. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  10130. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  10131. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  10132. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  10133. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  10134. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  10135. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  10136. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  10137. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  10138. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  10139. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  10140. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  10141. };
  10142. byte buff3[] = { /* no sni extension */
  10143. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  10144. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  10145. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  10146. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10147. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10148. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  10149. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10150. };
  10151. byte buff4[] = { /* last extension has zero size */
  10152. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  10153. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10154. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10155. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10156. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  10157. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  10158. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  10159. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  10160. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  10161. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  10162. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  10163. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  10164. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  10165. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  10166. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  10167. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  10168. 0x12, 0x00, 0x00
  10169. };
  10170. byte buff5[] = { /* SSL v2.0 client hello */
  10171. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  10172. /* dummy bytes below, just to pass size check */
  10173. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10174. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10175. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10176. };
  10177. byte result[32] = {0};
  10178. word32 length = 32;
  10179. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  10180. 0, result, &length));
  10181. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  10182. 0, result, &length));
  10183. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10184. 1, result, &length));
  10185. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10186. 0, result, &length));
  10187. buff[0] = 0x16;
  10188. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10189. 0, result, &length));
  10190. buff[1] = 0x03;
  10191. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  10192. sizeof(buff), 0, result, &length));
  10193. buff[2] = 0x03;
  10194. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  10195. sizeof(buff), 0, result, &length));
  10196. buff[4] = 0x64;
  10197. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10198. 0, result, &length));
  10199. if (EXPECT_SUCCESS())
  10200. result[length] = 0;
  10201. ExpectStrEQ("www.paypal.com", (const char*) result);
  10202. length = 32;
  10203. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10204. 0, result, &length));
  10205. if (EXPECT_SUCCESS())
  10206. result[length] = 0;
  10207. ExpectStrEQ("api.textmate.org", (const char*) result);
  10208. /* SSL v2.0 tests */
  10209. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  10210. sizeof(buff5), 0, result, &length));
  10211. buff5[2] = 0x02;
  10212. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10213. sizeof(buff5), 0, result, &length));
  10214. buff5[2] = 0x01; buff5[6] = 0x08;
  10215. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10216. sizeof(buff5), 0, result, &length));
  10217. buff5[6] = 0x09; buff5[8] = 0x01;
  10218. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10219. sizeof(buff5), 0, result, &length));
  10220. return EXPECT_RESULT();
  10221. }
  10222. #endif /* HAVE_SNI */
  10223. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10224. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10225. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10226. /* Dummy peer functions to satisfy the exporter/importer */
  10227. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10228. int* ipSz, unsigned short* port, int* fam)
  10229. {
  10230. (void)ssl;
  10231. ip[0] = -1;
  10232. *ipSz = 1;
  10233. *port = 1;
  10234. *fam = 2;
  10235. return 1;
  10236. }
  10237. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10238. int ipSz, unsigned short port, int fam)
  10239. {
  10240. (void)ssl;
  10241. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10242. return 0;
  10243. return 1;
  10244. }
  10245. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10246. WOLFSSL **ssl)
  10247. {
  10248. EXPECT_DECLS;
  10249. unsigned char* sessionBuf = NULL;
  10250. unsigned int sessionSz = 0;
  10251. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10252. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10253. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10254. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10255. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10256. ExpectNotNull(sessionBuf =
  10257. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10258. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10259. wolfSSL_free(*ssl);
  10260. *ssl = NULL;
  10261. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10262. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10263. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10264. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10265. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10266. return EXPECT_RESULT();
  10267. }
  10268. #endif
  10269. static int test_wolfSSL_dtls_export_peers(void)
  10270. {
  10271. EXPECT_DECLS;
  10272. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10273. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10274. test_ssl_cbf client_cbf;
  10275. test_ssl_cbf server_cbf;
  10276. size_t i, j;
  10277. struct test_params {
  10278. method_provider client_meth;
  10279. method_provider server_meth;
  10280. const char* dtls_version;
  10281. } params[] = {
  10282. #ifndef NO_OLD_TLS
  10283. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10284. #endif
  10285. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10286. /* TODO DTLS 1.3 exporting not supported
  10287. #ifdef WOLFSSL_DTLS13
  10288. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10289. #endif
  10290. */
  10291. };
  10292. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10293. for (j = 0; j <= 0b11; j++) {
  10294. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10295. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10296. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10297. client_cbf.method = params[i].client_meth;
  10298. server_cbf.method = params[i].server_meth;
  10299. if (j & 0b01) {
  10300. client_cbf.on_handshake =
  10301. test_wolfSSL_dtls_export_peers_on_handshake;
  10302. printf(" With client export;");
  10303. }
  10304. if (j & 0b10) {
  10305. server_cbf.on_handshake =
  10306. test_wolfSSL_dtls_export_peers_on_handshake;
  10307. printf(" With server export;");
  10308. }
  10309. printf("\n");
  10310. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10311. &server_cbf, NULL), TEST_SUCCESS);
  10312. if (!EXPECT_SUCCESS())
  10313. break;
  10314. }
  10315. }
  10316. #endif
  10317. return EXPECT_RESULT();
  10318. }
  10319. static int test_wolfSSL_UseTrustedCA(void)
  10320. {
  10321. EXPECT_DECLS;
  10322. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10323. && !defined(NO_RSA)
  10324. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10325. WOLFSSL_CTX *ctx = NULL;
  10326. WOLFSSL *ssl = NULL;
  10327. byte id[20];
  10328. #ifndef NO_WOLFSSL_SERVER
  10329. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10330. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10331. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10332. #else
  10333. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10334. #endif
  10335. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10336. XMEMSET(id, 0, sizeof(id));
  10337. /* error cases */
  10338. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10339. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10340. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10341. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10342. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10343. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10344. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10345. #ifdef NO_SHA
  10346. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10347. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10348. #endif
  10349. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10350. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10351. /* success cases */
  10352. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10353. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10354. #ifndef NO_SHA
  10355. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10356. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10357. #endif
  10358. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10359. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10360. wolfSSL_free(ssl);
  10361. wolfSSL_CTX_free(ctx);
  10362. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10363. #endif /* HAVE_TRUSTED_CA */
  10364. return EXPECT_RESULT();
  10365. }
  10366. static int test_wolfSSL_UseMaxFragment(void)
  10367. {
  10368. EXPECT_DECLS;
  10369. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10370. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10371. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10372. #ifndef NO_WOLFSSL_SERVER
  10373. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10374. #else
  10375. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10376. #endif
  10377. WOLFSSL *ssl = NULL;
  10378. #ifdef OPENSSL_EXTRA
  10379. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10380. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10381. #else
  10382. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10383. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10384. #endif
  10385. #ifndef NO_WOLFSSL_SERVER
  10386. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10387. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10388. #endif
  10389. ExpectNotNull(ctx);
  10390. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10391. #ifdef OPENSSL_EXTRA
  10392. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10393. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10394. #else
  10395. UseMaxFragment = wolfSSL_UseMaxFragment;
  10396. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10397. #endif
  10398. /* error cases */
  10399. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10400. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10401. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10402. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10403. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10404. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10405. /* success case */
  10406. #ifdef OPENSSL_EXTRA
  10407. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10408. #else
  10409. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10410. #endif
  10411. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10412. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10413. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10414. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10415. #ifdef OPENSSL_EXTRA
  10416. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10417. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10418. #else
  10419. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10420. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10421. #endif
  10422. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10423. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10424. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10425. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10426. #ifdef OPENSSL_EXTRA
  10427. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10428. #else
  10429. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10430. #endif
  10431. wolfSSL_free(ssl);
  10432. wolfSSL_CTX_free(ctx);
  10433. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10434. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10435. /* check negotiated max fragment size */
  10436. {
  10437. WOLFSSL *ssl_c = NULL;
  10438. WOLFSSL *ssl_s = NULL;
  10439. struct test_memio_ctx test_ctx;
  10440. WOLFSSL_CTX *ctx_c = NULL;
  10441. WOLFSSL_CTX *ctx_s = NULL;
  10442. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10443. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10444. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10445. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10446. WOLFSSL_SUCCESS);
  10447. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10448. #ifndef NO_SESSION_CACHE
  10449. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10450. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10451. #endif
  10452. wolfSSL_free(ssl_c);
  10453. wolfSSL_free(ssl_s);
  10454. wolfSSL_CTX_free(ctx_c);
  10455. wolfSSL_CTX_free(ctx_s);
  10456. }
  10457. #endif
  10458. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10459. #endif
  10460. return EXPECT_RESULT();
  10461. }
  10462. static int test_wolfSSL_UseTruncatedHMAC(void)
  10463. {
  10464. EXPECT_DECLS;
  10465. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10466. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10467. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10468. #ifndef NO_WOLFSSL_SERVER
  10469. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10470. #else
  10471. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10472. #endif
  10473. WOLFSSL *ssl = NULL;
  10474. ExpectNotNull(ctx);
  10475. #ifndef NO_WOLFSSL_SERVER
  10476. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10477. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10478. #endif
  10479. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10480. /* error cases */
  10481. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10482. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10483. /* success case */
  10484. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10485. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10486. wolfSSL_free(ssl);
  10487. wolfSSL_CTX_free(ctx);
  10488. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10489. #endif
  10490. return EXPECT_RESULT();
  10491. }
  10492. static int test_wolfSSL_UseSupportedCurve(void)
  10493. {
  10494. EXPECT_DECLS;
  10495. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10496. !defined(NO_TLS)
  10497. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10498. WOLFSSL *ssl = wolfSSL_new(ctx);
  10499. ExpectNotNull(ctx);
  10500. ExpectNotNull(ssl);
  10501. /* error cases */
  10502. ExpectIntNE(WOLFSSL_SUCCESS,
  10503. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10504. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10505. ExpectIntNE(WOLFSSL_SUCCESS,
  10506. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10507. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10508. /* success case */
  10509. ExpectIntEQ(WOLFSSL_SUCCESS,
  10510. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10511. ExpectIntEQ(WOLFSSL_SUCCESS,
  10512. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10513. wolfSSL_free(ssl);
  10514. wolfSSL_CTX_free(ctx);
  10515. #endif
  10516. return EXPECT_RESULT();
  10517. }
  10518. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10519. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10520. {
  10521. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10522. }
  10523. static void use_ALPN_all(WOLFSSL* ssl)
  10524. {
  10525. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10526. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10527. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10528. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10529. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10530. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10531. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10532. }
  10533. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10534. {
  10535. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10536. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10537. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10538. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10539. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10540. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10541. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10542. }
  10543. static void use_ALPN_one(WOLFSSL* ssl)
  10544. {
  10545. /* spdy/2 */
  10546. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10547. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10548. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10549. }
  10550. static void use_ALPN_unknown(WOLFSSL* ssl)
  10551. {
  10552. /* http/2.0 */
  10553. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10554. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10555. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10556. }
  10557. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10558. {
  10559. /* http/2.0 */
  10560. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10561. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10562. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10563. }
  10564. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10565. {
  10566. /* spdy/3 */
  10567. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10568. char *proto = NULL;
  10569. word16 protoSz = 0;
  10570. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10571. /* check value */
  10572. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10573. if (proto) {
  10574. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10575. }
  10576. }
  10577. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10578. {
  10579. char *proto = NULL;
  10580. word16 protoSz = 0;
  10581. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10582. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10583. /* check value */
  10584. AssertIntEQ(1, (0 == protoSz));
  10585. AssertIntEQ(1, (NULL == proto));
  10586. }
  10587. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10588. {
  10589. /* http/1.1 */
  10590. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10591. char *proto;
  10592. word16 protoSz = 0;
  10593. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10594. /* check value */
  10595. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10596. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10597. }
  10598. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10599. {
  10600. /* spdy/2 */
  10601. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10602. char *proto;
  10603. word16 protoSz = 0;
  10604. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10605. /* check value */
  10606. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10607. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10608. }
  10609. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10610. {
  10611. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10612. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10613. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10614. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10615. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10616. char *clist = NULL;
  10617. word16 clistSz = 0;
  10618. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10619. &clistSz));
  10620. /* check value */
  10621. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10622. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10623. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10624. }
  10625. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10626. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10627. /* ALPN select callback, success with spdy/2 */
  10628. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10629. unsigned char *outlen, const unsigned char *in,
  10630. unsigned int inlen, void *arg)
  10631. {
  10632. /* spdy/2 */
  10633. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10634. (void)ssl;
  10635. (void)arg;
  10636. /* adding +1 since LEN byte comes first */
  10637. if (inlen < sizeof(proto) + 1) {
  10638. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10639. }
  10640. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10641. *out = in + 1;
  10642. *outlen = (unsigned char)sizeof(proto);
  10643. return SSL_TLSEXT_ERR_OK;
  10644. }
  10645. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10646. }
  10647. /* ALPN select callback, force failure */
  10648. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10649. unsigned char *outlen, const unsigned char *in,
  10650. unsigned int inlen, void *arg)
  10651. {
  10652. (void)ssl;
  10653. (void)out;
  10654. (void)outlen;
  10655. (void)in;
  10656. (void)inlen;
  10657. (void)arg;
  10658. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10659. }
  10660. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10661. {
  10662. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10663. }
  10664. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10665. {
  10666. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10667. }
  10668. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10669. static int test_wolfSSL_UseALPN_connection(void)
  10670. {
  10671. int res = TEST_SKIPPED;
  10672. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10673. callback_functions client_cb;
  10674. callback_functions server_cb;
  10675. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10676. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10677. client_cb.method = wolfSSLv23_client_method;
  10678. server_cb.method = wolfSSLv23_server_method;
  10679. client_cb.devId = testDevId;
  10680. server_cb.devId = testDevId;
  10681. /* success case same list */
  10682. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10683. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10684. test_wolfSSL_client_server(&client_cb, &server_cb);
  10685. /* success case only one for server */
  10686. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10687. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10688. test_wolfSSL_client_server(&client_cb, &server_cb);
  10689. /* success case only one for client */
  10690. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10691. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10692. test_wolfSSL_client_server(&client_cb, &server_cb);
  10693. /* success case none for client */
  10694. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10695. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10696. test_wolfSSL_client_server(&client_cb, &server_cb);
  10697. /* success case mismatch behavior but option 'continue' set */
  10698. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10699. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10700. test_wolfSSL_client_server(&client_cb, &server_cb);
  10701. /* success case read protocol send by client */
  10702. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10703. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10704. test_wolfSSL_client_server(&client_cb, &server_cb);
  10705. /* mismatch behavior with same list
  10706. * the first and only this one must be taken */
  10707. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10708. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10709. test_wolfSSL_client_server(&client_cb, &server_cb);
  10710. /* default mismatch behavior */
  10711. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10712. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10713. test_wolfSSL_client_server(&client_cb, &server_cb);
  10714. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10715. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10716. /* WOLFSSL-level ALPN select callback tests */
  10717. /* Callback: success (one protocol, spdy/2) */
  10718. client_cb.ctx_ready = NULL;
  10719. client_cb.ssl_ready = use_ALPN_one;
  10720. client_cb.on_result = verify_ALPN_matching_spdy2;
  10721. server_cb.ctx_ready = NULL;
  10722. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10723. server_cb.on_result = verify_ALPN_matching_spdy2;
  10724. test_wolfSSL_client_server(&client_cb, &server_cb);
  10725. /* Callback: failure (one client protocol, spdy/2) */
  10726. client_cb.ctx_ready = NULL;
  10727. client_cb.ssl_ready = use_ALPN_one;
  10728. client_cb.on_result = NULL;
  10729. server_cb.ctx_ready = NULL;
  10730. server_cb.ssl_ready = use_ALPN_failure_callback;
  10731. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10732. test_wolfSSL_client_server(&client_cb, &server_cb);
  10733. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10734. res = TEST_RES_CHECK(1);
  10735. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10736. return res;
  10737. }
  10738. static int test_wolfSSL_UseALPN_params(void)
  10739. {
  10740. EXPECT_DECLS;
  10741. #ifndef NO_WOLFSSL_CLIENT
  10742. /* "http/1.1" */
  10743. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10744. /* "spdy/1" */
  10745. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10746. /* "spdy/2" */
  10747. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10748. /* "spdy/3" */
  10749. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10750. char buff[256];
  10751. word32 idx;
  10752. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10753. WOLFSSL *ssl = wolfSSL_new(ctx);
  10754. ExpectNotNull(ctx);
  10755. ExpectNotNull(ssl);
  10756. /* error cases */
  10757. ExpectIntNE(WOLFSSL_SUCCESS,
  10758. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10759. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10760. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10761. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10762. /* success case */
  10763. /* http1 only */
  10764. ExpectIntEQ(WOLFSSL_SUCCESS,
  10765. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10766. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10767. /* http1, spdy1 */
  10768. XMEMCPY(buff, http1, sizeof(http1));
  10769. idx = sizeof(http1);
  10770. buff[idx++] = ',';
  10771. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10772. idx += sizeof(spdy1);
  10773. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10774. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10775. /* http1, spdy2, spdy1 */
  10776. XMEMCPY(buff, http1, sizeof(http1));
  10777. idx = sizeof(http1);
  10778. buff[idx++] = ',';
  10779. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10780. idx += sizeof(spdy2);
  10781. buff[idx++] = ',';
  10782. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10783. idx += sizeof(spdy1);
  10784. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10785. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10786. /* spdy3, http1, spdy2, spdy1 */
  10787. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10788. idx = sizeof(spdy3);
  10789. buff[idx++] = ',';
  10790. XMEMCPY(buff+idx, http1, sizeof(http1));
  10791. idx += sizeof(http1);
  10792. buff[idx++] = ',';
  10793. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10794. idx += sizeof(spdy2);
  10795. buff[idx++] = ',';
  10796. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10797. idx += sizeof(spdy1);
  10798. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10799. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10800. wolfSSL_free(ssl);
  10801. wolfSSL_CTX_free(ctx);
  10802. #endif
  10803. return EXPECT_RESULT();
  10804. }
  10805. #endif /* HAVE_ALPN */
  10806. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10807. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10808. {
  10809. unsigned char p[] = {
  10810. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10811. 6, 's', 'p', 'd', 'y', '/', '2',
  10812. 6, 's', 'p', 'd', 'y', '/', '1',
  10813. };
  10814. unsigned char p_len = sizeof(p);
  10815. int ret;
  10816. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10817. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10818. AssertIntEQ(ret, 0);
  10819. #else
  10820. AssertIntEQ(ret, SSL_SUCCESS);
  10821. #endif
  10822. }
  10823. static void set_alpn_protos(SSL* ssl)
  10824. {
  10825. unsigned char p[] = {
  10826. 6, 's', 'p', 'd', 'y', '/', '3',
  10827. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10828. 6, 's', 'p', 'd', 'y', '/', '2',
  10829. 6, 's', 'p', 'd', 'y', '/', '1',
  10830. };
  10831. unsigned char p_len = sizeof(p);
  10832. int ret;
  10833. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10834. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10835. AssertIntEQ(ret, 0);
  10836. #else
  10837. AssertIntEQ(ret, SSL_SUCCESS);
  10838. #endif
  10839. }
  10840. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10841. {
  10842. /* "spdy/3" */
  10843. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10844. const unsigned char *proto;
  10845. unsigned int protoSz = 0;
  10846. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10847. /* check value */
  10848. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10849. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10850. }
  10851. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10852. {
  10853. /* "http/1.1" */
  10854. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10855. const unsigned char *proto;
  10856. unsigned int protoSz = 0;
  10857. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10858. /* check value */
  10859. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10860. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10861. }
  10862. static int test_wolfSSL_set_alpn_protos(void)
  10863. {
  10864. int res = TEST_SKIPPED;
  10865. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10866. callback_functions client_cb;
  10867. callback_functions server_cb;
  10868. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10869. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10870. client_cb.method = wolfSSLv23_client_method;
  10871. server_cb.method = wolfSSLv23_server_method;
  10872. client_cb.devId = testDevId;
  10873. server_cb.devId = testDevId;
  10874. /* use CTX_alpn_protos */
  10875. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10876. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10877. test_wolfSSL_client_server(&client_cb, &server_cb);
  10878. /* use set_alpn_protos */
  10879. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10880. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10881. test_wolfSSL_client_server(&client_cb, &server_cb);
  10882. res = TEST_SUCCESS;
  10883. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10884. return res;
  10885. }
  10886. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10887. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10888. {
  10889. EXPECT_DECLS;
  10890. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10891. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10892. WOLFSSL *ssl = wolfSSL_new(ctx);
  10893. ExpectNotNull(ctx);
  10894. ExpectNotNull(ssl);
  10895. /* error cases */
  10896. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10897. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10898. /* success cases */
  10899. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10900. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10901. wolfSSL_free(ssl);
  10902. wolfSSL_CTX_free(ctx);
  10903. #endif
  10904. return EXPECT_RESULT();
  10905. }
  10906. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10907. {
  10908. EXPECT_DECLS;
  10909. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10910. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10911. WOLFSSL *ssl = wolfSSL_new(ctx);
  10912. ExpectNotNull(ctx);
  10913. ExpectNotNull(ssl);
  10914. /* error cases */
  10915. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10916. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10917. /* success cases */
  10918. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10919. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10920. wolfSSL_free(ssl);
  10921. wolfSSL_CTX_free(ctx);
  10922. #endif
  10923. return EXPECT_RESULT();
  10924. }
  10925. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10926. static int test_wolfSSL_SCR_Reconnect(void)
  10927. {
  10928. EXPECT_DECLS;
  10929. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10930. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10931. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10932. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10933. struct test_memio_ctx test_ctx;
  10934. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10935. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10936. byte data;
  10937. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10938. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10939. test_ctx.s_ciphers =
  10940. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10941. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10942. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10943. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10944. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10945. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10946. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10947. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10948. /* WOLFSSL_FATAL_ERROR since it will block */
  10949. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10950. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10951. WOLFSSL_ERROR_WANT_READ);
  10952. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10953. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10954. WOLFSSL_ERROR_WANT_READ);
  10955. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10956. wolfSSL_free(ssl_c);
  10957. ssl_c = NULL;
  10958. wolfSSL_free(ssl_s);
  10959. ssl_s = NULL;
  10960. wolfSSL_CTX_free(ctx_c);
  10961. ctx_c = NULL;
  10962. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10963. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10964. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10965. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10966. wolfSSL_free(ssl_s);
  10967. wolfSSL_free(ssl_c);
  10968. wolfSSL_CTX_free(ctx_s);
  10969. wolfSSL_CTX_free(ctx_c);
  10970. #endif
  10971. return EXPECT_RESULT();
  10972. }
  10973. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10974. (!defined(NO_RSA) || defined(HAVE_ECC))
  10975. /* Called when writing. */
  10976. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10977. {
  10978. (void)ssl;
  10979. (void)buf;
  10980. (void)sz;
  10981. (void)ctx;
  10982. /* Force error return from wolfSSL_accept_TLSv13(). */
  10983. return WANT_WRITE;
  10984. }
  10985. /* Called when reading. */
  10986. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10987. {
  10988. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10989. int len = (int)msg->length;
  10990. (void)ssl;
  10991. (void)sz;
  10992. /* Pass back as much of message as will fit in buffer. */
  10993. if (len > sz)
  10994. len = sz;
  10995. XMEMCPY(buf, msg->buffer, len);
  10996. /* Move over returned data. */
  10997. msg->buffer += len;
  10998. msg->length -= len;
  10999. /* Amount actually copied. */
  11000. return len;
  11001. }
  11002. #endif
  11003. /* Test the detection of duplicate known TLS extensions.
  11004. * Specifically in a ClientHello.
  11005. */
  11006. static int test_tls_ext_duplicate(void)
  11007. {
  11008. EXPECT_DECLS;
  11009. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  11010. !defined(NO_FILESYSTEM)
  11011. const unsigned char clientHelloDupTlsExt[] = {
  11012. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  11013. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  11014. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  11015. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  11016. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  11017. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  11018. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  11019. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  11020. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11021. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  11022. 0x00, 0x9e, 0x01, 0x00,
  11023. /* Extensions - duplicate signature algorithms. */
  11024. 0x00, 0x19, 0x00, 0x0d,
  11025. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  11026. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  11027. /* Supported Versions extension for TLS 1.3. */
  11028. 0x00, 0x2b,
  11029. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  11030. };
  11031. WOLFSSL_BUFFER_INFO msg;
  11032. const char* testCertFile;
  11033. const char* testKeyFile;
  11034. WOLFSSL_CTX *ctx = NULL;
  11035. WOLFSSL *ssl = NULL;
  11036. #ifndef NO_RSA
  11037. testCertFile = svrCertFile;
  11038. testKeyFile = svrKeyFile;
  11039. #elif defined(HAVE_ECC)
  11040. testCertFile = eccCertFile;
  11041. testKeyFile = eccKeyFile;
  11042. #endif
  11043. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11044. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  11045. WOLFSSL_FILETYPE_PEM));
  11046. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  11047. WOLFSSL_FILETYPE_PEM));
  11048. /* Read from 'msg'. */
  11049. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  11050. /* No where to send to - dummy sender. */
  11051. wolfSSL_SetIOSend(ctx, DummySend);
  11052. ssl = wolfSSL_new(ctx);
  11053. ExpectNotNull(ssl);
  11054. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  11055. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  11056. wolfSSL_SetIOReadCtx(ssl, &msg);
  11057. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  11058. /* can return duplicate ext error or socket error if the peer closed down
  11059. * while sending alert */
  11060. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  11061. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  11062. }
  11063. wolfSSL_free(ssl);
  11064. wolfSSL_CTX_free(ctx);
  11065. #endif
  11066. return EXPECT_RESULT();
  11067. }
  11068. /*----------------------------------------------------------------------------*
  11069. | X509 Tests
  11070. *----------------------------------------------------------------------------*/
  11071. static int test_wolfSSL_X509_NAME_get_entry(void)
  11072. {
  11073. EXPECT_DECLS;
  11074. #if !defined(NO_CERTS) && !defined(NO_RSA)
  11075. #if defined(OPENSSL_ALL) || \
  11076. (defined(OPENSSL_EXTRA) && \
  11077. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  11078. /* use openssl like name to test mapping */
  11079. X509_NAME_ENTRY* ne = NULL;
  11080. X509_NAME* name = NULL;
  11081. X509* x509 = NULL;
  11082. #ifndef NO_FILESYSTEM
  11083. ASN1_STRING* asn = NULL;
  11084. char* subCN = NULL;
  11085. #endif
  11086. int idx = 0;
  11087. ASN1_OBJECT *object = NULL;
  11088. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11089. defined(WOLFSSL_NGINX)
  11090. #ifndef NO_BIO
  11091. BIO* bio = NULL;
  11092. #endif
  11093. #endif
  11094. #ifndef NO_FILESYSTEM
  11095. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11096. WOLFSSL_FILETYPE_PEM));
  11097. ExpectNotNull(name = X509_get_subject_name(x509));
  11098. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11099. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11100. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  11101. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  11102. wolfSSL_FreeX509(x509);
  11103. x509 = NULL;
  11104. #endif
  11105. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11106. WOLFSSL_FILETYPE_PEM));
  11107. ExpectNotNull(name = X509_get_subject_name(x509));
  11108. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11109. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11110. defined(WOLFSSL_NGINX)
  11111. #ifndef NO_BIO
  11112. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11113. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  11114. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11115. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  11116. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11117. BIO_free(bio);
  11118. #endif
  11119. #endif
  11120. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11121. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  11122. wolfSSL_FreeX509(x509);
  11123. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  11124. #endif /* !NO_CERTS && !NO_RSA */
  11125. return EXPECT_RESULT();
  11126. }
  11127. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  11128. static int test_wolfSSL_PKCS12(void)
  11129. {
  11130. EXPECT_DECLS;
  11131. /* .p12 file is encrypted with DES3 */
  11132. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  11133. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  11134. * Password Key
  11135. */
  11136. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  11137. !defined(NO_STDIO_FILESYSTEM) && \
  11138. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  11139. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  11140. byte buf[6000];
  11141. char file[] = "./certs/test-servercert.p12";
  11142. char order[] = "./certs/ecc-rsa-server.p12";
  11143. #ifdef WC_RC2
  11144. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  11145. #endif
  11146. char pass[] = "a password";
  11147. const char goodPsw[] = "wolfSSL test";
  11148. const char badPsw[] = "bad";
  11149. #ifdef HAVE_ECC
  11150. WOLFSSL_X509_NAME *subject = NULL;
  11151. WOLFSSL_X509 *x509 = NULL;
  11152. #endif
  11153. XFILE f = XBADFILE;
  11154. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  11155. WOLFSSL_BIO *bio = NULL;
  11156. WOLFSSL_EVP_PKEY *pkey = NULL;
  11157. WC_PKCS12 *pkcs12 = NULL;
  11158. WC_PKCS12 *pkcs12_2 = NULL;
  11159. WOLFSSL_X509 *cert = NULL;
  11160. WOLFSSL_X509 *tmp = NULL;
  11161. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  11162. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11163. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11164. WOLFSSL_CTX *ctx = NULL;
  11165. WOLFSSL *ssl = NULL;
  11166. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  11167. #endif
  11168. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11169. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11170. if (f != XBADFILE) {
  11171. XFCLOSE(f);
  11172. f = XBADFILE;
  11173. }
  11174. goodPswLen = (int)XSTRLEN(goodPsw);
  11175. badPswLen = (int)XSTRLEN(badPsw);
  11176. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  11177. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  11178. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  11179. ExpectNotNull(pkcs12);
  11180. BIO_free(bio);
  11181. bio = NULL;
  11182. /* check verify MAC directly */
  11183. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  11184. /* check verify MAC fail case directly */
  11185. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  11186. /* check verify MAC fail case */
  11187. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11188. ExpectNull(pkey);
  11189. ExpectNull(cert);
  11190. /* check parse with no extra certs kept */
  11191. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11192. 1);
  11193. ExpectNotNull(pkey);
  11194. ExpectNotNull(cert);
  11195. wolfSSL_EVP_PKEY_free(pkey);
  11196. pkey = NULL;
  11197. wolfSSL_X509_free(cert);
  11198. cert = NULL;
  11199. /* check parse with extra certs kept */
  11200. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11201. 1);
  11202. ExpectNotNull(pkey);
  11203. ExpectNotNull(cert);
  11204. ExpectNotNull(ca);
  11205. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11206. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11207. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  11208. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11209. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11210. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11211. #else
  11212. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11213. #endif
  11214. /* Copy stack structure */
  11215. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  11216. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  11217. /* CTX now owns the tmp_ca stack structure */
  11218. tmp_ca = NULL;
  11219. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  11220. ExpectNotNull(tmp_ca);
  11221. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11222. /* Check that the main cert is also set */
  11223. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11224. ExpectNotNull(ssl = SSL_new(ctx));
  11225. ExpectNotNull(SSL_get_certificate(ssl));
  11226. SSL_free(ssl);
  11227. SSL_CTX_free(ctx);
  11228. ctx = NULL;
  11229. #endif
  11230. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11231. /* should be 2 other certs on stack */
  11232. ExpectNotNull(tmp = sk_X509_pop(ca));
  11233. X509_free(tmp);
  11234. ExpectNotNull(tmp = sk_X509_pop(ca));
  11235. X509_free(tmp);
  11236. ExpectNull(sk_X509_pop(ca));
  11237. EVP_PKEY_free(pkey);
  11238. pkey = NULL;
  11239. X509_free(cert);
  11240. cert = NULL;
  11241. sk_X509_pop_free(ca, X509_free);
  11242. ca = NULL;
  11243. /* check PKCS12_create */
  11244. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11245. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11246. SSL_SUCCESS);
  11247. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11248. -1, -1, 100, -1, 0)));
  11249. EVP_PKEY_free(pkey);
  11250. pkey = NULL;
  11251. X509_free(cert);
  11252. cert = NULL;
  11253. sk_X509_pop_free(ca, NULL);
  11254. ca = NULL;
  11255. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11256. SSL_SUCCESS);
  11257. PKCS12_free(pkcs12_2);
  11258. pkcs12_2 = NULL;
  11259. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11260. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11261. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11262. 2000, 1, 0)));
  11263. EVP_PKEY_free(pkey);
  11264. pkey = NULL;
  11265. X509_free(cert);
  11266. cert = NULL;
  11267. sk_X509_pop_free(ca, NULL);
  11268. ca = NULL;
  11269. /* convert to DER then back and parse */
  11270. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11271. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11272. PKCS12_free(pkcs12_2);
  11273. pkcs12_2 = NULL;
  11274. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11275. BIO_free(bio);
  11276. bio = NULL;
  11277. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11278. SSL_SUCCESS);
  11279. /* should be 2 other certs on stack */
  11280. ExpectNotNull(tmp = sk_X509_pop(ca));
  11281. X509_free(tmp);
  11282. ExpectNotNull(tmp = sk_X509_pop(ca));
  11283. X509_free(tmp);
  11284. ExpectNull(sk_X509_pop(ca));
  11285. #ifndef NO_RC4
  11286. PKCS12_free(pkcs12_2);
  11287. pkcs12_2 = NULL;
  11288. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11289. NID_pbe_WithSHA1And128BitRC4,
  11290. NID_pbe_WithSHA1And128BitRC4,
  11291. 2000, 1, 0)));
  11292. EVP_PKEY_free(pkey);
  11293. pkey = NULL;
  11294. X509_free(cert);
  11295. cert = NULL;
  11296. sk_X509_pop_free(ca, NULL);
  11297. ca = NULL;
  11298. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11299. SSL_SUCCESS);
  11300. #endif /* NO_RC4 */
  11301. EVP_PKEY_free(pkey);
  11302. pkey = NULL;
  11303. X509_free(cert);
  11304. cert = NULL;
  11305. PKCS12_free(pkcs12);
  11306. pkcs12 = NULL;
  11307. PKCS12_free(pkcs12_2);
  11308. pkcs12_2 = NULL;
  11309. sk_X509_pop_free(ca, NULL);
  11310. ca = NULL;
  11311. #ifdef HAVE_ECC
  11312. /* test order of parsing */
  11313. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11314. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11315. if (f != XBADFILE) {
  11316. XFCLOSE(f);
  11317. f = XBADFILE;
  11318. }
  11319. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11320. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11321. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11322. WOLFSSL_SUCCESS);
  11323. /* check use of pkey after parse */
  11324. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11325. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11326. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11327. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11328. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11329. #else
  11330. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11331. #endif
  11332. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11333. SSL_CTX_free(ctx);
  11334. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11335. #endif
  11336. ExpectNotNull(pkey);
  11337. ExpectNotNull(cert);
  11338. ExpectNotNull(ca);
  11339. /* compare subject lines of certificates */
  11340. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11341. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11342. SSL_FILETYPE_PEM));
  11343. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11344. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11345. X509_free(x509);
  11346. x509 = NULL;
  11347. /* test expected fail case */
  11348. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11349. SSL_FILETYPE_PEM));
  11350. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11351. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11352. X509_free(x509);
  11353. x509 = NULL;
  11354. X509_free(cert);
  11355. cert = NULL;
  11356. /* get subject line from ca stack */
  11357. ExpectNotNull(cert = sk_X509_pop(ca));
  11358. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11359. /* compare subject from certificate in ca to expected */
  11360. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11361. SSL_FILETYPE_PEM));
  11362. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11363. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11364. /* modify case and compare subject from certificate in ca to expected.
  11365. * The first bit of the name is:
  11366. * /C=US/ST=Washington
  11367. * So we'll change subject->name[1] to 'c' (lower case) */
  11368. if (subject != NULL) {
  11369. subject->name[1] = 'c';
  11370. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11371. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11372. }
  11373. EVP_PKEY_free(pkey);
  11374. pkey = NULL;
  11375. X509_free(x509);
  11376. x509 = NULL;
  11377. X509_free(cert);
  11378. cert = NULL;
  11379. BIO_free(bio);
  11380. bio = NULL;
  11381. PKCS12_free(pkcs12);
  11382. pkcs12 = NULL;
  11383. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11384. ca = NULL;
  11385. /* test order of parsing */
  11386. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11387. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11388. if (f != XBADFILE) {
  11389. XFCLOSE(f);
  11390. f = XBADFILE;
  11391. }
  11392. /* check verify MAC fail case */
  11393. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11394. ExpectNull(pkey);
  11395. ExpectNull(cert);
  11396. /* check parse with no extra certs kept */
  11397. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11398. 1);
  11399. ExpectNotNull(pkey);
  11400. ExpectNotNull(cert);
  11401. wolfSSL_EVP_PKEY_free(pkey);
  11402. pkey = NULL;
  11403. wolfSSL_X509_free(cert);
  11404. cert = NULL;
  11405. /* check parse with extra certs kept */
  11406. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11407. 1);
  11408. ExpectNotNull(pkey);
  11409. ExpectNotNull(cert);
  11410. ExpectNotNull(ca);
  11411. wolfSSL_EVP_PKEY_free(pkey);
  11412. pkey = NULL;
  11413. wolfSSL_X509_free(cert);
  11414. cert = NULL;
  11415. sk_X509_pop_free(ca, NULL);
  11416. ca = NULL;
  11417. PKCS12_free(pkcs12);
  11418. pkcs12 = NULL;
  11419. #endif /* HAVE_ECC */
  11420. #ifdef WC_RC2
  11421. /* test PKCS#12 with RC2 encryption */
  11422. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11423. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11424. if (f != XBADFILE) {
  11425. XFCLOSE(f);
  11426. f = XBADFILE;
  11427. }
  11428. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11429. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11430. /* check verify MAC fail case */
  11431. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11432. ExpectNull(pkey);
  11433. ExpectNull(cert);
  11434. /* check parse with not extra certs kept */
  11435. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11436. WOLFSSL_SUCCESS);
  11437. ExpectNotNull(pkey);
  11438. ExpectNotNull(cert);
  11439. wolfSSL_EVP_PKEY_free(pkey);
  11440. pkey = NULL;
  11441. wolfSSL_X509_free(cert);
  11442. cert = NULL;
  11443. /* check parse with extra certs kept */
  11444. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11445. WOLFSSL_SUCCESS);
  11446. ExpectNotNull(pkey);
  11447. ExpectNotNull(cert);
  11448. ExpectNotNull(ca);
  11449. wolfSSL_EVP_PKEY_free(pkey);
  11450. wolfSSL_X509_free(cert);
  11451. sk_X509_pop_free(ca, NULL);
  11452. BIO_free(bio);
  11453. bio = NULL;
  11454. PKCS12_free(pkcs12);
  11455. pkcs12 = NULL;
  11456. #endif /* WC_RC2 */
  11457. /* Test i2d_PKCS12_bio */
  11458. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11459. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11460. if (f != XBADFILE)
  11461. XFCLOSE(f);
  11462. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11463. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11464. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11465. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11466. PKCS12_free(pkcs12);
  11467. BIO_free(bio);
  11468. (void)order;
  11469. #endif /* OPENSSL_EXTRA */
  11470. #endif /* HAVE_FIPS */
  11471. return EXPECT_RESULT();
  11472. }
  11473. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11474. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11475. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11476. #define TEST_PKCS8_ENC
  11477. #endif
  11478. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11479. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11480. /* used to keep track if FailTestCallback was called */
  11481. static int failTestCallbackCalled = 0;
  11482. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11483. {
  11484. (void)passwd;
  11485. (void)sz;
  11486. (void)rw;
  11487. (void)userdata;
  11488. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11489. failTestCallbackCalled = 1;
  11490. return -1;
  11491. }
  11492. #endif
  11493. static int test_wolfSSL_no_password_cb(void)
  11494. {
  11495. EXPECT_DECLS;
  11496. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11497. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11498. WOLFSSL_CTX* ctx = NULL;
  11499. byte buff[FOURK_BUF];
  11500. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11501. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11502. XFILE f = XBADFILE;
  11503. int bytes = 0;
  11504. #ifndef NO_WOLFSSL_CLIENT
  11505. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11506. #else
  11507. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11508. #endif
  11509. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11510. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11511. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11512. if (f != XBADFILE) {
  11513. XFCLOSE(f);
  11514. f = XBADFILE;
  11515. }
  11516. ExpectIntLE(bytes, sizeof(buff));
  11517. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11518. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11519. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11520. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11521. if (f != XBADFILE)
  11522. XFCLOSE(f);
  11523. ExpectIntLE(bytes, sizeof(buff));
  11524. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11525. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11526. wolfSSL_CTX_free(ctx);
  11527. /* Password callback should not be called by default */
  11528. ExpectIntEQ(failTestCallbackCalled, 0);
  11529. #endif
  11530. return EXPECT_RESULT();
  11531. }
  11532. #ifdef TEST_PKCS8_ENC
  11533. /* for PKCS8 test case */
  11534. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11535. {
  11536. int flag = 0;
  11537. (void)rw;
  11538. if (userdata != NULL) {
  11539. flag = *((int*)userdata); /* user set data */
  11540. }
  11541. switch (flag) {
  11542. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11543. * can be anything the user wishes to be passed to the callback
  11544. * associated with the WOLFSSL_CTX */
  11545. XSTRNCPY(passwd, "yassl123", sz);
  11546. return 8;
  11547. default:
  11548. return BAD_FUNC_ARG;
  11549. }
  11550. }
  11551. #endif /* TEST_PKCS8_ENC */
  11552. /* Testing functions dealing with PKCS8 */
  11553. static int test_wolfSSL_PKCS8(void)
  11554. {
  11555. EXPECT_DECLS;
  11556. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11557. !defined(WOLFCRYPT_ONLY)
  11558. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11559. byte buff[FOURK_BUF];
  11560. byte der[FOURK_BUF];
  11561. #ifndef NO_RSA
  11562. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11563. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11564. #endif
  11565. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11566. #ifdef HAVE_ECC
  11567. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11568. #endif
  11569. XFILE f = XBADFILE;
  11570. int bytes = 0;
  11571. WOLFSSL_CTX* ctx = NULL;
  11572. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11573. int ret;
  11574. ecc_key key;
  11575. word32 x = 0;
  11576. #endif
  11577. #ifdef TEST_PKCS8_ENC
  11578. #if !defined(NO_RSA) && !defined(NO_SHA)
  11579. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11580. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11581. #endif
  11582. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11583. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11584. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11585. #endif
  11586. int flag;
  11587. #endif
  11588. (void)der;
  11589. #ifndef NO_WOLFSSL_CLIENT
  11590. #ifndef WOLFSSL_NO_TLS12
  11591. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11592. #else
  11593. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11594. #endif
  11595. #else
  11596. #ifndef WOLFSSL_NO_TLS12
  11597. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11598. #else
  11599. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11600. #endif
  11601. #endif
  11602. #ifdef TEST_PKCS8_ENC
  11603. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11604. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11605. flag = 1; /* used by password callback as return code */
  11606. #if !defined(NO_RSA) && !defined(NO_SHA)
  11607. /* test loading PEM PKCS8 encrypted file */
  11608. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11609. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11610. if (f != XBADFILE) {
  11611. XFCLOSE(f);
  11612. f = XBADFILE;
  11613. }
  11614. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11615. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11616. /* this next case should fail because of password callback return code */
  11617. flag = 0; /* used by password callback as return code */
  11618. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11619. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11620. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11621. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11622. "yassl123"), 0);
  11623. /* test that error value is returned with a bad password */
  11624. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11625. "bad"), 0);
  11626. /* test loading PEM PKCS8 encrypted file */
  11627. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11628. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11629. if (f != XBADFILE) {
  11630. XFCLOSE(f);
  11631. f = XBADFILE;
  11632. }
  11633. flag = 1; /* used by password callback as return code */
  11634. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11635. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11636. /* this next case should fail because of password callback return code */
  11637. flag = 0; /* used by password callback as return code */
  11638. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11639. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11640. #endif /* !NO_RSA && !NO_SHA */
  11641. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11642. /* test loading PEM PKCS8 encrypted ECC Key file */
  11643. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11644. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11645. if (f != XBADFILE) {
  11646. XFCLOSE(f);
  11647. f = XBADFILE;
  11648. }
  11649. flag = 1; /* used by password callback as return code */
  11650. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11651. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11652. /* this next case should fail because of password callback return code */
  11653. flag = 0; /* used by password callback as return code */
  11654. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11655. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11656. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11657. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11658. "yassl123"), 0);
  11659. /* test that error value is returned with a bad password */
  11660. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11661. "bad"), 0);
  11662. /* test loading DER PKCS8 encrypted ECC Key file */
  11663. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11664. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11665. if (f != XBADFILE) {
  11666. XFCLOSE(f);
  11667. f = XBADFILE;
  11668. }
  11669. flag = 1; /* used by password callback as return code */
  11670. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11671. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11672. /* this next case should fail because of password callback return code */
  11673. flag = 0; /* used by password callback as return code */
  11674. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11675. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11676. /* leave flag as "okay" */
  11677. flag = 1;
  11678. #endif /* HAVE_ECC && !NO_SHA */
  11679. #endif /* TEST_PKCS8_ENC */
  11680. #ifndef NO_RSA
  11681. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11682. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11683. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11684. if (f != XBADFILE) {
  11685. XFCLOSE(f);
  11686. f = XBADFILE;
  11687. }
  11688. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11689. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11690. /* test loading PEM PKCS8 private key file (not encrypted) */
  11691. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11692. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11693. if (f != XBADFILE) {
  11694. XFCLOSE(f);
  11695. f = XBADFILE;
  11696. }
  11697. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11698. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11699. #endif /* !NO_RSA */
  11700. /* Test PKCS8 PEM ECC key no crypt */
  11701. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11702. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11703. if (f != XBADFILE) {
  11704. XFCLOSE(f);
  11705. f = XBADFILE;
  11706. }
  11707. #ifdef HAVE_ECC
  11708. /* Test PKCS8 PEM ECC key no crypt */
  11709. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11710. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11711. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11712. /* decrypt PKCS8 PEM to key in DER format */
  11713. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11714. (word32)sizeof(der), NULL)), 0);
  11715. ret = wc_ecc_init(&key);
  11716. if (ret == 0) {
  11717. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11718. wc_ecc_free(&key);
  11719. }
  11720. ExpectIntEQ(ret, 0);
  11721. #endif
  11722. /* Test PKCS8 DER ECC key no crypt */
  11723. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11724. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11725. if (f != XBADFILE)
  11726. XFCLOSE(f);
  11727. /* Test using a PKCS8 ECC PEM */
  11728. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11729. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11730. #else
  11731. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11732. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11733. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11734. #endif /* HAVE_ECC */
  11735. wolfSSL_CTX_free(ctx);
  11736. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11737. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11738. return EXPECT_RESULT();
  11739. }
  11740. static int test_wolfSSL_PKCS8_ED25519(void)
  11741. {
  11742. EXPECT_DECLS;
  11743. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11744. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11745. defined(HAVE_ED25519_KEY_IMPORT)
  11746. const byte encPrivKey[] = \
  11747. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11748. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11749. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11750. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11751. "2L9W4v7swXkV+X+a1ww=\n"
  11752. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11753. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11754. byte der[FOURK_BUF];
  11755. WOLFSSL_CTX* ctx = NULL;
  11756. int bytes;
  11757. XMEMSET(der, 0, sizeof(der));
  11758. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11759. (word32)sizeof(der), password)), 0);
  11760. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11761. #ifndef NO_WOLFSSL_SERVER
  11762. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11763. #else
  11764. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11765. #endif
  11766. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11767. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11768. wolfSSL_CTX_free(ctx);
  11769. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11770. #endif
  11771. return EXPECT_RESULT();
  11772. }
  11773. static int test_wolfSSL_PKCS8_ED448(void)
  11774. {
  11775. EXPECT_DECLS;
  11776. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11777. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11778. defined(HAVE_ED448_KEY_IMPORT)
  11779. const byte encPrivKey[] = \
  11780. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11781. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11782. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11783. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11784. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11785. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11786. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11787. byte der[FOURK_BUF];
  11788. WOLFSSL_CTX* ctx = NULL;
  11789. int bytes;
  11790. XMEMSET(der, 0, sizeof(der));
  11791. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11792. (word32)sizeof(der), password)), 0);
  11793. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11794. #ifndef NO_WOLFSSL_SERVER
  11795. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11796. #else
  11797. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11798. #endif
  11799. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11800. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11801. wolfSSL_CTX_free(ctx);
  11802. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11803. #endif
  11804. return EXPECT_RESULT();
  11805. }
  11806. /* Testing functions dealing with PKCS5 */
  11807. static int test_wolfSSL_PKCS5(void)
  11808. {
  11809. EXPECT_DECLS;
  11810. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11811. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11812. const char* passwd = "myfipsPa$$W0rd";
  11813. #else
  11814. const char *passwd = "pass1234";
  11815. #endif
  11816. const unsigned char *salt = (unsigned char *)"salt1234";
  11817. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11818. DYNAMIC_TYPE_TMP_BUFFER);
  11819. int ret = 0;
  11820. ExpectNotNull(out);
  11821. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11822. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11823. WOLFSSL_SUCCESS);
  11824. #ifdef WOLFSSL_SHA512
  11825. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11826. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11827. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11828. #endif
  11829. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11830. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11831. return EXPECT_RESULT();
  11832. }
  11833. /* test parsing URI from certificate */
  11834. static int test_wolfSSL_URI(void)
  11835. {
  11836. EXPECT_DECLS;
  11837. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11838. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11839. defined(OPENSSL_EXTRA))
  11840. WOLFSSL_X509* x509 = NULL;
  11841. const char uri[] = "./certs/client-uri-cert.pem";
  11842. const char urn[] = "./certs/client-absolute-urn.pem";
  11843. const char badUri[] = "./certs/client-relative-uri.pem";
  11844. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11845. WOLFSSL_FILETYPE_PEM));
  11846. wolfSSL_FreeX509(x509);
  11847. x509 = NULL;
  11848. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11849. WOLFSSL_FILETYPE_PEM));
  11850. wolfSSL_FreeX509(x509);
  11851. x509 = NULL;
  11852. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11853. && !defined(WOLFSSL_FPKI)
  11854. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11855. WOLFSSL_FILETYPE_PEM));
  11856. #else
  11857. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11858. WOLFSSL_FILETYPE_PEM));
  11859. #endif
  11860. wolfSSL_FreeX509(x509);
  11861. #endif
  11862. return EXPECT_RESULT();
  11863. }
  11864. static int test_wolfSSL_TBS(void)
  11865. {
  11866. EXPECT_DECLS;
  11867. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11868. && defined(OPENSSL_EXTRA)
  11869. WOLFSSL_X509* x509 = NULL;
  11870. const unsigned char* tbs;
  11871. int tbsSz;
  11872. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11873. WOLFSSL_FILETYPE_PEM));
  11874. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11875. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11876. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11877. ExpectIntEQ(tbsSz, 1003);
  11878. wolfSSL_FreeX509(x509);
  11879. #endif
  11880. return EXPECT_RESULT();
  11881. }
  11882. static int test_wolfSSL_X509_verify(void)
  11883. {
  11884. EXPECT_DECLS;
  11885. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11886. defined(OPENSSL_EXTRA)
  11887. WOLFSSL_X509* ca = NULL;
  11888. WOLFSSL_X509* serv = NULL;
  11889. WOLFSSL_EVP_PKEY* pkey = NULL;
  11890. unsigned char buf[2048];
  11891. const unsigned char* pt = NULL;
  11892. int bufSz;
  11893. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11894. WOLFSSL_FILETYPE_PEM));
  11895. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11896. WOLFSSL_SUCCESS);
  11897. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11898. WOLFSSL_SUCCESS);
  11899. ExpectIntEQ(bufSz, 294);
  11900. bufSz = 2048;
  11901. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11902. WOLFSSL_SUCCESS);
  11903. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11904. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11905. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11906. WOLFSSL_FILETYPE_PEM));
  11907. /* success case */
  11908. pt = buf;
  11909. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11910. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11911. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11912. wolfSSL_EVP_PKEY_free(pkey);
  11913. pkey = NULL;
  11914. /* fail case */
  11915. bufSz = 2048;
  11916. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11917. WOLFSSL_SUCCESS);
  11918. pt = buf;
  11919. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11920. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11921. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11922. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11923. wolfSSL_EVP_PKEY_free(pkey);
  11924. wolfSSL_FreeX509(ca);
  11925. wolfSSL_FreeX509(serv);
  11926. #endif
  11927. return EXPECT_RESULT();
  11928. }
  11929. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11930. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11931. /* Given acert file and its pubkey file, read them and then
  11932. * attempt to verify signed acert.
  11933. *
  11934. * If expect_pass is true, then verification should pass.
  11935. * If expect_pass is false, then verification should fail.
  11936. * */
  11937. static int do_acert_verify_test(const char * acert_file,
  11938. const char * pkey_file,
  11939. size_t expect_pass)
  11940. {
  11941. X509_ACERT * x509 = NULL;
  11942. EVP_PKEY * pkey = NULL;
  11943. BIO * bp = NULL;
  11944. int verify_rc = 0;
  11945. /* First read the attribute certificate. */
  11946. bp = BIO_new_file(acert_file, "r");
  11947. if (bp == NULL) {
  11948. return -1;
  11949. }
  11950. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11951. BIO_free(bp);
  11952. bp = NULL;
  11953. if (x509 == NULL) {
  11954. return -1;
  11955. }
  11956. /* Next read the associated pub key. */
  11957. bp = BIO_new_file(pkey_file, "r");
  11958. if (bp == NULL) {
  11959. X509_ACERT_free(x509);
  11960. x509 = NULL;
  11961. return -1;
  11962. }
  11963. pkey = PEM_read_bio_PUBKEY(bp, &pkey, NULL, NULL);
  11964. BIO_free(bp);
  11965. bp = NULL;
  11966. if (pkey == NULL) {
  11967. X509_ACERT_free(x509);
  11968. x509 = NULL;
  11969. return -1;
  11970. }
  11971. /* Finally, do verification. */
  11972. verify_rc = X509_ACERT_verify(x509, pkey);
  11973. X509_ACERT_free(x509);
  11974. x509 = NULL;
  11975. EVP_PKEY_free(pkey);
  11976. pkey = NULL;
  11977. if (expect_pass && verify_rc != 1) {
  11978. return -1;
  11979. }
  11980. if (!expect_pass && verify_rc == 1) {
  11981. return -1;
  11982. }
  11983. return 0;
  11984. }
  11985. #endif
  11986. static int test_wolfSSL_X509_ACERT_verify(void)
  11987. {
  11988. EXPECT_DECLS;
  11989. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11990. defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11991. /* Walk over list of signed ACERTs and their pubkeys.
  11992. * All should load and pass verification. */
  11993. const char * acerts[4] = {"certs/acert/acert.pem",
  11994. "certs/acert/acert_ietf.pem",
  11995. "certs/acert/rsa_pss/acert.pem",
  11996. "certs/acert/rsa_pss/acert_ietf.pem"};
  11997. const char * pkeys[4] = {"certs/acert/acert_pubkey.pem",
  11998. "certs/acert/acert_ietf_pubkey.pem",
  11999. "certs/acert/rsa_pss/acert_pubkey.pem",
  12000. "certs/acert/rsa_pss/acert_ietf_pubkey.pem"};
  12001. int rc = 0;
  12002. size_t i = 0;
  12003. size_t j = 0;
  12004. for (i = 0; i < 4; ++i) {
  12005. for (j = i; j < 4; ++j) {
  12006. rc = do_acert_verify_test(acerts[i], pkeys[j], i == j);
  12007. if (rc) {
  12008. fprintf(stderr, "error: %s: i = %zu, j = %zu, rc = %d\n",
  12009. "do_acert_verify_test", i, j, rc);
  12010. break;
  12011. }
  12012. }
  12013. if (rc) { break; }
  12014. }
  12015. ExpectIntEQ(rc, 0);
  12016. #endif
  12017. return EXPECT_RESULT();
  12018. }
  12019. static int test_wolfSSL_X509_ACERT_misc_api(void)
  12020. {
  12021. EXPECT_DECLS;
  12022. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  12023. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  12024. const char * acerts[4] = {"certs/acert/acert.pem",
  12025. "certs/acert/acert_ietf.pem",
  12026. "certs/acert/rsa_pss/acert.pem",
  12027. "certs/acert/rsa_pss/acert_ietf.pem"};
  12028. int rc = 0;
  12029. X509_ACERT * x509 = NULL;
  12030. BIO * bp = NULL;
  12031. long ver_long = 0;
  12032. int ver = 0;
  12033. int nid = 0;
  12034. const byte * raw_attr = NULL;
  12035. word32 attr_len = 0;
  12036. size_t i = 0;
  12037. int buf_len = 0;
  12038. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12039. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12040. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12041. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12042. for (i = 0; i < 4; ++i) {
  12043. const char * acert_file = acerts[i];
  12044. int is_rsa_pss = 0;
  12045. int is_ietf_acert = 0;
  12046. byte serial[64];
  12047. int serial_len = sizeof(serial);
  12048. XMEMSET(serial, 0, sizeof(serial));
  12049. is_rsa_pss = XSTRSTR(acert_file, "rsa_pss") != NULL ? 1 : 0;
  12050. is_ietf_acert = XSTRSTR(acert_file, "ietf.pem") != NULL ? 1 : 0;
  12051. /* First read the attribute certificate. */
  12052. bp = BIO_new_file(acert_file, "r");
  12053. ExpectNotNull(bp);
  12054. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  12055. ExpectNotNull(x509);
  12056. /* We're done with the bio for now. */
  12057. if (bp != NULL) {
  12058. BIO_free(bp);
  12059. bp = NULL;
  12060. }
  12061. /* Check version and signature NID. */
  12062. ver_long = X509_ACERT_get_version(x509);
  12063. ExpectIntEQ(ver_long, 1);
  12064. ver = wolfSSL_X509_ACERT_version(x509);
  12065. ExpectIntEQ(ver, 2);
  12066. nid = X509_ACERT_get_signature_nid(x509);
  12067. if (is_rsa_pss) {
  12068. ExpectIntEQ(nid, NID_rsassaPss);
  12069. }
  12070. else {
  12071. ExpectIntEQ(nid, NID_sha256WithRSAEncryption);
  12072. }
  12073. /* Get the serial number buffer.
  12074. * The ietf acert example has a 20 byte serial number. */
  12075. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  12076. ExpectIntEQ(rc, SSL_SUCCESS);
  12077. if (is_ietf_acert) {
  12078. ExpectIntEQ(serial_len, 20);
  12079. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  12080. }
  12081. else {
  12082. ExpectIntEQ(serial_len, 1);
  12083. ExpectTrue(serial[0] == 0x01);
  12084. }
  12085. /* Repeat the same but with null serial buffer. This is ok. */
  12086. rc = wolfSSL_X509_ACERT_get_serial_number(x509, NULL, &serial_len);
  12087. ExpectIntEQ(rc, SSL_SUCCESS);
  12088. if (is_ietf_acert) {
  12089. ExpectIntEQ(serial_len, 20);
  12090. }
  12091. else {
  12092. ExpectIntEQ(serial_len, 1);
  12093. ExpectTrue(serial[0] == 0x01);
  12094. }
  12095. /* Get the attributes buffer. */
  12096. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  12097. ExpectIntEQ(rc, SSL_SUCCESS);
  12098. if (is_ietf_acert) {
  12099. /* This cert has a 65 byte attributes field. */
  12100. ExpectNotNull(raw_attr);
  12101. ExpectIntEQ(attr_len, 65);
  12102. }
  12103. else {
  12104. /* This cert has a 237 byte attributes field. */
  12105. ExpectNotNull(raw_attr);
  12106. ExpectIntEQ(attr_len, 237);
  12107. }
  12108. /* Test printing acert to memory bio. */
  12109. ExpectNotNull(bp = BIO_new(BIO_s_mem()));
  12110. rc = X509_ACERT_print(bp, x509);
  12111. ExpectIntEQ(rc, SSL_SUCCESS);
  12112. /* Now do a bunch of invalid stuff with partially valid inputs. */
  12113. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, NULL);
  12114. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12115. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, NULL, &attr_len);
  12116. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12117. rc = wolfSSL_X509_ACERT_get_attr_buf(NULL, &raw_attr, &attr_len);
  12118. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12119. ver_long = X509_ACERT_get_version(NULL);
  12120. ExpectIntEQ(ver_long, 0);
  12121. ver = wolfSSL_X509_ACERT_version(NULL);
  12122. ExpectIntEQ(ver, 0);
  12123. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, NULL);
  12124. ExpectIntEQ(rc, WOLFSSL_FATAL_ERROR);
  12125. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, &buf_len);
  12126. ExpectIntEQ(rc, SSL_SUCCESS);
  12127. ExpectIntEQ(buf_len, 256);
  12128. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, NULL);
  12129. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12130. rc = X509_ACERT_print(bp, NULL);
  12131. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12132. rc = X509_ACERT_print(NULL, x509);
  12133. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12134. /* Finally free the acert and bio, we're done with them. */
  12135. if (x509 != NULL) {
  12136. X509_ACERT_free(x509);
  12137. x509 = NULL;
  12138. }
  12139. if (bp != NULL) {
  12140. BIO_free(bp);
  12141. bp = NULL;
  12142. }
  12143. }
  12144. #endif
  12145. return EXPECT_RESULT();
  12146. }
  12147. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12148. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12149. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12150. /* create certificate with version 2 */
  12151. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  12152. {
  12153. EXPECT_DECLS;
  12154. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  12155. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  12156. unsigned char *der = NULL, *key = NULL, *pt;
  12157. char *header = NULL, *name = NULL;
  12158. int derSz;
  12159. long keySz;
  12160. XFILE fp = XBADFILE;
  12161. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  12162. time_t t;
  12163. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  12164. WOLFSSL_FILETYPE_PEM));
  12165. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  12166. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  12167. WOLFSSL_SUCCESS);
  12168. if (fp != XBADFILE)
  12169. XFCLOSE(fp);
  12170. pt = key;
  12171. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  12172. (const unsigned char**)&pt, keySz));
  12173. /* create the version 2 certificate */
  12174. ExpectNotNull(x509v2 = X509_new());
  12175. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  12176. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  12177. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  12178. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  12179. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  12180. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  12181. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  12182. t = time(NULL);
  12183. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  12184. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  12185. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  12186. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  12187. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  12188. derSz = wolfSSL_i2d_X509(x509v2, &der);
  12189. ExpectIntGT(derSz, 0);
  12190. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  12191. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  12192. /* TODO: Replace with API call */
  12193. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  12194. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12195. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12196. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12197. wolfSSL_X509_free(x509);
  12198. wolfSSL_X509_free(x509v2);
  12199. wolfSSL_EVP_PKEY_free(priv);
  12200. wolfSSL_EVP_PKEY_free(pub);
  12201. wolfSSL_ASN1_TIME_free(notBefore);
  12202. wolfSSL_ASN1_TIME_free(notAfter);
  12203. return EXPECT_RESULT();
  12204. }
  12205. /* override certificate version error */
  12206. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  12207. {
  12208. EXPECT_DECLS;
  12209. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12210. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  12211. #else
  12212. ExpectIntEQ(store->error, 0);
  12213. #endif
  12214. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  12215. (void)preverify;
  12216. return EXPECT_RESULT() == TEST_SUCCESS;
  12217. }
  12218. /* set verify callback that will override bad certificate version */
  12219. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  12220. {
  12221. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  12222. return TEST_SUCCESS;
  12223. }
  12224. #endif
  12225. static int test_wolfSSL_X509_TLS_version_test_1(void)
  12226. {
  12227. EXPECT_DECLS;
  12228. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12229. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12230. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12231. test_ssl_cbf func_cb_client;
  12232. test_ssl_cbf func_cb_server;
  12233. /* test server rejects a client certificate that is not version 3 */
  12234. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12235. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12236. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12237. #ifndef WOLFSSL_NO_TLS12
  12238. func_cb_client.method = wolfTLSv1_2_client_method;
  12239. #else
  12240. func_cb_client.method = wolfTLSv1_3_client_method;
  12241. #endif
  12242. #ifndef WOLFSSL_NO_TLS12
  12243. func_cb_server.method = wolfTLSv1_2_server_method;
  12244. #else
  12245. func_cb_server.method = wolfTLSv1_3_server_method;
  12246. #endif
  12247. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12248. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12249. &func_cb_server, NULL), -1001);
  12250. #else
  12251. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12252. &func_cb_server, NULL), TEST_SUCCESS);
  12253. #endif
  12254. #endif
  12255. return EXPECT_RESULT();
  12256. }
  12257. static int test_wolfSSL_X509_TLS_version_test_2(void)
  12258. {
  12259. EXPECT_DECLS;
  12260. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12261. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12262. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12263. test_ssl_cbf func_cb_client;
  12264. test_ssl_cbf func_cb_server;
  12265. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12266. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12267. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12268. func_cb_server.ctx_ready = &test_set_override_x509;
  12269. #ifndef WOLFSSL_NO_TLS12
  12270. func_cb_client.method = wolfTLSv1_2_client_method;
  12271. #else
  12272. func_cb_client.method = wolfTLSv1_3_client_method;
  12273. #endif
  12274. #ifndef WOLFSSL_NO_TLS12
  12275. func_cb_server.method = wolfTLSv1_2_server_method;
  12276. #else
  12277. func_cb_server.method = wolfTLSv1_3_server_method;
  12278. #endif
  12279. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12280. &func_cb_server, NULL), TEST_SUCCESS);
  12281. #endif
  12282. return EXPECT_RESULT();
  12283. }
  12284. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  12285. * version allowed.
  12286. * POST: 1 on success.
  12287. */
  12288. static int test_wolfSSL_CTX_SetMinVersion(void)
  12289. {
  12290. int res = TEST_SKIPPED;
  12291. #ifndef NO_WOLFSSL_CLIENT
  12292. int failFlag = WOLFSSL_SUCCESS;
  12293. WOLFSSL_CTX* ctx;
  12294. int itr;
  12295. #ifndef NO_OLD_TLS
  12296. const int versions[] = {
  12297. #ifdef WOLFSSL_ALLOW_TLSV10
  12298. WOLFSSL_TLSV1,
  12299. #endif
  12300. WOLFSSL_TLSV1_1,
  12301. WOLFSSL_TLSV1_2 };
  12302. #elif !defined(WOLFSSL_NO_TLS12)
  12303. const int versions[] = { WOLFSSL_TLSV1_2 };
  12304. #elif defined(WOLFSSL_TLS13)
  12305. const int versions[] = { WOLFSSL_TLSV1_3 };
  12306. #else
  12307. const int versions[0];
  12308. #endif
  12309. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  12310. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  12311. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  12312. != WOLFSSL_SUCCESS) {
  12313. failFlag = WOLFSSL_FAILURE;
  12314. }
  12315. }
  12316. wolfSSL_CTX_free(ctx);
  12317. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  12318. #endif
  12319. return res;
  12320. } /* END test_wolfSSL_CTX_SetMinVersion */
  12321. /*----------------------------------------------------------------------------*
  12322. | OCSP Stapling
  12323. *----------------------------------------------------------------------------*/
  12324. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  12325. * need to contact the CA, lowering the cost of cert revocation checking.
  12326. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  12327. * POST: 1 returned for success.
  12328. */
  12329. static int test_wolfSSL_UseOCSPStapling(void)
  12330. {
  12331. EXPECT_DECLS;
  12332. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  12333. !defined(NO_WOLFSSL_CLIENT)
  12334. WOLFSSL_CTX* ctx = NULL;
  12335. WOLFSSL* ssl = NULL;
  12336. #ifndef NO_WOLFSSL_CLIENT
  12337. #ifndef WOLFSSL_NO_TLS12
  12338. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12339. #else
  12340. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12341. #endif
  12342. #else
  12343. #ifndef WOLFSSL_NO_TLS12
  12344. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12345. #else
  12346. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12347. #endif
  12348. #endif
  12349. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12350. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  12351. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12352. #ifndef NO_WOLFSSL_CLIENT
  12353. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12354. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12355. #else
  12356. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12357. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12358. #endif
  12359. wolfSSL_free(ssl);
  12360. wolfSSL_CTX_free(ctx);
  12361. #endif
  12362. return EXPECT_RESULT();
  12363. } /* END test_wolfSSL_UseOCSPStapling */
  12364. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  12365. * stapling eliminates the need to contact the CA and lowers cert revocation
  12366. * check.
  12367. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  12368. */
  12369. static int test_wolfSSL_UseOCSPStaplingV2(void)
  12370. {
  12371. EXPECT_DECLS;
  12372. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  12373. !defined(NO_WOLFSSL_CLIENT)
  12374. WOLFSSL_CTX* ctx = NULL;
  12375. WOLFSSL* ssl = NULL;
  12376. #ifndef NO_WOLFSSL_CLIENT
  12377. #ifndef WOLFSSL_NO_TLS12
  12378. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12379. #else
  12380. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12381. #endif
  12382. #else
  12383. #ifndef WOLFSSL_NO_TLS12
  12384. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12385. #else
  12386. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12387. #endif
  12388. #endif
  12389. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12390. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  12391. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12392. #ifndef NO_WOLFSSL_CLIENT
  12393. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12394. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12395. #else
  12396. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12397. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12398. #endif
  12399. wolfSSL_free(ssl);
  12400. wolfSSL_CTX_free(ctx);
  12401. #endif
  12402. return EXPECT_RESULT();
  12403. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  12404. /*----------------------------------------------------------------------------*
  12405. | Multicast Tests
  12406. *----------------------------------------------------------------------------*/
  12407. static int test_wolfSSL_mcast(void)
  12408. {
  12409. EXPECT_DECLS;
  12410. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  12411. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  12412. WOLFSSL_CTX* ctx = NULL;
  12413. WOLFSSL* ssl = NULL;
  12414. byte preMasterSecret[512];
  12415. byte clientRandom[32];
  12416. byte serverRandom[32];
  12417. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  12418. byte buf[256];
  12419. word16 newId;
  12420. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  12421. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  12422. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12423. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  12424. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  12425. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  12426. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  12427. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  12428. WOLFSSL_SUCCESS);
  12429. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  12430. ExpectIntLE(newId, 100);
  12431. wolfSSL_free(ssl);
  12432. wolfSSL_CTX_free(ctx);
  12433. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  12434. * WOLFSSL_SNIFFER) */
  12435. return EXPECT_RESULT();
  12436. }
  12437. /*----------------------------------------------------------------------------*
  12438. | Wolfcrypt
  12439. *----------------------------------------------------------------------------*/
  12440. /*
  12441. * Unit test for the wc_InitBlake2b()
  12442. */
  12443. static int test_wc_InitBlake2b(void)
  12444. {
  12445. EXPECT_DECLS;
  12446. #ifdef HAVE_BLAKE2
  12447. Blake2b blake;
  12448. /* Test good arg. */
  12449. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12450. /* Test bad arg. */
  12451. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12452. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12453. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12454. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12455. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12456. #endif
  12457. return EXPECT_RESULT();
  12458. } /* END test_wc_InitBlake2b*/
  12459. /*
  12460. * Unit test for the wc_InitBlake2b_WithKey()
  12461. */
  12462. static int test_wc_InitBlake2b_WithKey(void)
  12463. {
  12464. EXPECT_DECLS;
  12465. #ifdef HAVE_BLAKE2
  12466. Blake2b blake;
  12467. word32 digestSz = BLAKE2B_KEYBYTES;
  12468. byte key[BLAKE2B_KEYBYTES];
  12469. word32 keylen = BLAKE2B_KEYBYTES;
  12470. XMEMSET(key, 0, sizeof(key));
  12471. /* Test good arg. */
  12472. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12473. /* Test bad args. */
  12474. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12475. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12476. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12478. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12479. #endif
  12480. return EXPECT_RESULT();
  12481. } /* END wc_InitBlake2b_WithKey*/
  12482. /*
  12483. * Unit test for the wc_InitBlake2s_WithKey()
  12484. */
  12485. static int test_wc_InitBlake2s_WithKey(void)
  12486. {
  12487. EXPECT_DECLS;
  12488. #ifdef HAVE_BLAKE2S
  12489. Blake2s blake;
  12490. word32 digestSz = BLAKE2S_KEYBYTES;
  12491. byte *key = (byte*)"01234567890123456789012345678901";
  12492. word32 keylen = BLAKE2S_KEYBYTES;
  12493. /* Test good arg. */
  12494. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12495. /* Test bad args. */
  12496. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12497. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12498. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12499. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12500. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12501. #endif
  12502. return EXPECT_RESULT();
  12503. } /* END wc_InitBlake2s_WithKey*/
  12504. /*
  12505. * Unit test for the wc_InitMd5()
  12506. */
  12507. static int test_wc_InitMd5(void)
  12508. {
  12509. EXPECT_DECLS;
  12510. #ifndef NO_MD5
  12511. wc_Md5 md5;
  12512. /* Test good arg. */
  12513. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12514. /* Test bad arg. */
  12515. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12516. wc_Md5Free(&md5);
  12517. #endif
  12518. return EXPECT_RESULT();
  12519. } /* END test_wc_InitMd5 */
  12520. /*
  12521. * Testing wc_UpdateMd5()
  12522. */
  12523. static int test_wc_Md5Update(void)
  12524. {
  12525. EXPECT_DECLS;
  12526. #ifndef NO_MD5
  12527. wc_Md5 md5;
  12528. byte hash[WC_MD5_DIGEST_SIZE];
  12529. testVector a, b, c;
  12530. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12531. /* Input */
  12532. a.input = "a";
  12533. a.inLen = XSTRLEN(a.input);
  12534. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12535. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12536. /* Update input. */
  12537. a.input = "abc";
  12538. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12539. "\x72";
  12540. a.inLen = XSTRLEN(a.input);
  12541. a.outLen = XSTRLEN(a.output);
  12542. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12543. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12544. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12545. /* Pass in bad values. */
  12546. b.input = NULL;
  12547. b.inLen = 0;
  12548. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12549. c.input = NULL;
  12550. c.inLen = WC_MD5_DIGEST_SIZE;
  12551. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12552. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12553. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12554. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12555. wc_Md5Free(&md5);
  12556. #endif
  12557. return EXPECT_RESULT();
  12558. } /* END test_wc_Md5Update() */
  12559. /*
  12560. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12561. */
  12562. static int test_wc_Md5Final(void)
  12563. {
  12564. EXPECT_DECLS;
  12565. #ifndef NO_MD5
  12566. /* Instantiate */
  12567. wc_Md5 md5;
  12568. byte* hash_test[3];
  12569. byte hash1[WC_MD5_DIGEST_SIZE];
  12570. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12571. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12572. int times, i;
  12573. /* Initialize */
  12574. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12575. hash_test[0] = hash1;
  12576. hash_test[1] = hash2;
  12577. hash_test[2] = hash3;
  12578. times = sizeof(hash_test)/sizeof(byte*);
  12579. for (i = 0; i < times; i++) {
  12580. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12581. }
  12582. /* Test bad args. */
  12583. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12584. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12585. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12586. wc_Md5Free(&md5);
  12587. #endif
  12588. return EXPECT_RESULT();
  12589. }
  12590. /*
  12591. * Unit test for the wc_InitSha()
  12592. */
  12593. static int test_wc_InitSha(void)
  12594. {
  12595. EXPECT_DECLS;
  12596. #ifndef NO_SHA
  12597. wc_Sha sha;
  12598. /* Test good arg. */
  12599. ExpectIntEQ(wc_InitSha(&sha), 0);
  12600. /* Test bad arg. */
  12601. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12602. wc_ShaFree(&sha);
  12603. #endif
  12604. return EXPECT_RESULT();
  12605. } /* END test_wc_InitSha */
  12606. /*
  12607. * Tesing wc_ShaUpdate()
  12608. */
  12609. static int test_wc_ShaUpdate(void)
  12610. {
  12611. EXPECT_DECLS;
  12612. #ifndef NO_SHA
  12613. wc_Sha sha;
  12614. byte hash[WC_SHA_DIGEST_SIZE];
  12615. testVector a, b, c;
  12616. ExpectIntEQ(wc_InitSha(&sha), 0);
  12617. /* Input. */
  12618. a.input = "a";
  12619. a.inLen = XSTRLEN(a.input);
  12620. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12621. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12622. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12623. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12624. /* Update input. */
  12625. a.input = "abc";
  12626. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12627. "\x6C\x9C\xD0\xD8\x9D";
  12628. a.inLen = XSTRLEN(a.input);
  12629. a.outLen = XSTRLEN(a.output);
  12630. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12631. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12632. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12633. /* Try passing in bad values. */
  12634. b.input = NULL;
  12635. b.inLen = 0;
  12636. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12637. c.input = NULL;
  12638. c.inLen = WC_SHA_DIGEST_SIZE;
  12639. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12640. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12641. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12642. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12643. wc_ShaFree(&sha);
  12644. #endif
  12645. return EXPECT_RESULT();
  12646. } /* END test_wc_ShaUpdate() */
  12647. /*
  12648. * Unit test on wc_ShaFinal
  12649. */
  12650. static int test_wc_ShaFinal(void)
  12651. {
  12652. EXPECT_DECLS;
  12653. #ifndef NO_SHA
  12654. wc_Sha sha;
  12655. byte* hash_test[3];
  12656. byte hash1[WC_SHA_DIGEST_SIZE];
  12657. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12658. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12659. int times, i;
  12660. /* Initialize*/
  12661. ExpectIntEQ(wc_InitSha(&sha), 0);
  12662. hash_test[0] = hash1;
  12663. hash_test[1] = hash2;
  12664. hash_test[2] = hash3;
  12665. times = sizeof(hash_test)/sizeof(byte*);
  12666. for (i = 0; i < times; i++) {
  12667. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12668. }
  12669. /* Test bad args. */
  12670. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12671. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12672. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12673. wc_ShaFree(&sha);
  12674. #endif
  12675. return EXPECT_RESULT();
  12676. } /* END test_wc_ShaFinal */
  12677. /*
  12678. * Unit test for wc_InitSha256()
  12679. */
  12680. static int test_wc_InitSha256(void)
  12681. {
  12682. EXPECT_DECLS;
  12683. #ifndef NO_SHA256
  12684. wc_Sha256 sha256;
  12685. /* Test good arg. */
  12686. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12687. /* Test bad arg. */
  12688. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12689. wc_Sha256Free(&sha256);
  12690. #endif
  12691. return EXPECT_RESULT();
  12692. } /* END test_wc_InitSha256 */
  12693. /*
  12694. * Unit test for wc_Sha256Update()
  12695. */
  12696. static int test_wc_Sha256Update(void)
  12697. {
  12698. EXPECT_DECLS;
  12699. #ifndef NO_SHA256
  12700. wc_Sha256 sha256;
  12701. byte hash[WC_SHA256_DIGEST_SIZE];
  12702. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12703. testVector a, b, c;
  12704. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12705. /* Input. */
  12706. a.input = "a";
  12707. a.inLen = XSTRLEN(a.input);
  12708. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12709. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12710. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12711. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12712. /* Update input. */
  12713. a.input = "abc";
  12714. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12715. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12716. "\x15\xAD";
  12717. a.inLen = XSTRLEN(a.input);
  12718. a.outLen = XSTRLEN(a.output);
  12719. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12720. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12721. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12722. /* Unaligned check. */
  12723. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12724. 0);
  12725. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12726. /* Try passing in bad values */
  12727. b.input = NULL;
  12728. b.inLen = 0;
  12729. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12730. c.input = NULL;
  12731. c.inLen = WC_SHA256_DIGEST_SIZE;
  12732. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12733. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12734. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12735. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12736. wc_Sha256Free(&sha256);
  12737. #endif
  12738. return EXPECT_RESULT();
  12739. } /* END test_wc_Sha256Update */
  12740. /*
  12741. * Unit test function for wc_Sha256Final()
  12742. */
  12743. static int test_wc_Sha256Final(void)
  12744. {
  12745. EXPECT_DECLS;
  12746. #ifndef NO_SHA256
  12747. wc_Sha256 sha256;
  12748. byte* hash_test[3];
  12749. byte hash1[WC_SHA256_DIGEST_SIZE];
  12750. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12751. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12752. int times, i;
  12753. /* Initialize */
  12754. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12755. hash_test[0] = hash1;
  12756. hash_test[1] = hash2;
  12757. hash_test[2] = hash3;
  12758. times = sizeof(hash_test) / sizeof(byte*);
  12759. for (i = 0; i < times; i++) {
  12760. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12761. }
  12762. /* Test bad args. */
  12763. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12764. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12765. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12766. wc_Sha256Free(&sha256);
  12767. #endif
  12768. return EXPECT_RESULT();
  12769. } /* END test_wc_Sha256Final */
  12770. /*
  12771. * Unit test function for wc_Sha256FinalRaw()
  12772. */
  12773. static int test_wc_Sha256FinalRaw(void)
  12774. {
  12775. EXPECT_DECLS;
  12776. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12777. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12778. !defined(WOLFSSL_NO_HASH_RAW)
  12779. wc_Sha256 sha256;
  12780. byte* hash_test[3];
  12781. byte hash1[WC_SHA256_DIGEST_SIZE];
  12782. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12783. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12784. int times, i;
  12785. /* Initialize */
  12786. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12787. hash_test[0] = hash1;
  12788. hash_test[1] = hash2;
  12789. hash_test[2] = hash3;
  12790. times = sizeof(hash_test) / sizeof(byte*);
  12791. for (i = 0; i < times; i++) {
  12792. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12793. }
  12794. /* Test bad args. */
  12795. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12796. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12797. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12798. wc_Sha256Free(&sha256);
  12799. #endif
  12800. return EXPECT_RESULT();
  12801. } /* END test_wc_Sha256FinalRaw */
  12802. /*
  12803. * Unit test function for wc_Sha256GetFlags()
  12804. */
  12805. static int test_wc_Sha256GetFlags(void)
  12806. {
  12807. EXPECT_DECLS;
  12808. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12809. wc_Sha256 sha256;
  12810. word32 flags = 0;
  12811. /* Initialize */
  12812. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12813. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12814. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12815. wc_Sha256Free(&sha256);
  12816. #endif
  12817. return EXPECT_RESULT();
  12818. } /* END test_wc_Sha256GetFlags */
  12819. /*
  12820. * Unit test function for wc_Sha256Free()
  12821. */
  12822. static int test_wc_Sha256Free(void)
  12823. {
  12824. EXPECT_DECLS;
  12825. #ifndef NO_SHA256
  12826. wc_Sha256Free(NULL);
  12827. /* Set result to SUCCESS. */
  12828. ExpectTrue(1);
  12829. #endif
  12830. return EXPECT_RESULT();
  12831. } /* END test_wc_Sha256Free */
  12832. /*
  12833. * Unit test function for wc_Sha256GetHash()
  12834. */
  12835. static int test_wc_Sha256GetHash(void)
  12836. {
  12837. EXPECT_DECLS;
  12838. #ifndef NO_SHA256
  12839. wc_Sha256 sha256;
  12840. byte hash1[WC_SHA256_DIGEST_SIZE];
  12841. /* Initialize */
  12842. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12843. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12844. /* test bad arguments*/
  12845. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12846. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12847. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12848. wc_Sha256Free(&sha256);
  12849. #endif
  12850. return EXPECT_RESULT();
  12851. } /* END test_wc_Sha256GetHash */
  12852. /*
  12853. * Unit test function for wc_Sha256Copy()
  12854. */
  12855. static int test_wc_Sha256Copy(void)
  12856. {
  12857. EXPECT_DECLS;
  12858. #ifndef NO_SHA256
  12859. wc_Sha256 sha256;
  12860. wc_Sha256 temp;
  12861. XMEMSET(&sha256, 0, sizeof(sha256));
  12862. XMEMSET(&temp, 0, sizeof(temp));
  12863. /* Initialize */
  12864. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12865. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12866. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12867. /* test bad arguments*/
  12868. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12869. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12870. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12871. wc_Sha256Free(&sha256);
  12872. wc_Sha256Free(&temp);
  12873. #endif
  12874. return EXPECT_RESULT();
  12875. } /* END test_wc_Sha256Copy */
  12876. /*
  12877. * Testing wc_InitSha512()
  12878. */
  12879. static int test_wc_InitSha512(void)
  12880. {
  12881. EXPECT_DECLS;
  12882. #ifdef WOLFSSL_SHA512
  12883. wc_Sha512 sha512;
  12884. /* Test good arg. */
  12885. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12886. /* Test bad arg. */
  12887. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12888. wc_Sha512Free(&sha512);
  12889. #endif
  12890. return EXPECT_RESULT();
  12891. } /* END test_wc_InitSha512 */
  12892. /*
  12893. * wc_Sha512Update() test.
  12894. */
  12895. static int test_wc_Sha512Update(void)
  12896. {
  12897. EXPECT_DECLS;
  12898. #ifdef WOLFSSL_SHA512
  12899. wc_Sha512 sha512;
  12900. byte hash[WC_SHA512_DIGEST_SIZE];
  12901. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  12902. testVector a, b, c;
  12903. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12904. /* Input. */
  12905. a.input = "a";
  12906. a.inLen = XSTRLEN(a.input);
  12907. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  12908. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  12909. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  12910. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12911. /* Update input. */
  12912. a.input = "abc";
  12913. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  12914. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  12915. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  12916. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  12917. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  12918. a.inLen = XSTRLEN(a.input);
  12919. a.outLen = XSTRLEN(a.output);
  12920. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  12921. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12922. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  12923. /* Unaligned check. */
  12924. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  12925. 0);
  12926. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  12927. /* Try passing in bad values */
  12928. b.input = NULL;
  12929. b.inLen = 0;
  12930. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  12931. c.input = NULL;
  12932. c.inLen = WC_SHA512_DIGEST_SIZE;
  12933. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12934. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12935. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  12936. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12937. wc_Sha512Free(&sha512);
  12938. #endif
  12939. return EXPECT_RESULT();
  12940. } /* END test_wc_Sha512Update */
  12941. #ifdef WOLFSSL_SHA512
  12942. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12943. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12944. /* Performs test for
  12945. * - wc_Sha512Final/wc_Sha512FinalRaw
  12946. * - wc_Sha512_224Final/wc_Sha512_224Final
  12947. * - wc_Sha512_256Final/wc_Sha512_256Final
  12948. * parameter:
  12949. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  12950. * WC_HASH_TYPE_SHA512_256
  12951. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  12952. *return 0 on success
  12953. */
  12954. static int test_Sha512_Family_Final(int type, int isRaw)
  12955. {
  12956. EXPECT_DECLS;
  12957. wc_Sha512 sha512;
  12958. byte* hash_test[3];
  12959. byte hash1[WC_SHA512_DIGEST_SIZE];
  12960. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12961. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12962. int times, i;
  12963. int(*initFp)(wc_Sha512*);
  12964. int(*finalFp)(wc_Sha512*, byte*);
  12965. void(*freeFp)(wc_Sha512*);
  12966. if (type == WC_HASH_TYPE_SHA512) {
  12967. initFp = wc_InitSha512;
  12968. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12969. !defined(WOLFSSL_NO_HASH_RAW)
  12970. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  12971. #else
  12972. finalFp = (isRaw)? NULL : wc_Sha512Final;
  12973. #endif
  12974. freeFp = wc_Sha512Free;
  12975. }
  12976. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12977. #if !defined(WOLFSSL_NOSHA512_224)
  12978. else if (type == WC_HASH_TYPE_SHA512_224) {
  12979. initFp = wc_InitSha512_224;
  12980. #if !defined(WOLFSSL_NO_HASH_RAW)
  12981. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  12982. #else
  12983. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  12984. #endif
  12985. freeFp = wc_Sha512_224Free;
  12986. }
  12987. #endif
  12988. #if !defined(WOLFSSL_NOSHA512_256)
  12989. else if (type == WC_HASH_TYPE_SHA512_256) {
  12990. initFp = wc_InitSha512_256;
  12991. #if !defined(WOLFSSL_NO_HASH_RAW)
  12992. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  12993. #else
  12994. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  12995. #endif
  12996. freeFp = wc_Sha512_256Free;
  12997. }
  12998. #endif
  12999. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13000. else
  13001. return TEST_FAIL;
  13002. /* Initialize */
  13003. ExpectIntEQ(initFp(&sha512), 0);
  13004. hash_test[0] = hash1;
  13005. hash_test[1] = hash2;
  13006. hash_test[2] = hash3;
  13007. times = sizeof(hash_test) / sizeof(byte *);
  13008. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \
  13009. defined(WOLFSSL_NO_HASH_RAW)
  13010. if (finalFp != NULL)
  13011. #endif
  13012. {
  13013. /* Good test args. */
  13014. for (i = 0; i < times; i++) {
  13015. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  13016. }
  13017. /* Test bad args. */
  13018. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13019. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13020. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13021. }
  13022. freeFp(&sha512);
  13023. return EXPECT_RESULT();
  13024. }
  13025. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13026. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13027. #endif /* WOLFSSL_SHA512 */
  13028. /*
  13029. * Unit test function for wc_Sha512Final()
  13030. */
  13031. static int test_wc_Sha512Final(void)
  13032. {
  13033. EXPECT_DECLS;
  13034. #ifdef WOLFSSL_SHA512
  13035. wc_Sha512 sha512;
  13036. byte* hash_test[3];
  13037. byte hash1[WC_SHA512_DIGEST_SIZE];
  13038. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13039. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13040. int times, i;
  13041. /* Initialize */
  13042. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13043. hash_test[0] = hash1;
  13044. hash_test[1] = hash2;
  13045. hash_test[2] = hash3;
  13046. times = sizeof(hash_test) / sizeof(byte *);
  13047. for (i = 0; i < times; i++) {
  13048. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  13049. }
  13050. /* Test bad args. */
  13051. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13052. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13053. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13054. wc_Sha512Free(&sha512);
  13055. #endif
  13056. return EXPECT_RESULT();
  13057. } /* END test_wc_Sha512Final */
  13058. /*
  13059. * Unit test function for wc_Sha512GetFlags()
  13060. */
  13061. static int test_wc_Sha512GetFlags(void)
  13062. {
  13063. EXPECT_DECLS;
  13064. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  13065. wc_Sha512 sha512;
  13066. word32 flags = 0;
  13067. /* Initialize */
  13068. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13069. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  13070. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  13071. wc_Sha512Free(&sha512);
  13072. #endif
  13073. return EXPECT_RESULT();
  13074. } /* END test_wc_Sha512GetFlags */
  13075. /*
  13076. * Unit test function for wc_Sha512FinalRaw()
  13077. */
  13078. static int test_wc_Sha512FinalRaw(void)
  13079. {
  13080. EXPECT_DECLS;
  13081. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13082. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13083. !defined(WOLFSSL_NO_HASH_RAW)
  13084. wc_Sha512 sha512;
  13085. byte* hash_test[3];
  13086. byte hash1[WC_SHA512_DIGEST_SIZE];
  13087. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13088. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13089. int times, i;
  13090. /* Initialize */
  13091. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13092. hash_test[0] = hash1;
  13093. hash_test[1] = hash2;
  13094. hash_test[2] = hash3;
  13095. times = sizeof(hash_test) / sizeof(byte*);
  13096. /* Good test args. */
  13097. for (i = 0; i < times; i++) {
  13098. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  13099. }
  13100. /* Test bad args. */
  13101. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13102. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13103. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13104. wc_Sha512Free(&sha512);
  13105. #endif
  13106. return EXPECT_RESULT();
  13107. } /* END test_wc_Sha512FinalRaw */
  13108. /*
  13109. * Unit test function for wc_Sha512Free()
  13110. */
  13111. static int test_wc_Sha512Free(void)
  13112. {
  13113. EXPECT_DECLS;
  13114. #ifdef WOLFSSL_SHA512
  13115. wc_Sha512Free(NULL);
  13116. /* Set result to SUCCESS. */
  13117. ExpectTrue(1);
  13118. #endif
  13119. return EXPECT_RESULT();
  13120. } /* END test_wc_Sha512Free */
  13121. #ifdef WOLFSSL_SHA512
  13122. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13123. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  13124. static int test_Sha512_Family_GetHash(int type )
  13125. {
  13126. EXPECT_DECLS;
  13127. int(*initFp)(wc_Sha512*);
  13128. int(*ghashFp)(wc_Sha512*, byte*);
  13129. wc_Sha512 sha512;
  13130. byte hash1[WC_SHA512_DIGEST_SIZE];
  13131. if (type == WC_HASH_TYPE_SHA512) {
  13132. initFp = wc_InitSha512;
  13133. ghashFp = wc_Sha512GetHash;
  13134. }
  13135. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13136. #if !defined(WOLFSSL_NOSHA512_224)
  13137. else if (type == WC_HASH_TYPE_SHA512_224) {
  13138. initFp = wc_InitSha512_224;
  13139. ghashFp = wc_Sha512_224GetHash;
  13140. }
  13141. #endif
  13142. #if !defined(WOLFSSL_NOSHA512_256)
  13143. else if (type == WC_HASH_TYPE_SHA512_256) {
  13144. initFp = wc_InitSha512_256;
  13145. ghashFp = wc_Sha512_256GetHash;
  13146. }
  13147. #endif
  13148. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13149. else {
  13150. initFp = NULL;
  13151. ghashFp = NULL;
  13152. }
  13153. if (initFp == NULL || ghashFp == NULL)
  13154. return TEST_FAIL;
  13155. ExpectIntEQ(initFp(&sha512), 0);
  13156. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  13157. /* test bad arguments*/
  13158. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13159. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13160. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13161. wc_Sha512Free(&sha512);
  13162. return EXPECT_RESULT();
  13163. }
  13164. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13165. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13166. #endif /* WOLFSSL_SHA512 */
  13167. /*
  13168. * Unit test function for wc_Sha512GetHash()
  13169. */
  13170. static int test_wc_Sha512GetHash(void)
  13171. {
  13172. EXPECT_DECLS;
  13173. #ifdef WOLFSSL_SHA512
  13174. wc_Sha512 sha512;
  13175. byte hash1[WC_SHA512_DIGEST_SIZE];
  13176. /* Initialize */
  13177. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13178. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  13179. /* test bad arguments*/
  13180. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13181. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13182. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13183. wc_Sha512Free(&sha512);
  13184. #endif
  13185. return EXPECT_RESULT();
  13186. } /* END test_wc_Sha512GetHash */
  13187. /*
  13188. * Unit test function for wc_Sha512Copy()
  13189. */
  13190. static int test_wc_Sha512Copy(void)
  13191. {
  13192. EXPECT_DECLS;
  13193. #ifdef WOLFSSL_SHA512
  13194. wc_Sha512 sha512;
  13195. wc_Sha512 temp;
  13196. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13197. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13198. /* Initialize */
  13199. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13200. ExpectIntEQ(wc_InitSha512(&temp), 0);
  13201. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  13202. /* test bad arguments*/
  13203. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13204. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13205. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13206. wc_Sha512Free(&sha512);
  13207. wc_Sha512Free(&temp);
  13208. #endif
  13209. return EXPECT_RESULT();
  13210. } /* END test_wc_Sha512Copy */
  13211. static int test_wc_InitSha512_224(void)
  13212. {
  13213. EXPECT_DECLS;
  13214. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13215. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13216. wc_Sha512 sha512;
  13217. /* Test good arg. */
  13218. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13219. /* Test bad arg. */
  13220. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13221. wc_Sha512_224Free(&sha512);
  13222. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13223. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13224. return EXPECT_RESULT();
  13225. }
  13226. static int test_wc_Sha512_224Update(void)
  13227. {
  13228. EXPECT_DECLS;
  13229. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13230. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13231. wc_Sha512 sha512;
  13232. byte hash[WC_SHA512_DIGEST_SIZE];
  13233. testVector a, c;
  13234. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13235. /* Input. */
  13236. a.input = "a";
  13237. a.inLen = XSTRLEN(a.input);
  13238. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  13239. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  13240. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13241. 0);
  13242. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13243. /* Update input. */
  13244. a.input = "abc";
  13245. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  13246. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  13247. a.inLen = XSTRLEN(a.input);
  13248. a.outLen = XSTRLEN(a.output);
  13249. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13250. 0);
  13251. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13252. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  13253. c.input = NULL;
  13254. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  13255. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13256. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13257. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13258. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13259. wc_Sha512_224Free(&sha512);
  13260. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13261. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13262. return EXPECT_RESULT();
  13263. }
  13264. static int test_wc_Sha512_224Final(void)
  13265. {
  13266. EXPECT_DECLS;
  13267. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13268. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13269. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  13270. TEST_SUCCESS);
  13271. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13272. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13273. return EXPECT_RESULT();
  13274. }
  13275. static int test_wc_Sha512_224GetFlags(void)
  13276. {
  13277. EXPECT_DECLS;
  13278. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13279. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  13280. wc_Sha512 sha512;
  13281. wc_Sha512 copy;
  13282. word32 flags = 0;
  13283. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13284. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13285. /* Initialize */
  13286. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13287. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  13288. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  13289. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13290. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  13291. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  13292. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13293. wc_Sha512_224Free(&copy);
  13294. wc_Sha512_224Free(&sha512);
  13295. #endif
  13296. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13297. return EXPECT_RESULT();
  13298. }
  13299. static int test_wc_Sha512_224FinalRaw(void)
  13300. {
  13301. EXPECT_DECLS;
  13302. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13303. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  13304. !defined(WOLFSSL_NO_HASH_RAW)
  13305. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  13306. TEST_SUCCESS);
  13307. #endif
  13308. return EXPECT_RESULT();
  13309. }
  13310. static int test_wc_Sha512_224Free(void)
  13311. {
  13312. EXPECT_DECLS;
  13313. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13314. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13315. wc_Sha512_224Free(NULL);
  13316. /* Set result to SUCCESS. */
  13317. ExpectTrue(1);
  13318. #endif
  13319. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13320. return EXPECT_RESULT();
  13321. }
  13322. static int test_wc_Sha512_224GetHash(void)
  13323. {
  13324. EXPECT_DECLS;
  13325. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13326. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13327. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  13328. TEST_SUCCESS);
  13329. #endif
  13330. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13331. return EXPECT_RESULT();
  13332. }
  13333. static int test_wc_Sha512_224Copy(void)
  13334. {
  13335. EXPECT_DECLS;
  13336. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13337. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13338. wc_Sha512 sha512;
  13339. wc_Sha512 temp;
  13340. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13341. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13342. /* Initialize */
  13343. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13344. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  13345. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  13346. /* test bad arguments*/
  13347. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13348. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13349. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13350. wc_Sha512_224Free(&sha512);
  13351. wc_Sha512_224Free(&temp);
  13352. #endif
  13353. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13354. return EXPECT_RESULT();
  13355. }
  13356. static int test_wc_InitSha512_256(void)
  13357. {
  13358. EXPECT_DECLS;
  13359. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13360. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13361. wc_Sha512 sha512;
  13362. /* Test good arg. */
  13363. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13364. /* Test bad arg. */
  13365. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13366. wc_Sha512_256Free(&sha512);
  13367. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13368. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13369. return EXPECT_RESULT();
  13370. }
  13371. static int test_wc_Sha512_256Update(void)
  13372. {
  13373. EXPECT_DECLS;
  13374. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13375. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13376. wc_Sha512 sha512;
  13377. byte hash[WC_SHA512_DIGEST_SIZE];
  13378. testVector a, c;
  13379. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13380. /* Input. */
  13381. a.input = "a";
  13382. a.inLen = XSTRLEN(a.input);
  13383. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  13384. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  13385. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13386. 0);
  13387. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13388. /* Update input. */
  13389. a.input = "abc";
  13390. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  13391. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  13392. "\x07\xe7\xaf\x23";
  13393. a.inLen = XSTRLEN(a.input);
  13394. a.outLen = XSTRLEN(a.output);
  13395. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13396. 0);
  13397. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13398. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  13399. c.input = NULL;
  13400. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  13401. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13402. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13403. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  13404. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13405. wc_Sha512_256Free(&sha512);
  13406. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13407. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13408. return EXPECT_RESULT();
  13409. }
  13410. static int test_wc_Sha512_256Final(void)
  13411. {
  13412. EXPECT_DECLS;
  13413. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13414. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13415. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  13416. TEST_SUCCESS);
  13417. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13418. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13419. return EXPECT_RESULT();
  13420. }
  13421. static int test_wc_Sha512_256GetFlags(void)
  13422. {
  13423. EXPECT_DECLS;
  13424. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13425. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  13426. wc_Sha512 sha512, copy;
  13427. word32 flags = 0;
  13428. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13429. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13430. /* Initialize */
  13431. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13432. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  13433. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  13434. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13435. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  13436. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  13437. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13438. wc_Sha512_256Free(&sha512);
  13439. #endif
  13440. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13441. return EXPECT_RESULT();
  13442. }
  13443. static int test_wc_Sha512_256FinalRaw(void)
  13444. {
  13445. EXPECT_DECLS;
  13446. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13447. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13448. !defined(WOLFSSL_NO_HASH_RAW)
  13449. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13450. TEST_SUCCESS);
  13451. #endif
  13452. return EXPECT_RESULT();
  13453. }
  13454. static int test_wc_Sha512_256Free(void)
  13455. {
  13456. EXPECT_DECLS;
  13457. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13458. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13459. wc_Sha512_256Free(NULL);
  13460. /* Set result to SUCCESS. */
  13461. ExpectTrue(1);
  13462. #endif
  13463. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13464. return EXPECT_RESULT();
  13465. }
  13466. static int test_wc_Sha512_256GetHash(void)
  13467. {
  13468. EXPECT_DECLS;
  13469. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13470. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13471. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13472. TEST_SUCCESS);
  13473. #endif
  13474. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13475. return EXPECT_RESULT();
  13476. }
  13477. static int test_wc_Sha512_256Copy(void)
  13478. {
  13479. EXPECT_DECLS;
  13480. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13481. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13482. wc_Sha512 sha512;
  13483. wc_Sha512 temp;
  13484. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13485. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13486. /* Initialize */
  13487. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13488. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13489. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13490. /* test bad arguments*/
  13491. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13492. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13493. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13494. wc_Sha512_256Free(&sha512);
  13495. wc_Sha512_256Free(&temp);
  13496. #endif
  13497. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13498. return EXPECT_RESULT();
  13499. }
  13500. /*
  13501. * Testing wc_InitSha384()
  13502. */
  13503. static int test_wc_InitSha384(void)
  13504. {
  13505. EXPECT_DECLS;
  13506. #ifdef WOLFSSL_SHA384
  13507. wc_Sha384 sha384;
  13508. /* Test good arg. */
  13509. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13510. /* Test bad arg. */
  13511. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13512. wc_Sha384Free(&sha384);
  13513. #endif
  13514. return EXPECT_RESULT();
  13515. } /* END test_wc_InitSha384 */
  13516. /*
  13517. * test wc_Sha384Update()
  13518. */
  13519. static int test_wc_Sha384Update(void)
  13520. {
  13521. EXPECT_DECLS;
  13522. #ifdef WOLFSSL_SHA384
  13523. wc_Sha384 sha384;
  13524. byte hash[WC_SHA384_DIGEST_SIZE];
  13525. testVector a, b, c;
  13526. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13527. /* Input */
  13528. a.input = "a";
  13529. a.inLen = XSTRLEN(a.input);
  13530. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13531. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13532. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13533. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13534. /* Update input. */
  13535. a.input = "abc";
  13536. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13537. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13538. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13539. "\xc8\x25\xa7";
  13540. a.inLen = XSTRLEN(a.input);
  13541. a.outLen = XSTRLEN(a.output);
  13542. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13543. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13544. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13545. /* Pass in bad values. */
  13546. b.input = NULL;
  13547. b.inLen = 0;
  13548. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13549. c.input = NULL;
  13550. c.inLen = WC_SHA384_DIGEST_SIZE;
  13551. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13552. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13553. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13554. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13555. wc_Sha384Free(&sha384);
  13556. #endif
  13557. return EXPECT_RESULT();
  13558. } /* END test_wc_Sha384Update */
  13559. /*
  13560. * Unit test function for wc_Sha384Final();
  13561. */
  13562. static int test_wc_Sha384Final(void)
  13563. {
  13564. EXPECT_DECLS;
  13565. #ifdef WOLFSSL_SHA384
  13566. wc_Sha384 sha384;
  13567. byte* hash_test[3];
  13568. byte hash1[WC_SHA384_DIGEST_SIZE];
  13569. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13570. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13571. int times, i;
  13572. /* Initialize */
  13573. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13574. hash_test[0] = hash1;
  13575. hash_test[1] = hash2;
  13576. hash_test[2] = hash3;
  13577. times = sizeof(hash_test) / sizeof(byte*);
  13578. /* Good test args. */
  13579. for (i = 0; i < times; i++) {
  13580. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13581. }
  13582. /* Test bad args. */
  13583. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13584. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13585. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13586. wc_Sha384Free(&sha384);
  13587. #endif
  13588. return EXPECT_RESULT();
  13589. } /* END test_wc_Sha384Final */
  13590. /*
  13591. * Unit test function for wc_Sha384GetFlags()
  13592. */
  13593. static int test_wc_Sha384GetFlags(void)
  13594. {
  13595. EXPECT_DECLS;
  13596. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13597. wc_Sha384 sha384;
  13598. word32 flags = 0;
  13599. /* Initialize */
  13600. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13601. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13602. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13603. wc_Sha384Free(&sha384);
  13604. #endif
  13605. return EXPECT_RESULT();
  13606. } /* END test_wc_Sha384GetFlags */
  13607. /*
  13608. * Unit test function for wc_Sha384FinalRaw()
  13609. */
  13610. static int test_wc_Sha384FinalRaw(void)
  13611. {
  13612. EXPECT_DECLS;
  13613. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13614. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13615. !defined(WOLFSSL_NO_HASH_RAW)
  13616. wc_Sha384 sha384;
  13617. byte* hash_test[3];
  13618. byte hash1[WC_SHA384_DIGEST_SIZE];
  13619. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13620. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13621. int times, i;
  13622. /* Initialize */
  13623. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13624. hash_test[0] = hash1;
  13625. hash_test[1] = hash2;
  13626. hash_test[2] = hash3;
  13627. times = sizeof(hash_test) / sizeof(byte*);
  13628. /* Good test args. */
  13629. for (i = 0; i < times; i++) {
  13630. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13631. }
  13632. /* Test bad args. */
  13633. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13634. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13635. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13636. wc_Sha384Free(&sha384);
  13637. #endif
  13638. return EXPECT_RESULT();
  13639. } /* END test_wc_Sha384FinalRaw */
  13640. /*
  13641. * Unit test function for wc_Sha384Free()
  13642. */
  13643. static int test_wc_Sha384Free(void)
  13644. {
  13645. EXPECT_DECLS;
  13646. #ifdef WOLFSSL_SHA384
  13647. wc_Sha384Free(NULL);
  13648. /* Set result to SUCCESS. */
  13649. ExpectTrue(1);
  13650. #endif
  13651. return EXPECT_RESULT();
  13652. } /* END test_wc_Sha384Free */
  13653. /*
  13654. * Unit test function for wc_Sha384GetHash()
  13655. */
  13656. static int test_wc_Sha384GetHash(void)
  13657. {
  13658. EXPECT_DECLS;
  13659. #ifdef WOLFSSL_SHA384
  13660. wc_Sha384 sha384;
  13661. byte hash1[WC_SHA384_DIGEST_SIZE];
  13662. /* Initialize */
  13663. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13664. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13665. /* test bad arguments*/
  13666. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13667. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13668. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13669. wc_Sha384Free(&sha384);
  13670. #endif
  13671. return EXPECT_RESULT();
  13672. } /* END test_wc_Sha384GetHash */
  13673. /*
  13674. * Unit test function for wc_Sha384Copy()
  13675. */
  13676. static int test_wc_Sha384Copy(void)
  13677. {
  13678. EXPECT_DECLS;
  13679. #ifdef WOLFSSL_SHA384
  13680. wc_Sha384 sha384;
  13681. wc_Sha384 temp;
  13682. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13683. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13684. /* Initialize */
  13685. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13686. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13687. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13688. /* test bad arguments*/
  13689. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13690. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13691. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13692. wc_Sha384Free(&sha384);
  13693. wc_Sha384Free(&temp);
  13694. #endif
  13695. return EXPECT_RESULT();
  13696. } /* END test_wc_Sha384Copy */
  13697. /*
  13698. * Testing wc_InitSha224();
  13699. */
  13700. static int test_wc_InitSha224(void)
  13701. {
  13702. EXPECT_DECLS;
  13703. #ifdef WOLFSSL_SHA224
  13704. wc_Sha224 sha224;
  13705. /* Test good arg. */
  13706. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13707. /* Test bad arg. */
  13708. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13709. wc_Sha224Free(&sha224);
  13710. #endif
  13711. return EXPECT_RESULT();
  13712. } /* END test_wc_InitSha224 */
  13713. /*
  13714. * Unit test on wc_Sha224Update
  13715. */
  13716. static int test_wc_Sha224Update(void)
  13717. {
  13718. EXPECT_DECLS;
  13719. #ifdef WOLFSSL_SHA224
  13720. wc_Sha224 sha224;
  13721. byte hash[WC_SHA224_DIGEST_SIZE];
  13722. testVector a, b, c;
  13723. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13724. /* Input. */
  13725. a.input = "a";
  13726. a.inLen = XSTRLEN(a.input);
  13727. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13728. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13729. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13730. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13731. /* Update input. */
  13732. a.input = "abc";
  13733. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13734. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13735. a.inLen = XSTRLEN(a.input);
  13736. a.outLen = XSTRLEN(a.output);
  13737. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13738. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13739. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13740. /* Pass in bad values. */
  13741. b.input = NULL;
  13742. b.inLen = 0;
  13743. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13744. c.input = NULL;
  13745. c.inLen = WC_SHA224_DIGEST_SIZE;
  13746. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13747. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13748. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13749. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13750. wc_Sha224Free(&sha224);
  13751. #endif
  13752. return EXPECT_RESULT();
  13753. } /* END test_wc_Sha224Update */
  13754. /*
  13755. * Unit test for wc_Sha224Final();
  13756. */
  13757. static int test_wc_Sha224Final(void)
  13758. {
  13759. EXPECT_DECLS;
  13760. #ifdef WOLFSSL_SHA224
  13761. wc_Sha224 sha224;
  13762. byte* hash_test[3];
  13763. byte hash1[WC_SHA224_DIGEST_SIZE];
  13764. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13765. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13766. int times, i;
  13767. /* Initialize */
  13768. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13769. hash_test[0] = hash1;
  13770. hash_test[1] = hash2;
  13771. hash_test[2] = hash3;
  13772. times = sizeof(hash_test) / sizeof(byte*);
  13773. /* Good test args. */
  13774. /* Testing oversized buffers. */
  13775. for (i = 0; i < times; i++) {
  13776. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13777. }
  13778. /* Test bad args. */
  13779. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13780. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13781. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13782. wc_Sha224Free(&sha224);
  13783. #endif
  13784. return EXPECT_RESULT();
  13785. } /* END test_wc_Sha224Final */
  13786. /*
  13787. * Unit test function for wc_Sha224SetFlags()
  13788. */
  13789. static int test_wc_Sha224SetFlags(void)
  13790. {
  13791. EXPECT_DECLS;
  13792. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13793. wc_Sha224 sha224;
  13794. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13795. /* Initialize */
  13796. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13797. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13798. flags = 0;
  13799. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13800. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13801. wc_Sha224Free(&sha224);
  13802. #endif
  13803. return EXPECT_RESULT();
  13804. } /* END test_wc_Sha224SetFlags */
  13805. /*
  13806. * Unit test function for wc_Sha224GetFlags()
  13807. */
  13808. static int test_wc_Sha224GetFlags(void)
  13809. {
  13810. EXPECT_DECLS;
  13811. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13812. wc_Sha224 sha224;
  13813. word32 flags = 0;
  13814. /* Initialize */
  13815. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13816. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13817. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13818. wc_Sha224Free(&sha224);
  13819. #endif
  13820. return EXPECT_RESULT();
  13821. } /* END test_wc_Sha224GetFlags */
  13822. /*
  13823. * Unit test function for wc_Sha224Free()
  13824. */
  13825. static int test_wc_Sha224Free(void)
  13826. {
  13827. EXPECT_DECLS;
  13828. #ifdef WOLFSSL_SHA224
  13829. wc_Sha224Free(NULL);
  13830. /* Set result to SUCCESS. */
  13831. ExpectTrue(1);
  13832. #endif
  13833. return EXPECT_RESULT();
  13834. } /* END test_wc_Sha224Free */
  13835. /*
  13836. * Unit test function for wc_Sha224GetHash()
  13837. */
  13838. static int test_wc_Sha224GetHash(void)
  13839. {
  13840. EXPECT_DECLS;
  13841. #ifdef WOLFSSL_SHA224
  13842. wc_Sha224 sha224;
  13843. byte hash1[WC_SHA224_DIGEST_SIZE];
  13844. /* Initialize */
  13845. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13846. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13847. /* test bad arguments*/
  13848. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13849. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13850. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13851. wc_Sha224Free(&sha224);
  13852. #endif
  13853. return EXPECT_RESULT();
  13854. } /* END test_wc_Sha224GetHash */
  13855. /*
  13856. * Unit test function for wc_Sha224Copy()
  13857. */
  13858. static int test_wc_Sha224Copy(void)
  13859. {
  13860. EXPECT_DECLS;
  13861. #ifdef WOLFSSL_SHA224
  13862. wc_Sha224 sha224;
  13863. wc_Sha224 temp;
  13864. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13865. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13866. /* Initialize */
  13867. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13868. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13869. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  13870. /* test bad arguments*/
  13871. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13872. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13873. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13874. wc_Sha224Free(&sha224);
  13875. wc_Sha224Free(&temp);
  13876. #endif
  13877. return EXPECT_RESULT();
  13878. } /* END test_wc_Sha224Copy */
  13879. /*
  13880. * Testing wc_InitRipeMd()
  13881. */
  13882. static int test_wc_InitRipeMd(void)
  13883. {
  13884. EXPECT_DECLS;
  13885. #ifdef WOLFSSL_RIPEMD
  13886. RipeMd ripemd;
  13887. /* Test good arg. */
  13888. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13889. /* Test bad arg. */
  13890. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13891. #endif
  13892. return EXPECT_RESULT();
  13893. } /* END test_wc_InitRipeMd */
  13894. /*
  13895. * Testing wc_RipeMdUpdate()
  13896. */
  13897. static int test_wc_RipeMdUpdate(void)
  13898. {
  13899. EXPECT_DECLS;
  13900. #ifdef WOLFSSL_RIPEMD
  13901. RipeMd ripemd;
  13902. byte hash[RIPEMD_DIGEST_SIZE];
  13903. testVector a, b, c;
  13904. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13905. /* Input */
  13906. a.input = "a";
  13907. a.inLen = XSTRLEN(a.input);
  13908. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13909. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13910. /* Update input. */
  13911. a.input = "abc";
  13912. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  13913. "\xb0\x87\xf1\x5a\x0b\xfc";
  13914. a.inLen = XSTRLEN(a.input);
  13915. a.outLen = XSTRLEN(a.output);
  13916. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13917. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13918. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  13919. /* Pass in bad values. */
  13920. b.input = NULL;
  13921. b.inLen = 0;
  13922. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  13923. c.input = NULL;
  13924. c.inLen = RIPEMD_DIGEST_SIZE;
  13925. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  13926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13927. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  13928. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13929. #endif
  13930. return EXPECT_RESULT();
  13931. } /* END test_wc_RipeMdUdpate */
  13932. /*
  13933. * Unit test function for wc_RipeMdFinal()
  13934. */
  13935. static int test_wc_RipeMdFinal(void)
  13936. {
  13937. EXPECT_DECLS;
  13938. #ifdef WOLFSSL_RIPEMD
  13939. RipeMd ripemd;
  13940. byte* hash_test[3];
  13941. byte hash1[RIPEMD_DIGEST_SIZE];
  13942. byte hash2[2*RIPEMD_DIGEST_SIZE];
  13943. byte hash3[5*RIPEMD_DIGEST_SIZE];
  13944. int times, i;
  13945. /* Initialize */
  13946. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13947. hash_test[0] = hash1;
  13948. hash_test[1] = hash2;
  13949. hash_test[2] = hash3;
  13950. times = sizeof(hash_test) / sizeof(byte*);
  13951. /* Testing oversized buffers. */
  13952. for (i = 0; i < times; i++) {
  13953. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  13954. }
  13955. /* Test bad args. */
  13956. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13957. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13958. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13959. #endif
  13960. return EXPECT_RESULT();
  13961. } /* END test_wc_RipeMdFinal */
  13962. /*
  13963. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  13964. * wc_InitSha3_512
  13965. */
  13966. static int test_wc_InitSha3(void)
  13967. {
  13968. EXPECT_DECLS;
  13969. #if defined(WOLFSSL_SHA3)
  13970. wc_Sha3 sha3;
  13971. (void)sha3;
  13972. #if !defined(WOLFSSL_NOSHA3_224)
  13973. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13974. /* Test bad args. */
  13975. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13976. wc_Sha3_224_Free(&sha3);
  13977. #endif /* NOSHA3_224 */
  13978. #if !defined(WOLFSSL_NOSHA3_256)
  13979. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13980. /* Test bad args. */
  13981. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13982. wc_Sha3_256_Free(&sha3);
  13983. #endif /* NOSHA3_256 */
  13984. #if !defined(WOLFSSL_NOSHA3_384)
  13985. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13986. /* Test bad args. */
  13987. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13988. wc_Sha3_384_Free(&sha3);
  13989. #endif /* NOSHA3_384 */
  13990. #if !defined(WOLFSSL_NOSHA3_512)
  13991. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13992. /* Test bad args. */
  13993. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13994. wc_Sha3_512_Free(&sha3);
  13995. #endif /* NOSHA3_512 */
  13996. #endif
  13997. return EXPECT_RESULT();
  13998. } /* END test_wc_InitSha3 */
  13999. /*
  14000. * Testing wc_Sha3_Update()
  14001. */
  14002. static int testing_wc_Sha3_Update(void)
  14003. {
  14004. EXPECT_DECLS;
  14005. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  14006. !defined(WOLFSSL_AFALG_XILINX)
  14007. wc_Sha3 sha3;
  14008. byte msg[] = "Everybody's working for the weekend.";
  14009. byte msg2[] = "Everybody gets Friday off.";
  14010. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14011. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14012. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14013. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14014. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14015. word32 msglen = sizeof(msg) - 1;
  14016. word32 msg2len = sizeof(msg2);
  14017. word32 msgCmplen = sizeof(msgCmp);
  14018. #if !defined(WOLFSSL_NOSHA3_224)
  14019. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14020. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  14021. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14022. ExpectTrue(sha3.i == msglen);
  14023. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14024. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14025. /* Pass bad args. */
  14026. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14027. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14028. wc_Sha3_224_Free(&sha3);
  14029. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14030. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  14031. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14032. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14033. wc_Sha3_224_Free(&sha3);
  14034. #endif /* SHA3_224 */
  14035. #if !defined(WOLFSSL_NOSHA3_256)
  14036. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14037. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  14038. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14039. ExpectTrue(sha3.i == msglen);
  14040. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14041. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14042. /* Pass bad args. */
  14043. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14044. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14045. wc_Sha3_256_Free(&sha3);
  14046. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14047. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  14048. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14049. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14050. wc_Sha3_256_Free(&sha3);
  14051. #endif /* SHA3_256 */
  14052. #if !defined(WOLFSSL_NOSHA3_384)
  14053. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14054. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  14055. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14056. ExpectTrue(sha3.i == msglen);
  14057. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14058. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14059. /* Pass bad args. */
  14060. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14061. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14062. wc_Sha3_384_Free(&sha3);
  14063. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14064. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  14065. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14066. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14067. wc_Sha3_384_Free(&sha3);
  14068. #endif /* SHA3_384 */
  14069. #if !defined(WOLFSSL_NOSHA3_512)
  14070. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14071. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  14072. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14073. ExpectTrue(sha3.i == msglen);
  14074. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14075. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14076. /* Pass bad args. */
  14077. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14078. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14079. wc_Sha3_512_Free(&sha3);
  14080. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14081. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  14082. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14083. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14084. wc_Sha3_512_Free(&sha3);
  14085. #endif /* SHA3_512 */
  14086. #endif /* WOLFSSL_SHA3 */
  14087. return EXPECT_RESULT();
  14088. } /* END testing_wc_Sha3_Update */
  14089. /*
  14090. * Testing wc_Sha3_224_Final()
  14091. */
  14092. static int test_wc_Sha3_224_Final(void)
  14093. {
  14094. EXPECT_DECLS;
  14095. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14096. wc_Sha3 sha3;
  14097. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14098. "nopnopq";
  14099. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  14100. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  14101. "\x64\xea\xd0\xfc\xce\x33";
  14102. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14103. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  14104. /* Init stack variables. */
  14105. XMEMSET(hash, 0, sizeof(hash));
  14106. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14107. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14108. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14109. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  14110. /* Test bad args. */
  14111. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14112. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14113. wc_Sha3_224_Free(&sha3);
  14114. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14115. /* Init stack variables. */
  14116. XMEMSET(hash, 0, sizeof(hash));
  14117. XMEMSET(hashRet, 0, sizeof(hashRet));
  14118. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14119. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  14120. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14121. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  14122. /* Test bad args. */
  14123. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14124. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14125. wc_Sha3_224_Free(&sha3);
  14126. #endif
  14127. return EXPECT_RESULT();
  14128. } /* END test_wc_Sha3_224_Final */
  14129. /*
  14130. * Testing wc_Sha3_256_Final()
  14131. */
  14132. static int test_wc_Sha3_256_Final(void)
  14133. {
  14134. EXPECT_DECLS;
  14135. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14136. wc_Sha3 sha3;
  14137. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14138. "nopnopq";
  14139. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  14140. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  14141. "\xdd\x97\x49\x6d\x33\x76";
  14142. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14143. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  14144. /* Init stack variables. */
  14145. XMEMSET(hash, 0, sizeof(hash));
  14146. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14147. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14148. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14149. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  14150. /* Test bad args. */
  14151. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14152. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14153. wc_Sha3_256_Free(&sha3);
  14154. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14155. /* Init stack variables. */
  14156. XMEMSET(hash, 0, sizeof(hash));
  14157. XMEMSET(hashRet, 0, sizeof(hashRet));
  14158. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14159. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  14160. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14161. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  14162. /* Test bad args. */
  14163. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14164. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14165. wc_Sha3_256_Free(&sha3);
  14166. #endif
  14167. return EXPECT_RESULT();
  14168. } /* END test_wc_Sha3_256_Final */
  14169. /*
  14170. * Testing wc_Sha3_384_Final()
  14171. */
  14172. static int test_wc_Sha3_384_Final(void)
  14173. {
  14174. EXPECT_DECLS;
  14175. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14176. wc_Sha3 sha3;
  14177. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14178. "nopnopq";
  14179. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  14180. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  14181. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  14182. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  14183. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14184. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  14185. /* Init stack variables. */
  14186. XMEMSET(hash, 0, sizeof(hash));
  14187. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14188. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14189. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14190. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  14191. /* Test bad args. */
  14192. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14193. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14194. wc_Sha3_384_Free(&sha3);
  14195. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14196. /* Init stack variables. */
  14197. XMEMSET(hash, 0, sizeof(hash));
  14198. XMEMSET(hashRet, 0, sizeof(hashRet));
  14199. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14200. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  14201. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14202. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  14203. /* Test bad args. */
  14204. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14205. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14206. wc_Sha3_384_Free(&sha3);
  14207. #endif
  14208. return EXPECT_RESULT();
  14209. } /* END test_wc_Sha3_384_Final */
  14210. /*
  14211. * Testing wc_Sha3_512_Final()
  14212. */
  14213. static int test_wc_Sha3_512_Final(void)
  14214. {
  14215. EXPECT_DECLS;
  14216. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  14217. !defined(WOLFSSL_NOSHA3_384)
  14218. wc_Sha3 sha3;
  14219. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14220. "nopnopq";
  14221. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  14222. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  14223. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  14224. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  14225. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  14226. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14227. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  14228. /* Init stack variables. */
  14229. XMEMSET(hash, 0, sizeof(hash));
  14230. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14231. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14232. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14233. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  14234. /* Test bad args. */
  14235. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14236. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14237. wc_Sha3_512_Free(&sha3);
  14238. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14239. /* Init stack variables. */
  14240. XMEMSET(hash, 0, sizeof(hash));
  14241. XMEMSET(hashRet, 0, sizeof(hashRet));
  14242. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14243. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  14244. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14245. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  14246. /* Test bad args. */
  14247. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14248. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14249. wc_Sha3_512_Free(&sha3);
  14250. #endif
  14251. return EXPECT_RESULT();
  14252. } /* END test_wc_Sha3_512_Final */
  14253. /*
  14254. * Testing wc_Sha3_224_Copy()
  14255. */
  14256. static int test_wc_Sha3_224_Copy(void)
  14257. {
  14258. EXPECT_DECLS;
  14259. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14260. wc_Sha3 sha3, sha3Cpy;
  14261. const char* msg = TEST_STRING;
  14262. word32 msglen = (word32)TEST_STRING_SZ;
  14263. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14264. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  14265. XMEMSET(hash, 0, sizeof(hash));
  14266. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14267. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14268. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14269. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14270. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14271. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  14272. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  14273. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14274. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  14275. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14276. /* Test bad args. */
  14277. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14278. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14279. wc_Sha3_224_Free(&sha3);
  14280. wc_Sha3_224_Free(&sha3Cpy);
  14281. #endif
  14282. return EXPECT_RESULT();
  14283. } /* END test_wc_Sha3_224_Copy */
  14284. /*
  14285. * Testing wc_Sha3_256_Copy()
  14286. */
  14287. static int test_wc_Sha3_256_Copy(void)
  14288. {
  14289. EXPECT_DECLS;
  14290. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14291. wc_Sha3 sha3, sha3Cpy;
  14292. const char* msg = TEST_STRING;
  14293. word32 msglen = (word32)TEST_STRING_SZ;
  14294. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14295. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  14296. XMEMSET(hash, 0, sizeof(hash));
  14297. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14298. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14299. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14300. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14301. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14302. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  14303. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  14304. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14305. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  14306. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14307. /* Test bad args. */
  14308. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14309. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14310. wc_Sha3_256_Free(&sha3);
  14311. wc_Sha3_256_Free(&sha3Cpy);
  14312. #endif
  14313. return EXPECT_RESULT();
  14314. } /* END test_wc_Sha3_256_Copy */
  14315. /*
  14316. * Testing wc_Sha3_384_Copy()
  14317. */
  14318. static int test_wc_Sha3_384_Copy(void)
  14319. {
  14320. EXPECT_DECLS;
  14321. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14322. wc_Sha3 sha3, sha3Cpy;
  14323. const char* msg = TEST_STRING;
  14324. word32 msglen = (word32)TEST_STRING_SZ;
  14325. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14326. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  14327. XMEMSET(hash, 0, sizeof(hash));
  14328. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14329. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14330. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14331. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14332. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14333. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  14334. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  14335. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14336. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  14337. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14338. /* Test bad args. */
  14339. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14340. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14341. wc_Sha3_384_Free(&sha3);
  14342. wc_Sha3_384_Free(&sha3Cpy);
  14343. #endif
  14344. return EXPECT_RESULT();
  14345. } /* END test_wc_Sha3_384_Copy */
  14346. /*
  14347. * Testing wc_Sha3_512_Copy()
  14348. */
  14349. static int test_wc_Sha3_512_Copy(void)
  14350. {
  14351. EXPECT_DECLS;
  14352. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  14353. wc_Sha3 sha3, sha3Cpy;
  14354. const char* msg = TEST_STRING;
  14355. word32 msglen = (word32)TEST_STRING_SZ;
  14356. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14357. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  14358. XMEMSET(hash, 0, sizeof(hash));
  14359. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14360. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14361. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14362. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14363. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14364. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  14365. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  14366. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14367. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  14368. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14369. /* Test bad args. */
  14370. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14371. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14372. wc_Sha3_512_Free(&sha3);
  14373. wc_Sha3_512_Free(&sha3Cpy);
  14374. #endif
  14375. return EXPECT_RESULT();
  14376. } /* END test_wc_Sha3_512_Copy */
  14377. /*
  14378. * Unit test function for wc_Sha3_GetFlags()
  14379. */
  14380. static int test_wc_Sha3_GetFlags(void)
  14381. {
  14382. EXPECT_DECLS;
  14383. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  14384. wc_Sha3 sha3;
  14385. word32 flags = 0;
  14386. /* Initialize */
  14387. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14388. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  14389. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  14390. wc_Sha3_224_Free(&sha3);
  14391. #endif
  14392. return EXPECT_RESULT();
  14393. } /* END test_wc_Sha3_GetFlags */
  14394. static int test_wc_InitShake256(void)
  14395. {
  14396. EXPECT_DECLS;
  14397. #ifdef WOLFSSL_SHAKE256
  14398. wc_Shake shake;
  14399. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14400. /* Test bad args. */
  14401. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14402. wc_Shake256_Free(&shake);
  14403. #endif
  14404. return EXPECT_RESULT();
  14405. }
  14406. static int testing_wc_Shake256_Update(void)
  14407. {
  14408. EXPECT_DECLS;
  14409. #ifdef WOLFSSL_SHAKE256
  14410. wc_Shake shake;
  14411. byte msg[] = "Everybody's working for the weekend.";
  14412. byte msg2[] = "Everybody gets Friday off.";
  14413. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14414. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14415. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14416. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14417. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14418. word32 msglen = sizeof(msg) - 1;
  14419. word32 msg2len = sizeof(msg2);
  14420. word32 msgCmplen = sizeof(msgCmp);
  14421. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14422. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  14423. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  14424. ExpectTrue(shake.i == msglen);
  14425. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14426. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  14427. /* Pass bad args. */
  14428. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14429. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14430. wc_Shake256_Free(&shake);
  14431. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14432. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  14433. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14434. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  14435. wc_Shake256_Free(&shake);
  14436. #endif /* WOLFSSL_SHAKE256 */
  14437. return EXPECT_RESULT();
  14438. }
  14439. static int test_wc_Shake256_Final(void)
  14440. {
  14441. EXPECT_DECLS;
  14442. #ifdef WOLFSSL_SHAKE256
  14443. wc_Shake shake;
  14444. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14445. "nopnopq";
  14446. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14447. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14448. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14449. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14450. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14451. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14452. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14453. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14454. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14455. byte hash[114];
  14456. /* Init stack variables. */
  14457. XMEMSET(hash, 0, sizeof(hash));
  14458. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14459. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14460. 0);
  14461. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14462. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14463. /* Test bad args. */
  14464. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14466. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14468. wc_Shake256_Free(&shake);
  14469. #endif
  14470. return EXPECT_RESULT();
  14471. }
  14472. /*
  14473. * Testing wc_Shake256_Copy()
  14474. */
  14475. static int test_wc_Shake256_Copy(void)
  14476. {
  14477. EXPECT_DECLS;
  14478. #ifdef WOLFSSL_SHAKE256
  14479. wc_Shake shake, shakeCpy;
  14480. const char* msg = TEST_STRING;
  14481. word32 msglen = (word32)TEST_STRING_SZ;
  14482. byte hash[144];
  14483. byte hashCpy[144];
  14484. word32 hashLen = sizeof(hash);
  14485. word32 hashLenCpy = sizeof(hashCpy);
  14486. XMEMSET(hash, 0, sizeof(hash));
  14487. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14488. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14489. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14490. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14491. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14492. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14493. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14494. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14495. /* Test bad args. */
  14496. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14497. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14498. wc_Shake256_Free(&shake);
  14499. wc_Shake256_Free(&shakeCpy);
  14500. #endif
  14501. return EXPECT_RESULT();
  14502. } /* END test_wc_Shake256_Copy */
  14503. /*
  14504. * Unit test function for wc_Shake256Hash()
  14505. */
  14506. static int test_wc_Shake256Hash(void)
  14507. {
  14508. EXPECT_DECLS;
  14509. #ifdef WOLFSSL_SHAKE256
  14510. const byte data[] = { /* Hello World */
  14511. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14512. 0x72,0x6c,0x64
  14513. };
  14514. word32 len = sizeof(data);
  14515. byte hash[144];
  14516. word32 hashLen = sizeof(hash);
  14517. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14518. #endif
  14519. return EXPECT_RESULT();
  14520. } /* END test_wc_Shake256Hash */
  14521. /*
  14522. * Testing wc_InitSm3(), wc_Sm3Free()
  14523. */
  14524. static int test_wc_InitSm3Free(void)
  14525. {
  14526. EXPECT_DECLS;
  14527. #ifdef WOLFSSL_SM3
  14528. wc_Sm3 sm3;
  14529. /* Invalid Parameters */
  14530. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14531. /* Valid Parameters */
  14532. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14533. wc_Sm3Free(NULL);
  14534. wc_Sm3Free(&sm3);
  14535. #endif
  14536. return EXPECT_RESULT();
  14537. } /* END test_wc_InitSm3 */
  14538. /*
  14539. * Testing wc_Sm3Update(), wc_Sm3Final()
  14540. */
  14541. static int test_wc_Sm3UpdateFinal(void)
  14542. {
  14543. EXPECT_DECLS;
  14544. #ifdef WOLFSSL_SM3
  14545. wc_Sm3 sm3;
  14546. byte data[WC_SM3_BLOCK_SIZE * 4];
  14547. byte hash[WC_SM3_DIGEST_SIZE];
  14548. byte calcHash[WC_SM3_DIGEST_SIZE];
  14549. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14550. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14551. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14552. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14553. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14554. };
  14555. word32 chunk;
  14556. word32 i;
  14557. XMEMSET(data, 0, sizeof(data));
  14558. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14559. /* Invalid Parameters */
  14560. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14561. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14562. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14563. /* Valid Parameters */
  14564. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14565. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14566. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14567. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14568. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14569. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14570. /* Ensure too many bytes for lengths. */
  14571. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14572. /* Invalid Parameters */
  14573. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14574. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14575. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14576. /* Valid Parameters */
  14577. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14578. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14579. /* Chunk tests. */
  14580. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14581. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14582. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14583. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14584. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14585. }
  14586. if (i < (word32)sizeof(data)) {
  14587. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14588. 0);
  14589. }
  14590. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14591. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14592. }
  14593. /* Not testing when the low 32-bit length overflows. */
  14594. wc_Sm3Free(&sm3);
  14595. #endif
  14596. return EXPECT_RESULT();
  14597. } /* END test_wc_Sm3Update */
  14598. /*
  14599. * Testing wc_Sm3GetHash()
  14600. */
  14601. static int test_wc_Sm3GetHash(void)
  14602. {
  14603. EXPECT_DECLS;
  14604. #ifdef WOLFSSL_SM3
  14605. wc_Sm3 sm3;
  14606. byte hash[WC_SM3_DIGEST_SIZE];
  14607. byte calcHash[WC_SM3_DIGEST_SIZE];
  14608. byte data[WC_SM3_BLOCK_SIZE];
  14609. XMEMSET(data, 0, sizeof(data));
  14610. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14611. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14612. /* Invalid Parameters */
  14613. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14614. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14615. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14616. /* Valid Parameters */
  14617. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14618. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14619. /* With update. */
  14620. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14621. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14622. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14623. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14624. wc_Sm3Free(&sm3);
  14625. #endif
  14626. return EXPECT_RESULT();
  14627. } /* END test_wc_Sm3Update */
  14628. /*
  14629. * Testing wc_Sm3Copy()
  14630. */
  14631. static int test_wc_Sm3Copy(void)
  14632. {
  14633. EXPECT_DECLS;
  14634. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14635. wc_Sm3 sm3;
  14636. wc_Sm3 sm3Copy;
  14637. byte hash[WC_SM3_DIGEST_SIZE];
  14638. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14639. byte data[WC_SM3_BLOCK_SIZE + 1];
  14640. int i;
  14641. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14642. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14643. /* Invalid Parameters */
  14644. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14645. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14646. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14647. /* Valid Parameters */
  14648. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14649. /* Ensure all parts of data updated during hashing are copied. */
  14650. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14651. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14652. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14653. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14654. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14655. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14656. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14657. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14658. }
  14659. wc_Sm3Free(&sm3Copy);
  14660. wc_Sm3Free(&sm3);
  14661. #endif
  14662. return EXPECT_RESULT();
  14663. } /* END test_wc_Sm3Copy */
  14664. /*
  14665. * Testing wc_Sm3FinalRaw()
  14666. */
  14667. static int test_wc_Sm3FinalRaw(void)
  14668. {
  14669. EXPECT_DECLS;
  14670. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14671. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14672. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14673. !defined(WOLFSSL_NO_HASH_RAW)
  14674. wc_Sm3 sm3;
  14675. byte hash1[WC_SM3_DIGEST_SIZE];
  14676. byte hash2[WC_SM3_DIGEST_SIZE];
  14677. byte hash3[WC_SM3_DIGEST_SIZE];
  14678. byte* hash_test[3] = { hash1, hash2, hash3 };
  14679. int times;
  14680. int i;
  14681. XMEMSET(&sm3, 0, sizeof(sm3));
  14682. /* Initialize */
  14683. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14684. /* Invalid Parameters */
  14685. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14686. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14687. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14688. times = sizeof(hash_test) / sizeof(byte*);
  14689. for (i = 0; i < times; i++) {
  14690. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14691. }
  14692. wc_Sm3Free(&sm3);
  14693. #endif
  14694. return EXPECT_RESULT();
  14695. } /* END test_wc_Sm3FinalRaw */
  14696. /*
  14697. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14698. */
  14699. static int test_wc_Sm3GetSetFlags(void)
  14700. {
  14701. EXPECT_DECLS;
  14702. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14703. wc_Sm3 sm3;
  14704. wc_Sm3 sm3Copy;
  14705. word32 flags = 0;
  14706. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14707. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14708. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14709. ExpectIntEQ(flags, 0);
  14710. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14711. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14712. ExpectIntEQ(flags, 0);
  14713. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14714. ExpectIntEQ(flags, 0);
  14715. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14716. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14717. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14718. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14719. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14720. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14721. wc_Sm3Free(&sm3Copy);
  14722. wc_Sm3Free(&sm3);
  14723. #endif
  14724. return EXPECT_RESULT();
  14725. } /* END test_wc_Sm3Update */
  14726. /*
  14727. * Testing wc_Sm3Hash()
  14728. */
  14729. static int test_wc_Sm3Hash(void)
  14730. {
  14731. EXPECT_DECLS;
  14732. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14733. byte data[WC_SM3_BLOCK_SIZE];
  14734. byte hash[WC_SM3_DIGEST_SIZE];
  14735. /* Invalid parameters. */
  14736. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14737. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14738. /* Valid parameters. */
  14739. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14740. #endif
  14741. return EXPECT_RESULT();
  14742. } /* END test_wc_Sm3Hash */
  14743. /*
  14744. * Test function for wc_HmacSetKey
  14745. */
  14746. static int test_wc_Md5HmacSetKey(void)
  14747. {
  14748. EXPECT_DECLS;
  14749. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14750. Hmac hmac;
  14751. int ret, times, itr;
  14752. const char* keys[]=
  14753. {
  14754. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14755. #ifndef HAVE_FIPS
  14756. "Jefe", /* smaller than minimum FIPS key size */
  14757. #endif
  14758. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14759. };
  14760. times = sizeof(keys) / sizeof(char*);
  14761. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14762. for (itr = 0; itr < times; itr++) {
  14763. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14764. (word32)XSTRLEN(keys[itr]));
  14765. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14766. wc_HmacFree(&hmac);
  14767. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14768. #else
  14769. ExpectIntEQ(ret, 0);
  14770. #endif
  14771. }
  14772. /* Bad args. */
  14773. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14774. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14775. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14777. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14778. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14779. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14780. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14781. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14782. #elif defined(HAVE_FIPS)
  14783. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14784. #else
  14785. ExpectIntEQ(ret, 0);
  14786. #endif
  14787. wc_HmacFree(&hmac);
  14788. #endif
  14789. return EXPECT_RESULT();
  14790. } /* END test_wc_Md5HmacSetKey */
  14791. /*
  14792. * testing wc_HmacSetKey() on wc_Sha hash.
  14793. */
  14794. static int test_wc_ShaHmacSetKey(void)
  14795. {
  14796. EXPECT_DECLS;
  14797. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14798. Hmac hmac;
  14799. int ret, times, itr;
  14800. const char* keys[]=
  14801. {
  14802. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14803. "\x0b\x0b\x0b",
  14804. #ifndef HAVE_FIPS
  14805. "Jefe", /* smaller than minimum FIPS key size */
  14806. #endif
  14807. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14808. "\xAA\xAA\xAA"
  14809. };
  14810. times = sizeof(keys) / sizeof(char*);
  14811. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14812. for (itr = 0; itr < times; itr++) {
  14813. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14814. (word32)XSTRLEN(keys[itr])), 0);
  14815. }
  14816. /* Bad args. */
  14817. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14818. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14819. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14821. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14822. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14823. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14824. #ifdef HAVE_FIPS
  14825. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14826. #else
  14827. ExpectIntEQ(ret, 0);
  14828. #endif
  14829. wc_HmacFree(&hmac);
  14830. #endif
  14831. return EXPECT_RESULT();
  14832. } /* END test_wc_ShaHmacSetKey() */
  14833. /*
  14834. * testing wc_HmacSetKey() on Sha224 hash.
  14835. */
  14836. static int test_wc_Sha224HmacSetKey(void)
  14837. {
  14838. EXPECT_DECLS;
  14839. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14840. Hmac hmac;
  14841. int ret, times, itr;
  14842. const char* keys[]=
  14843. {
  14844. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14845. "\x0b\x0b\x0b",
  14846. #ifndef HAVE_FIPS
  14847. "Jefe", /* smaller than minimum FIPS key size */
  14848. #endif
  14849. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14850. "\xAA\xAA\xAA"
  14851. };
  14852. times = sizeof(keys) / sizeof(char*);
  14853. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14854. for (itr = 0; itr < times; itr++) {
  14855. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14856. (word32)XSTRLEN(keys[itr])), 0);
  14857. }
  14858. /* Bad args. */
  14859. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14860. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14861. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14862. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14863. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14864. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14865. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14866. #ifdef HAVE_FIPS
  14867. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14868. #else
  14869. ExpectIntEQ(ret, 0);
  14870. #endif
  14871. wc_HmacFree(&hmac);
  14872. #endif
  14873. return EXPECT_RESULT();
  14874. } /* END test_wc_Sha224HmacSetKey() */
  14875. /*
  14876. * testing wc_HmacSetKey() on Sha256 hash
  14877. */
  14878. static int test_wc_Sha256HmacSetKey(void)
  14879. {
  14880. EXPECT_DECLS;
  14881. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14882. Hmac hmac;
  14883. int ret, times, itr;
  14884. const char* keys[]=
  14885. {
  14886. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14887. "\x0b\x0b\x0b",
  14888. #ifndef HAVE_FIPS
  14889. "Jefe", /* smaller than minimum FIPS key size */
  14890. #endif
  14891. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14892. "\xAA\xAA\xAA"
  14893. };
  14894. times = sizeof(keys) / sizeof(char*);
  14895. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14896. for (itr = 0; itr < times; itr++) {
  14897. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  14898. (word32)XSTRLEN(keys[itr])), 0);
  14899. }
  14900. /* Bad args. */
  14901. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  14902. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14903. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  14904. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14905. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14906. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14907. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  14908. #ifdef HAVE_FIPS
  14909. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14910. #else
  14911. ExpectIntEQ(ret, 0);
  14912. #endif
  14913. wc_HmacFree(&hmac);
  14914. #endif
  14915. return EXPECT_RESULT();
  14916. } /* END test_wc_Sha256HmacSetKey() */
  14917. /*
  14918. * testing wc_HmacSetKey on Sha384 hash.
  14919. */
  14920. static int test_wc_Sha384HmacSetKey(void)
  14921. {
  14922. EXPECT_DECLS;
  14923. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14924. Hmac hmac;
  14925. int ret, times, itr;
  14926. const char* keys[]=
  14927. {
  14928. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14929. "\x0b\x0b\x0b",
  14930. #ifndef HAVE_FIPS
  14931. "Jefe", /* smaller than minimum FIPS key size */
  14932. #endif
  14933. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14934. "\xAA\xAA\xAA"
  14935. };
  14936. times = sizeof(keys) / sizeof(char*);
  14937. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14938. for (itr = 0; itr < times; itr++) {
  14939. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  14940. (word32)XSTRLEN(keys[itr])), 0);
  14941. }
  14942. /* Bad args. */
  14943. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  14944. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14945. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  14946. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14947. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14948. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14949. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  14950. #ifdef HAVE_FIPS
  14951. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14952. #else
  14953. ExpectIntEQ(ret, 0);
  14954. #endif
  14955. wc_HmacFree(&hmac);
  14956. #endif
  14957. return EXPECT_RESULT();
  14958. } /* END test_wc_Sha384HmacSetKey() */
  14959. /*
  14960. * testing wc_HmacUpdate on wc_Md5 hash.
  14961. */
  14962. static int test_wc_Md5HmacUpdate(void)
  14963. {
  14964. EXPECT_DECLS;
  14965. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14966. Hmac hmac;
  14967. testVector a, b;
  14968. #ifdef HAVE_FIPS
  14969. const char* keys =
  14970. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14971. #else
  14972. const char* keys = "Jefe";
  14973. #endif
  14974. a.input = "what do ya want for nothing?";
  14975. a.inLen = XSTRLEN(a.input);
  14976. b.input = "Hi There";
  14977. b.inLen = XSTRLEN(b.input);
  14978. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14979. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  14980. (word32)XSTRLEN(keys)), 0);
  14981. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14982. /* Update Hmac. */
  14983. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14984. /* Test bad args. */
  14985. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14986. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14987. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14988. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14989. wc_HmacFree(&hmac);
  14990. #endif
  14991. return EXPECT_RESULT();
  14992. } /* END test_wc_Md5HmacUpdate */
  14993. /*
  14994. * testing wc_HmacUpdate on SHA hash.
  14995. */
  14996. static int test_wc_ShaHmacUpdate(void)
  14997. {
  14998. EXPECT_DECLS;
  14999. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15000. Hmac hmac;
  15001. testVector a, b;
  15002. #ifdef HAVE_FIPS
  15003. const char* keys =
  15004. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15005. #else
  15006. const char* keys = "Jefe";
  15007. #endif
  15008. a.input = "what do ya want for nothing?";
  15009. a.inLen = XSTRLEN(a.input);
  15010. b.input = "Hi There";
  15011. b.inLen = XSTRLEN(b.input);
  15012. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15013. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  15014. (word32)XSTRLEN(keys)), 0);
  15015. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15016. /* Update Hmac. */
  15017. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15018. /* Test bad args. */
  15019. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15020. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15021. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15022. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15023. wc_HmacFree(&hmac);
  15024. #endif
  15025. return EXPECT_RESULT();
  15026. } /* END test_wc_ShaHmacUpdate */
  15027. /*
  15028. * testing wc_HmacUpdate on SHA224 hash.
  15029. */
  15030. static int test_wc_Sha224HmacUpdate(void)
  15031. {
  15032. EXPECT_DECLS;
  15033. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15034. Hmac hmac;
  15035. testVector a, b;
  15036. #ifdef HAVE_FIPS
  15037. const char* keys =
  15038. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15039. #else
  15040. const char* keys = "Jefe";
  15041. #endif
  15042. a.input = "what do ya want for nothing?";
  15043. a.inLen = XSTRLEN(a.input);
  15044. b.input = "Hi There";
  15045. b.inLen = XSTRLEN(b.input);
  15046. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15047. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  15048. (word32)XSTRLEN(keys)), 0);
  15049. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15050. /* Update Hmac. */
  15051. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15052. /* Test bad args. */
  15053. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15055. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15056. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15057. wc_HmacFree(&hmac);
  15058. #endif
  15059. return EXPECT_RESULT();
  15060. } /* END test_wc_Sha224HmacUpdate */
  15061. /*
  15062. * testing wc_HmacUpdate on SHA256 hash.
  15063. */
  15064. static int test_wc_Sha256HmacUpdate(void)
  15065. {
  15066. EXPECT_DECLS;
  15067. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15068. Hmac hmac;
  15069. testVector a, b;
  15070. #ifdef HAVE_FIPS
  15071. const char* keys =
  15072. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15073. #else
  15074. const char* keys = "Jefe";
  15075. #endif
  15076. a.input = "what do ya want for nothing?";
  15077. a.inLen = XSTRLEN(a.input);
  15078. b.input = "Hi There";
  15079. b.inLen = XSTRLEN(b.input);
  15080. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15081. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  15082. (word32)XSTRLEN(keys)), 0);
  15083. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15084. /* Update Hmac. */
  15085. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15086. /* Test bad args. */
  15087. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15088. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15089. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15090. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15091. wc_HmacFree(&hmac);
  15092. #endif
  15093. return EXPECT_RESULT();
  15094. } /* END test_wc_Sha256HmacUpdate */
  15095. /*
  15096. * testing wc_HmacUpdate on SHA384 hash.
  15097. */
  15098. static int test_wc_Sha384HmacUpdate(void)
  15099. {
  15100. EXPECT_DECLS;
  15101. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15102. Hmac hmac;
  15103. testVector a, b;
  15104. #ifdef HAVE_FIPS
  15105. const char* keys =
  15106. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15107. #else
  15108. const char* keys = "Jefe";
  15109. #endif
  15110. a.input = "what do ya want for nothing?";
  15111. a.inLen = XSTRLEN(a.input);
  15112. b.input = "Hi There";
  15113. b.inLen = XSTRLEN(b.input);
  15114. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15115. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  15116. (word32)XSTRLEN(keys)), 0);
  15117. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15118. /* Update Hmac. */
  15119. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15120. /* Test bad args. */
  15121. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15122. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15123. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15124. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15125. wc_HmacFree(&hmac);
  15126. #endif
  15127. return EXPECT_RESULT();
  15128. } /* END test_wc_Sha384HmacUpdate */
  15129. /*
  15130. * Testing wc_HmacFinal() with MD5
  15131. */
  15132. static int test_wc_Md5HmacFinal(void)
  15133. {
  15134. EXPECT_DECLS;
  15135. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  15136. Hmac hmac;
  15137. byte hash[WC_MD5_DIGEST_SIZE];
  15138. testVector a;
  15139. const char* key;
  15140. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15141. a.input = "Hi There";
  15142. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  15143. "\x9d";
  15144. a.inLen = XSTRLEN(a.input);
  15145. a.outLen = XSTRLEN(a.output);
  15146. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15147. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  15148. 0);
  15149. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15150. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15151. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  15152. /* Try bad parameters. */
  15153. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15154. #ifndef HAVE_FIPS
  15155. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15156. #endif
  15157. wc_HmacFree(&hmac);
  15158. #endif
  15159. return EXPECT_RESULT();
  15160. } /* END test_wc_Md5HmacFinal */
  15161. /*
  15162. * Testing wc_HmacFinal() with SHA
  15163. */
  15164. static int test_wc_ShaHmacFinal(void)
  15165. {
  15166. EXPECT_DECLS;
  15167. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15168. Hmac hmac;
  15169. byte hash[WC_SHA_DIGEST_SIZE];
  15170. testVector a;
  15171. const char* key;
  15172. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15173. "\x0b\x0b\x0b";
  15174. a.input = "Hi There";
  15175. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  15176. "\x8e\xf1\x46\xbe\x00";
  15177. a.inLen = XSTRLEN(a.input);
  15178. a.outLen = XSTRLEN(a.output);
  15179. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15180. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  15181. 0);
  15182. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15183. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15184. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  15185. /* Try bad parameters. */
  15186. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15187. #ifndef HAVE_FIPS
  15188. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15189. #endif
  15190. wc_HmacFree(&hmac);
  15191. #endif
  15192. return EXPECT_RESULT();
  15193. } /* END test_wc_ShaHmacFinal */
  15194. /*
  15195. * Testing wc_HmacFinal() with SHA224
  15196. */
  15197. static int test_wc_Sha224HmacFinal(void)
  15198. {
  15199. EXPECT_DECLS;
  15200. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15201. Hmac hmac;
  15202. byte hash[WC_SHA224_DIGEST_SIZE];
  15203. testVector a;
  15204. const char* key;
  15205. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15206. "\x0b\x0b\x0b";
  15207. a.input = "Hi There";
  15208. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  15209. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  15210. a.inLen = XSTRLEN(a.input);
  15211. a.outLen = XSTRLEN(a.output);
  15212. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15213. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  15214. (word32)XSTRLEN(key)), 0);
  15215. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15216. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15217. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  15218. /* Try bad parameters. */
  15219. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15220. #ifndef HAVE_FIPS
  15221. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15222. #endif
  15223. wc_HmacFree(&hmac);
  15224. #endif
  15225. return EXPECT_RESULT();
  15226. } /* END test_wc_Sha224HmacFinal */
  15227. /*
  15228. * Testing wc_HmacFinal() with SHA256
  15229. */
  15230. static int test_wc_Sha256HmacFinal(void)
  15231. {
  15232. EXPECT_DECLS;
  15233. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15234. Hmac hmac;
  15235. byte hash[WC_SHA256_DIGEST_SIZE];
  15236. testVector a;
  15237. const char* key;
  15238. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15239. "\x0b\x0b\x0b";
  15240. a.input = "Hi There";
  15241. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  15242. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  15243. "\xcf\xf7";
  15244. a.inLen = XSTRLEN(a.input);
  15245. a.outLen = XSTRLEN(a.output);
  15246. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15247. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  15248. (word32)XSTRLEN(key)), 0);
  15249. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15250. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15251. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  15252. /* Try bad parameters. */
  15253. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15254. #ifndef HAVE_FIPS
  15255. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15256. #endif
  15257. wc_HmacFree(&hmac);
  15258. #endif
  15259. return EXPECT_RESULT();
  15260. } /* END test_wc_Sha256HmacFinal */
  15261. /*
  15262. * Testing wc_HmacFinal() with SHA384
  15263. */
  15264. static int test_wc_Sha384HmacFinal(void)
  15265. {
  15266. EXPECT_DECLS;
  15267. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15268. Hmac hmac;
  15269. byte hash[WC_SHA384_DIGEST_SIZE];
  15270. testVector a;
  15271. const char* key;
  15272. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15273. "\x0b\x0b\x0b";
  15274. a.input = "Hi There";
  15275. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  15276. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  15277. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  15278. "\xfa\x9c\xb6";
  15279. a.inLen = XSTRLEN(a.input);
  15280. a.outLen = XSTRLEN(a.output);
  15281. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15282. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  15283. (word32)XSTRLEN(key)), 0);
  15284. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15285. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15286. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  15287. /* Try bad parameters. */
  15288. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15289. #ifndef HAVE_FIPS
  15290. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15291. #endif
  15292. wc_HmacFree(&hmac);
  15293. #endif
  15294. return EXPECT_RESULT();
  15295. } /* END test_wc_Sha384HmacFinal */
  15296. /*
  15297. * Testing wc_InitCmac()
  15298. */
  15299. static int test_wc_InitCmac(void)
  15300. {
  15301. EXPECT_DECLS;
  15302. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  15303. Cmac cmac1;
  15304. Cmac cmac2;
  15305. Cmac cmac3;
  15306. /* AES 128 key. */
  15307. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15308. "\x09\x10\x11\x12\x13\x14\x15\x16";
  15309. /* AES 192 key. */
  15310. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15311. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15312. "\x01\x02\x03\x04\x05\x06\x07\x08";
  15313. /* AES 256 key. */
  15314. byte key3[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15315. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15316. "\x01\x02\x03\x04\x05\x06\x07\x08"
  15317. "\x09\x01\x11\x12\x13\x14\x15\x16";
  15318. word32 key1Sz = (word32)sizeof(key1) - 1;
  15319. word32 key2Sz = (word32)sizeof(key2) - 1;
  15320. word32 key3Sz = (word32)sizeof(key3) - 1;
  15321. int type = WC_CMAC_AES;
  15322. (void)key1;
  15323. (void)key1Sz;
  15324. (void)key2;
  15325. (void)key2Sz;
  15326. XMEMSET(&cmac1, 0, sizeof(Cmac));
  15327. XMEMSET(&cmac2, 0, sizeof(Cmac));
  15328. XMEMSET(&cmac3, 0, sizeof(Cmac));
  15329. #ifdef WOLFSSL_AES_128
  15330. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  15331. #endif
  15332. #ifdef WOLFSSL_AES_192
  15333. wc_AesFree(&cmac1.aes);
  15334. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  15335. #endif
  15336. #ifdef WOLFSSL_AES_256
  15337. wc_AesFree(&cmac2.aes);
  15338. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  15339. #endif
  15340. wc_AesFree(&cmac3.aes);
  15341. /* Test bad args. */
  15342. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15343. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15344. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15345. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15346. #endif
  15347. return EXPECT_RESULT();
  15348. } /* END test_wc_InitCmac */
  15349. /*
  15350. * Testing wc_CmacUpdate()
  15351. */
  15352. static int test_wc_CmacUpdate(void)
  15353. {
  15354. EXPECT_DECLS;
  15355. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15356. Cmac cmac;
  15357. byte key[] = {
  15358. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15359. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15360. };
  15361. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  15362. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  15363. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  15364. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  15365. "\xf4";
  15366. word32 inSz = (word32)sizeof(in) - 1;
  15367. word32 keySz = (word32)sizeof(key);
  15368. int type = WC_CMAC_AES;
  15369. XMEMSET(&cmac, 0, sizeof(Cmac));
  15370. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15371. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  15372. /* Test bad args. */
  15373. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15374. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15375. wc_AesFree(&cmac.aes);
  15376. #endif
  15377. return EXPECT_RESULT();
  15378. } /* END test_wc_CmacUpdate */
  15379. /*
  15380. * Testing wc_CmacFinal()
  15381. */
  15382. static int test_wc_CmacFinal(void)
  15383. {
  15384. EXPECT_DECLS;
  15385. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15386. Cmac cmac;
  15387. byte key[] = {
  15388. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15389. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15390. };
  15391. byte msg[] = {
  15392. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  15393. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  15394. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  15395. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  15396. 0xf4
  15397. };
  15398. /* Test vectors from CMACGenAES128.rsp from
  15399. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  15400. * Per RFC4493 truncation of lsb is possible.
  15401. */
  15402. byte expMac[] = {
  15403. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  15404. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  15405. };
  15406. byte mac[AES_BLOCK_SIZE];
  15407. word32 msgSz = (word32)sizeof(msg);
  15408. word32 keySz = (word32)sizeof(key);
  15409. word32 macSz = sizeof(mac);
  15410. word32 badMacSz = 17;
  15411. int expMacSz = sizeof(expMac);
  15412. int type = WC_CMAC_AES;
  15413. XMEMSET(&cmac, 0, sizeof(Cmac));
  15414. XMEMSET(mac, 0, macSz);
  15415. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15416. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  15417. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  15418. /* Pass in bad args. */
  15419. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15420. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15421. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15422. /* For the last call, use the API with implicit wc_CmacFree(). */
  15423. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15424. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15425. #else /* !HAVE_FIPS || FIPS>=5.3 */
  15426. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15427. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15428. /* Pass in bad args. */
  15429. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15430. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15431. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15432. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  15433. #endif
  15434. return EXPECT_RESULT();
  15435. } /* END test_wc_CmacFinal */
  15436. /*
  15437. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  15438. */
  15439. static int test_wc_AesCmacGenerate(void)
  15440. {
  15441. EXPECT_DECLS;
  15442. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15443. byte key[] = {
  15444. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15445. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15446. };
  15447. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15448. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15449. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15450. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15451. byte mac[AES_BLOCK_SIZE];
  15452. word32 keySz = sizeof(key);
  15453. word32 macSz = sizeof(mac);
  15454. word32 msgSz = sizeof(msg) - 1;
  15455. word32 expMacSz = sizeof(expMac) - 1;
  15456. XMEMSET(mac, 0, macSz);
  15457. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15458. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15459. /* Pass in bad args. */
  15460. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15462. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15464. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15466. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15468. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15469. /* Test bad args. */
  15470. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15471. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15472. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15474. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15475. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15476. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15478. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15479. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15480. #endif
  15481. return EXPECT_RESULT();
  15482. } /* END test_wc_AesCmacGenerate */
  15483. /*
  15484. * Testing streaming AES-GCM API.
  15485. */
  15486. static int test_wc_AesGcmStream(void)
  15487. {
  15488. EXPECT_DECLS;
  15489. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15490. defined(WOLFSSL_AESGCM_STREAM)
  15491. int i;
  15492. WC_RNG rng[1];
  15493. Aes aesEnc[1];
  15494. Aes aesDec[1];
  15495. byte tag[AES_BLOCK_SIZE];
  15496. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15497. byte out[AES_BLOCK_SIZE * 3 + 2];
  15498. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15499. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15500. byte key[AES_128_KEY_SIZE] = { 0, };
  15501. byte iv[AES_IV_SIZE] = { 1, };
  15502. byte ivOut[AES_IV_SIZE];
  15503. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15504. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15505. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15506. };
  15507. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15508. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15509. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15510. };
  15511. static const byte expTag[AES_BLOCK_SIZE] = {
  15512. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15513. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15514. };
  15515. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15516. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15517. XMEMSET(&aesDec, 0, sizeof(Aes));
  15518. /* Create a random for generating IV/nonce. */
  15519. ExpectIntEQ(wc_InitRng(rng), 0);
  15520. /* Initialize data structures. */
  15521. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15522. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15523. /* BadParameters to streaming init. */
  15524. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15525. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15526. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15527. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15528. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15529. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15530. /* Bad parameters to encrypt update. */
  15531. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15532. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15533. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15534. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15535. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15536. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15537. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15538. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15539. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15540. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15541. /* Bad parameters to decrypt update. */
  15542. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15543. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15544. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15545. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15546. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15547. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15548. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15549. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15550. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15551. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15552. /* Bad parameters to encrypt final. */
  15553. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15554. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15555. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15556. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15557. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15558. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15559. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15560. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15561. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15562. /* Bad parameters to decrypt final. */
  15563. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15564. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15565. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15566. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15567. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15568. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15569. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15570. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15571. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15572. /* Check calling final before setting key fails. */
  15573. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15574. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15575. /* Check calling update before setting key else fails. */
  15576. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15577. WC_NO_ERR_TRACE(MISSING_KEY));
  15578. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15579. WC_NO_ERR_TRACE(MISSING_KEY));
  15580. /* Set key but not IV. */
  15581. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15582. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15583. /* Check calling final before setting IV fails. */
  15584. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15585. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15586. /* Check calling update before setting IV else fails. */
  15587. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15588. WC_NO_ERR_TRACE(MISSING_IV));
  15589. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15590. WC_NO_ERR_TRACE(MISSING_IV));
  15591. /* Set IV using fixed part IV and external IV APIs. */
  15592. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15593. rng), 0);
  15594. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15595. GCM_NONCE_MID_SZ), 0);
  15596. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15597. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15598. /* Encrypt and decrypt data. */
  15599. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15600. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15601. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15602. /* Finalize and check tag matches. */
  15603. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15604. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15605. /* Set key and IV through streaming init API. */
  15606. wc_AesFree(aesEnc);
  15607. wc_AesFree(aesDec);
  15608. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15609. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15610. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15611. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15612. /* Encrypt/decrypt one block and AAD of one block. */
  15613. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15614. AES_BLOCK_SIZE), 0);
  15615. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15616. AES_BLOCK_SIZE), 0);
  15617. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15618. /* Finalize and check tag matches. */
  15619. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15620. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15621. /* Set key and IV through streaming init API. */
  15622. wc_AesFree(aesEnc);
  15623. wc_AesFree(aesDec);
  15624. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15625. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15626. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15627. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15628. /* No data to encrypt/decrypt one byte of AAD. */
  15629. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15630. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15631. /* Finalize and check tag matches. */
  15632. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15633. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15634. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15635. /* Set key and IV through streaming init API. */
  15636. wc_AesFree(aesEnc);
  15637. wc_AesFree(aesDec);
  15638. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15639. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15640. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15641. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15642. /* Encrypt/decrypt one byte and no AAD. */
  15643. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15644. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15645. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15646. /* Finalize and check tag matches. */
  15647. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15648. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15649. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15650. /* Set key and IV through streaming init API. */
  15651. wc_AesFree(aesEnc);
  15652. wc_AesFree(aesDec);
  15653. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15654. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15655. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15656. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15657. /* Encryption AES is one byte at a time */
  15658. for (i = 0; i < (int)sizeof(aad); i++) {
  15659. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15660. 0);
  15661. }
  15662. for (i = 0; i < (int)sizeof(in); i++) {
  15663. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15664. 0);
  15665. }
  15666. /* Decryption AES is two bytes at a time */
  15667. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15668. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15669. 0);
  15670. }
  15671. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15672. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15673. 0), 0);
  15674. }
  15675. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15676. /* Finalize and check tag matches. */
  15677. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15678. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15679. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15680. /* Check streaming encryption can be decrypted with one shot. */
  15681. wc_AesFree(aesDec);
  15682. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15683. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15684. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15685. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15686. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15687. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15688. wc_AesFree(aesEnc);
  15689. wc_AesFree(aesDec);
  15690. wc_FreeRng(rng);
  15691. #endif
  15692. return EXPECT_RESULT();
  15693. } /* END test_wc_AesGcmStream */
  15694. /*
  15695. * Testing streaming SM4 API.
  15696. */
  15697. static int test_wc_Sm4(void)
  15698. {
  15699. int res = TEST_SKIPPED;
  15700. #ifdef WOLFSSL_SM4
  15701. EXPECT_DECLS;
  15702. wc_Sm4 sm4;
  15703. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15704. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15705. unsigned char key[SM4_KEY_SIZE];
  15706. #endif
  15707. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15708. unsigned char iv[SM4_IV_SIZE];
  15709. #endif
  15710. /* Invalid parameters - wc_Sm4Init */
  15711. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15712. /* Valid cases - wc_Sm4Init */
  15713. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15714. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15715. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15716. XMEMSET(key, 0, sizeof(key));
  15717. /* Invalid parameters - wc_Sm4SetKey. */
  15718. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15719. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15720. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15721. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15722. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15723. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15724. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15725. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15726. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15727. /* Valid cases - wc_Sm4SetKey. */
  15728. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15729. #endif
  15730. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15731. XMEMSET(iv, 0, sizeof(iv));
  15732. /* Invalid parameters - wc_Sm4SetIV. */
  15733. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15734. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15735. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15736. /* Valid cases - wc_Sm4SetIV. */
  15737. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15738. #endif
  15739. /* Valid cases - wc_Sm4Free */
  15740. wc_Sm4Free(NULL);
  15741. wc_Sm4Free(&sm4);
  15742. res = EXPECT_RESULT();
  15743. #endif
  15744. return res;
  15745. } /* END test_wc_Sm4 */
  15746. /*
  15747. * Testing block based SM4-ECB API.
  15748. */
  15749. static int test_wc_Sm4Ecb(void)
  15750. {
  15751. int res = TEST_SKIPPED;
  15752. #ifdef WOLFSSL_SM4_ECB
  15753. EXPECT_DECLS;
  15754. wc_Sm4 sm4;
  15755. unsigned char key[SM4_KEY_SIZE];
  15756. unsigned char in[SM4_BLOCK_SIZE * 2];
  15757. unsigned char out[SM4_BLOCK_SIZE * 2];
  15758. unsigned char out2[SM4_BLOCK_SIZE];
  15759. XMEMSET(key, 0, sizeof(key));
  15760. XMEMSET(in, 0, sizeof(in));
  15761. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15762. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15763. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15764. /* Tested in test_wc_Sm4. */
  15765. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15766. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15767. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15768. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15769. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15770. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15771. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15772. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15773. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15774. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15775. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15776. /* Valid cases - wc_Sm4EcbEncrypt. */
  15777. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15778. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15779. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15780. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15781. /* In and out are same pointer. */
  15782. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15783. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15784. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15785. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15786. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15787. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15788. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15789. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15790. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15791. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15792. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15793. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15794. /* Valid cases - wc_Sm4EcbDecrypt. */
  15795. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15796. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15797. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15798. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15799. /* In and out are same pointer. */
  15800. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15801. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15802. wc_Sm4Free(&sm4);
  15803. res = EXPECT_RESULT();
  15804. #endif
  15805. return res;
  15806. } /* END test_wc_Sm4Ecb */
  15807. /*
  15808. * Testing block based SM4-CBC API.
  15809. */
  15810. static int test_wc_Sm4Cbc(void)
  15811. {
  15812. int res = TEST_SKIPPED;
  15813. #ifdef WOLFSSL_SM4_CBC
  15814. EXPECT_DECLS;
  15815. wc_Sm4 sm4;
  15816. unsigned char key[SM4_KEY_SIZE];
  15817. unsigned char iv[SM4_IV_SIZE];
  15818. unsigned char in[SM4_BLOCK_SIZE * 2];
  15819. unsigned char out[SM4_BLOCK_SIZE * 2];
  15820. unsigned char out2[SM4_BLOCK_SIZE];
  15821. XMEMSET(key, 0, sizeof(key));
  15822. XMEMSET(iv, 0, sizeof(iv));
  15823. XMEMSET(in, 0, sizeof(in));
  15824. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15825. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15826. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15827. /* Tested in test_wc_Sm4. */
  15828. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15829. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15830. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15831. /* Tested in test_wc_Sm4. */
  15832. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15833. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15834. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15835. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15836. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15837. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15838. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15839. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15840. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15841. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15842. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15843. /* Valid cases - wc_Sm4CbcEncrypt. */
  15844. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15845. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15846. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15847. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15848. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15849. /* In and out are same pointer. */
  15850. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15851. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15852. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15853. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15854. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15855. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15856. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15857. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15858. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15859. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15860. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15861. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15862. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15863. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15864. /* Valid cases - wc_Sm4CbcDecrypt. */
  15865. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15866. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15867. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15868. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15869. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15870. /* In and out are same pointer. */
  15871. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15872. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15873. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15874. wc_Sm4Free(&sm4);
  15875. res = EXPECT_RESULT();
  15876. #endif
  15877. return res;
  15878. } /* END test_wc_Sm4Cbc */
  15879. /*
  15880. * Testing streaming SM4-CTR API.
  15881. */
  15882. static int test_wc_Sm4Ctr(void)
  15883. {
  15884. int res = TEST_SKIPPED;
  15885. #ifdef WOLFSSL_SM4_CTR
  15886. EXPECT_DECLS;
  15887. wc_Sm4 sm4;
  15888. unsigned char key[SM4_KEY_SIZE];
  15889. unsigned char iv[SM4_IV_SIZE];
  15890. unsigned char in[SM4_BLOCK_SIZE * 4];
  15891. unsigned char out[SM4_BLOCK_SIZE * 4];
  15892. unsigned char out2[SM4_BLOCK_SIZE * 4];
  15893. word32 chunk;
  15894. word32 i;
  15895. XMEMSET(key, 0, sizeof(key));
  15896. XMEMSET(iv, 0, sizeof(iv));
  15897. XMEMSET(in, 0, sizeof(in));
  15898. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15899. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15900. /* Tested in test_wc_Sm4. */
  15901. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15902. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15903. /* Tested in test_wc_Sm4. */
  15904. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15905. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  15906. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15907. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15908. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15909. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15910. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15911. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15912. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15913. /* Valid cases - wc_Sm4CtrEncrypt. */
  15914. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  15915. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  15916. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15917. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  15918. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  15919. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15920. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15921. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  15922. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15923. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15924. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15925. /* In and out are same pointer. Also check encrypt of cipher text produces
  15926. * plaintext.
  15927. */
  15928. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15929. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  15930. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15931. /* Chunking tests. */
  15932. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15933. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  15934. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15935. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15936. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  15937. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  15938. }
  15939. if (i < (word32)sizeof(in)) {
  15940. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  15941. (word32)sizeof(in) - i), 0);
  15942. }
  15943. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  15944. }
  15945. for (i = 0; i < (word32)sizeof(iv); i++) {
  15946. iv[i] = 0xff;
  15947. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15948. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15949. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15950. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  15951. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  15952. }
  15953. wc_Sm4Free(&sm4);
  15954. res = EXPECT_RESULT();
  15955. #endif
  15956. return res;
  15957. } /* END test_wc_Sm4Ctr */
  15958. /*
  15959. * Testing stream SM4-GCM API.
  15960. */
  15961. static int test_wc_Sm4Gcm(void)
  15962. {
  15963. int res = TEST_SKIPPED;
  15964. #ifdef WOLFSSL_SM4_GCM
  15965. EXPECT_DECLS;
  15966. wc_Sm4 sm4;
  15967. unsigned char key[SM4_KEY_SIZE];
  15968. unsigned char nonce[GCM_NONCE_MAX_SZ];
  15969. unsigned char in[SM4_BLOCK_SIZE * 2];
  15970. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15971. unsigned char out[SM4_BLOCK_SIZE * 2];
  15972. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15973. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15974. unsigned char tag[SM4_BLOCK_SIZE];
  15975. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15976. word32 i;
  15977. XMEMSET(key, 0, sizeof(key));
  15978. XMEMSET(nonce, 0, sizeof(nonce));
  15979. XMEMSET(in, 0, sizeof(in));
  15980. XMEMSET(in2, 0, sizeof(in2));
  15981. XMEMSET(aad, 0, sizeof(aad));
  15982. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15983. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15984. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15985. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15986. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15987. /* Invalid parameters - wc_Sm4GcmSetKey. */
  15988. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15989. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15990. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15991. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15992. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15993. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15994. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15995. /* Valid parameters - wc_Sm4GcmSetKey. */
  15996. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15997. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  15998. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15999. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16000. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16001. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16002. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16003. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16004. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16005. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16006. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16007. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16008. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16009. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16010. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16011. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16012. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16013. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16014. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16015. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16016. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16017. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16018. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16019. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16020. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16021. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16022. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16023. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16024. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16025. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16026. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  16027. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16028. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16029. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16030. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16031. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16032. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16033. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16034. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16035. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16036. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16037. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16038. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16039. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16040. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16041. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16042. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16043. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16044. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16045. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16046. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16047. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16048. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16049. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16050. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16051. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16052. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16053. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16054. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16055. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16056. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16057. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16058. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16059. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16060. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16061. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16062. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16063. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16064. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16065. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16066. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16067. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16068. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16069. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16070. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16071. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16072. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16073. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16074. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16075. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16076. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16077. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16078. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16079. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16080. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16081. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16082. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16083. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16084. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16085. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16086. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16087. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16088. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16089. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16090. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16091. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16092. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16093. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  16094. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16095. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  16096. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16097. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16098. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16099. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16100. }
  16101. /* Check different in/out sizes. */
  16102. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  16103. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16104. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  16105. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16106. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  16107. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16108. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16109. XMEMCPY(out2, out, i - 1);
  16110. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  16111. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16112. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16113. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  16114. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16115. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16116. }
  16117. /* Force the counter to roll over in first byte. */
  16118. {
  16119. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16120. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16121. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16122. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16123. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16124. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16125. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16126. }
  16127. wc_Sm4Free(&sm4);
  16128. res = EXPECT_RESULT();
  16129. #endif
  16130. return res;
  16131. } /* END test_wc_Sm4Gcm */
  16132. /*
  16133. * Testing stream SM4-CCM API.
  16134. */
  16135. static int test_wc_Sm4Ccm(void)
  16136. {
  16137. int res = TEST_SKIPPED;
  16138. #ifdef WOLFSSL_SM4_CCM
  16139. EXPECT_DECLS;
  16140. wc_Sm4 sm4;
  16141. unsigned char key[SM4_KEY_SIZE];
  16142. unsigned char nonce[CCM_NONCE_MAX_SZ];
  16143. unsigned char in[SM4_BLOCK_SIZE * 2];
  16144. unsigned char in2[SM4_BLOCK_SIZE * 2];
  16145. unsigned char out[SM4_BLOCK_SIZE * 2];
  16146. unsigned char out2[SM4_BLOCK_SIZE * 2];
  16147. unsigned char dec[SM4_BLOCK_SIZE * 2];
  16148. unsigned char tag[SM4_BLOCK_SIZE];
  16149. unsigned char aad[SM4_BLOCK_SIZE * 2];
  16150. word32 i;
  16151. XMEMSET(key, 0, sizeof(key));
  16152. XMEMSET(nonce, 0, sizeof(nonce));
  16153. XMEMSET(in, 0, sizeof(in));
  16154. XMEMSET(in2, 0, sizeof(in2));
  16155. XMEMSET(aad, 0, sizeof(aad));
  16156. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16157. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16158. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16159. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16160. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16161. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16162. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  16163. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16164. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16165. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16166. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16167. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16168. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16169. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16170. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16171. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16172. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16173. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16174. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16175. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16176. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16177. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16178. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16179. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16180. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16181. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16182. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16183. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16184. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16185. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16186. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16187. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16188. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16189. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16190. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16191. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  16192. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16193. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16194. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16195. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16196. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16197. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16198. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16199. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16200. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16201. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16202. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16203. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16204. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16205. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16206. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16207. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16208. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16209. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16210. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16211. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16212. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16213. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16214. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16215. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16216. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16217. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16218. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16219. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16220. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16221. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16222. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16223. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16224. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16225. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16226. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16227. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16228. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16229. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16230. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16231. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16232. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16233. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16234. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16235. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16236. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16237. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16238. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16239. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16240. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16241. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16242. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16243. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16244. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16245. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16246. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16247. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16248. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  16249. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16250. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16251. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16252. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16253. }
  16254. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16255. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16256. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  16257. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16258. for (i = 0; i < 4; i++) {
  16259. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16260. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16261. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16262. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16263. }
  16264. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  16265. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16266. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16267. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16268. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16269. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16270. }
  16271. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  16272. * Even values in range 4..SM4_BLOCK_SIZE.
  16273. */
  16274. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16275. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16276. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16277. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16278. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16279. }
  16280. /* Check different in/out sizes. */
  16281. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  16282. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16283. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  16284. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16285. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  16286. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16287. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16288. XMEMCPY(out2, out, i - 1);
  16289. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  16290. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16291. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16292. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  16293. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16294. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16295. }
  16296. /* Force the counter to roll over in first byte. */
  16297. {
  16298. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16299. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16300. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16301. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16302. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16303. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16304. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16305. }
  16306. wc_Sm4Free(&sm4);
  16307. res = EXPECT_RESULT();
  16308. #endif
  16309. return res;
  16310. } /* END test_wc_Sm4Ccm */
  16311. /*
  16312. * unit test for wc_Des3_SetIV()
  16313. */
  16314. static int test_wc_Des3_SetIV(void)
  16315. {
  16316. EXPECT_DECLS;
  16317. #ifndef NO_DES3
  16318. Des3 des;
  16319. const byte key[] = {
  16320. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16321. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16322. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16323. };
  16324. const byte iv[] = {
  16325. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16326. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16327. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16328. };
  16329. XMEMSET(&des, 0, sizeof(Des3));
  16330. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16331. /* DES_ENCRYPTION or DES_DECRYPTION */
  16332. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16333. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16334. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  16335. /* Test explicitly wc_Des3_SetIV() */
  16336. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16337. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  16338. #endif
  16339. wc_Des3Free(&des);
  16340. #endif
  16341. return EXPECT_RESULT();
  16342. } /* END test_wc_Des3_SetIV */
  16343. /*
  16344. * unit test for wc_Des3_SetKey()
  16345. */
  16346. static int test_wc_Des3_SetKey(void)
  16347. {
  16348. EXPECT_DECLS;
  16349. #ifndef NO_DES3
  16350. Des3 des;
  16351. const byte key[] = {
  16352. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16353. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16354. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16355. };
  16356. const byte iv[] = {
  16357. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16358. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16359. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16360. };
  16361. XMEMSET(&des, 0, sizeof(Des3));
  16362. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16363. /* DES_ENCRYPTION or DES_DECRYPTION */
  16364. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16365. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16366. /* Test bad args. */
  16367. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16368. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16369. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16370. /* Default case. Should return 0. */
  16371. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  16372. wc_Des3Free(&des);
  16373. #endif
  16374. return EXPECT_RESULT();
  16375. } /* END test_wc_Des3_SetKey */
  16376. /*
  16377. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  16378. */
  16379. static int test_wc_Des3_CbcEncryptDecrypt(void)
  16380. {
  16381. EXPECT_DECLS;
  16382. #ifndef NO_DES3
  16383. Des3 des;
  16384. byte cipher[24];
  16385. byte plain[24];
  16386. const byte key[] = {
  16387. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16388. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16389. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16390. };
  16391. const byte iv[] = {
  16392. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16393. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16394. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16395. };
  16396. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16397. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16398. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16399. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16400. };
  16401. XMEMSET(&des, 0, sizeof(Des3));
  16402. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16403. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16404. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  16405. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  16406. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  16407. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16408. /* Pass in bad args. */
  16409. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16410. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16411. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  16412. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16413. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16414. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16415. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16416. wc_Des3Free(&des);
  16417. #endif
  16418. return EXPECT_RESULT();
  16419. } /* END wc_Des3_CbcEncrypt */
  16420. /*
  16421. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  16422. */
  16423. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  16424. {
  16425. EXPECT_DECLS;
  16426. #ifndef NO_DES3
  16427. word32 vectorSz, cipherSz;
  16428. byte cipher[24];
  16429. byte plain[24];
  16430. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16431. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16432. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16433. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16434. };
  16435. byte key[] = {
  16436. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16437. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16438. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16439. };
  16440. byte iv[] = {
  16441. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16442. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16443. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16444. };
  16445. vectorSz = sizeof(byte) * 24;
  16446. cipherSz = sizeof(byte) * 24;
  16447. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16448. 0);
  16449. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16450. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16451. /* pass in bad args. */
  16452. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16454. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16455. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16456. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16458. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16459. 0);
  16460. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16462. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16464. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16466. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16467. 0);
  16468. #endif
  16469. return EXPECT_RESULT();
  16470. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16471. /*
  16472. * Unit test for wc_Des3_EcbEncrypt
  16473. */
  16474. static int test_wc_Des3_EcbEncrypt(void)
  16475. {
  16476. EXPECT_DECLS;
  16477. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16478. Des3 des;
  16479. byte cipher[24];
  16480. word32 cipherSz = sizeof(cipher);
  16481. const byte key[] = {
  16482. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16483. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16484. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16485. };
  16486. const byte iv[] = {
  16487. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16488. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16489. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16490. };
  16491. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16492. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16493. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16494. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16495. };
  16496. XMEMSET(&des, 0, sizeof(Des3));
  16497. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16498. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16499. /* Bad Cases */
  16500. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16501. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16502. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16503. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16504. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16505. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16506. /* Good Cases */
  16507. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16508. wc_Des3Free(&des);
  16509. #endif
  16510. return EXPECT_RESULT();
  16511. } /* END test_wc_Des3_EcbEncrypt */
  16512. /*
  16513. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16514. */
  16515. static int test_wc_Chacha_SetKey(void)
  16516. {
  16517. EXPECT_DECLS;
  16518. #ifdef HAVE_CHACHA
  16519. ChaCha ctx;
  16520. const byte key[] = {
  16521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16522. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16523. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16524. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16525. };
  16526. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16527. byte cipher[128];
  16528. XMEMSET(cipher, 0, sizeof(cipher));
  16529. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16530. /* Test bad args. */
  16531. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16532. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16533. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16534. /* Test bad args. */
  16535. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16536. #endif
  16537. return EXPECT_RESULT();
  16538. } /* END test_wc_Chacha_SetKey */
  16539. /*
  16540. * unit test for wc_Poly1305SetKey()
  16541. */
  16542. static int test_wc_Poly1305SetKey(void)
  16543. {
  16544. EXPECT_DECLS;
  16545. #ifdef HAVE_POLY1305
  16546. Poly1305 ctx;
  16547. const byte key[] =
  16548. {
  16549. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16550. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16551. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16552. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16553. };
  16554. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16555. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16556. /* Test bad args. */
  16557. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16558. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16559. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16560. #endif
  16561. return EXPECT_RESULT();
  16562. } /* END test_wc_Poly1305_SetKey() */
  16563. /*
  16564. * Testing wc_Chacha_Process()
  16565. */
  16566. static int test_wc_Chacha_Process(void)
  16567. {
  16568. EXPECT_DECLS;
  16569. #ifdef HAVE_CHACHA
  16570. ChaCha enc, dec;
  16571. byte cipher[128];
  16572. byte plain[128];
  16573. const byte key[] =
  16574. {
  16575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16579. };
  16580. const char* input = "Everybody gets Friday off.";
  16581. word32 keySz = sizeof(key)/sizeof(byte);
  16582. unsigned long int inlen = XSTRLEN(input);
  16583. /* Initialize stack variables. */
  16584. XMEMSET(cipher, 0, 128);
  16585. XMEMSET(plain, 0, 128);
  16586. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16587. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16588. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16589. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16590. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16591. 0);
  16592. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16593. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16594. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16595. /* test checking and using leftovers, currently just in C code */
  16596. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16597. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16598. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16599. (word32)inlen - 2), 0);
  16600. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16601. (byte*)input + (inlen - 2), 2), 0);
  16602. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16603. (word32)inlen - 2), 0);
  16604. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16605. (byte*)input + (inlen - 2), 2), 0);
  16606. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16607. /* check edge cases with counter increment */
  16608. {
  16609. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16610. const byte expected[] = {
  16611. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16612. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16613. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16614. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16615. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16616. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16617. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16618. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16619. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16620. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16621. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16622. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16623. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16624. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16625. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16626. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16627. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16628. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16629. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16630. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16631. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16632. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16633. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16634. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16635. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16636. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16637. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16638. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16639. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16640. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16641. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16642. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16643. };
  16644. const byte iv2[] = {
  16645. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16646. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16647. };
  16648. byte input2[256];
  16649. int i;
  16650. for (i = 0; i < 256; i++)
  16651. input2[i] = i;
  16652. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16653. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16654. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16655. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16656. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16657. /* partial */
  16658. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16659. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16660. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16661. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16662. }
  16663. #endif
  16664. /* Test bad args. */
  16665. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16667. #endif
  16668. return EXPECT_RESULT();
  16669. } /* END test_wc_Chacha_Process */
  16670. /*
  16671. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16672. */
  16673. static int test_wc_ChaCha20Poly1305_aead(void)
  16674. {
  16675. EXPECT_DECLS;
  16676. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16677. const byte key[] = {
  16678. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16679. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16680. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16681. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16682. };
  16683. const byte plaintext[] = {
  16684. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16685. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16686. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16687. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16688. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16689. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16690. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16691. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16692. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16693. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16694. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16695. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16696. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16697. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16698. 0x74, 0x2e
  16699. };
  16700. const byte iv[] = {
  16701. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16702. 0x44, 0x45, 0x46, 0x47
  16703. };
  16704. const byte aad[] = { /* additional data */
  16705. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16706. 0xc4, 0xc5, 0xc6, 0xc7
  16707. };
  16708. const byte cipher[] = { /* expected output from operation */
  16709. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16710. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16711. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16712. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16713. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16714. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16715. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16716. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16717. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16718. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16719. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16720. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16721. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16722. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16723. 0x61, 0x16
  16724. };
  16725. const byte authTag[] = { /* expected output from operation */
  16726. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16727. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16728. };
  16729. byte generatedCiphertext[272];
  16730. byte generatedPlaintext[272];
  16731. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16732. /* Initialize stack variables. */
  16733. XMEMSET(generatedCiphertext, 0, 272);
  16734. XMEMSET(generatedPlaintext, 0, 272);
  16735. /* Test Encrypt */
  16736. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16737. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16738. 0);
  16739. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16740. sizeof(cipher)/sizeof(byte)), 0);
  16741. /* Test bad args. */
  16742. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16743. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16744. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16745. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16746. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16747. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16748. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16749. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16750. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16751. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16752. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16753. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16754. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16755. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16756. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16757. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16758. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16759. sizeof(cipher), authTag, generatedPlaintext), 0);
  16760. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16761. sizeof(plaintext)/sizeof(byte)), 0);
  16762. /* Test bad args. */
  16763. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16764. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16765. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16766. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16767. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16768. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16769. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16770. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16771. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16772. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16773. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16774. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16775. #endif
  16776. return EXPECT_RESULT();
  16777. } /* END test_wc_ChaCha20Poly1305_aead */
  16778. /*
  16779. * Testing function for wc_Rc2SetKey().
  16780. */
  16781. static int test_wc_Rc2SetKey(void)
  16782. {
  16783. EXPECT_DECLS;
  16784. #ifdef WC_RC2
  16785. Rc2 rc2;
  16786. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16787. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16788. /* valid key and IV */
  16789. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16790. iv, 40), 0);
  16791. /* valid key, no IV */
  16792. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16793. NULL, 40), 0);
  16794. /* bad arguments */
  16795. /* null Rc2 struct */
  16796. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16797. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16798. /* null key */
  16799. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16800. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16801. /* key size == 0 */
  16802. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16803. /* key size > 128 */
  16804. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16805. /* effective bits == 0 */
  16806. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16807. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16808. /* effective bits > 1024 */
  16809. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16810. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16811. #endif
  16812. return EXPECT_RESULT();
  16813. } /* END test_wc_Rc2SetKey */
  16814. /*
  16815. * Testing function for wc_Rc2SetIV().
  16816. */
  16817. static int test_wc_Rc2SetIV(void)
  16818. {
  16819. EXPECT_DECLS;
  16820. #ifdef WC_RC2
  16821. Rc2 rc2;
  16822. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16823. /* valid IV */
  16824. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16825. /* valid NULL IV */
  16826. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16827. /* bad arguments */
  16828. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16829. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16830. #endif
  16831. return EXPECT_RESULT();
  16832. } /* END test_wc_Rc2SetIV */
  16833. /*
  16834. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16835. */
  16836. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16837. {
  16838. EXPECT_DECLS;
  16839. #ifdef WC_RC2
  16840. Rc2 rc2;
  16841. int effectiveKeyBits = 63;
  16842. byte cipher[RC2_BLOCK_SIZE];
  16843. byte plain[RC2_BLOCK_SIZE];
  16844. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16845. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16846. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16847. XMEMSET(cipher, 0, sizeof(cipher));
  16848. XMEMSET(plain, 0, sizeof(plain));
  16849. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16850. NULL, effectiveKeyBits), 0);
  16851. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16852. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16853. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16854. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16855. /* Rc2EcbEncrypt bad arguments */
  16856. /* null Rc2 struct */
  16857. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16858. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16859. /* null out buffer */
  16860. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16861. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16862. /* null input buffer */
  16863. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16864. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16865. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16866. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16867. /* Rc2EcbDecrypt bad arguments */
  16868. /* null Rc2 struct */
  16869. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  16870. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16871. /* null out buffer */
  16872. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  16873. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16874. /* null input buffer */
  16875. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  16876. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16877. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16878. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16879. #endif
  16880. return EXPECT_RESULT();
  16881. } /* END test_wc_Rc2EcbEncryptDecrypt */
  16882. /*
  16883. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  16884. */
  16885. static int test_wc_Rc2CbcEncryptDecrypt(void)
  16886. {
  16887. EXPECT_DECLS;
  16888. #ifdef WC_RC2
  16889. Rc2 rc2;
  16890. int effectiveKeyBits = 63;
  16891. byte cipher[RC2_BLOCK_SIZE*2];
  16892. byte plain[RC2_BLOCK_SIZE*2];
  16893. /* vector taken from test.c */
  16894. byte key[] = {
  16895. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16896. };
  16897. byte iv[] = {
  16898. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16899. };
  16900. byte input[] = {
  16901. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16902. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16903. };
  16904. byte output[] = {
  16905. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  16906. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  16907. };
  16908. XMEMSET(cipher, 0, sizeof(cipher));
  16909. XMEMSET(plain, 0, sizeof(plain));
  16910. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16911. iv, effectiveKeyBits), 0);
  16912. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  16913. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  16914. /* reset IV for decrypt */
  16915. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16916. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  16917. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  16918. /* Rc2CbcEncrypt bad arguments */
  16919. /* null Rc2 struct */
  16920. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  16921. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16922. /* null out buffer */
  16923. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  16924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16925. /* null input buffer */
  16926. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  16927. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16928. /* Rc2CbcDecrypt bad arguments */
  16929. /* in size is 0 */
  16930. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  16931. /* null Rc2 struct */
  16932. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  16933. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16934. /* null out buffer */
  16935. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  16936. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16937. /* null input buffer */
  16938. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  16939. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16940. #endif
  16941. return EXPECT_RESULT();
  16942. } /* END test_wc_Rc2CbcEncryptDecrypt */
  16943. /*
  16944. * Testing function for wc_AesSetIV
  16945. */
  16946. static int test_wc_AesSetIV(void)
  16947. {
  16948. int res = TEST_SKIPPED;
  16949. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  16950. Aes aes;
  16951. int ret = 0;
  16952. byte key16[] =
  16953. {
  16954. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16955. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16956. };
  16957. byte iv1[] = "1234567890abcdef";
  16958. byte iv2[] = "0987654321fedcba";
  16959. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  16960. if (ret != 0)
  16961. return ret;
  16962. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  16963. iv1, AES_ENCRYPTION);
  16964. if (ret == 0) {
  16965. ret = wc_AesSetIV(&aes, iv2);
  16966. }
  16967. /* Test bad args. */
  16968. if (ret == 0) {
  16969. ret = wc_AesSetIV(NULL, iv1);
  16970. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  16971. /* NULL iv should return 0. */
  16972. ret = wc_AesSetIV(&aes, NULL);
  16973. }
  16974. else {
  16975. ret = WOLFSSL_FATAL_ERROR;
  16976. }
  16977. }
  16978. wc_AesFree(&aes);
  16979. res = TEST_RES_CHECK(ret == 0);
  16980. #endif
  16981. return res;
  16982. } /* test_wc_AesSetIV */
  16983. /*
  16984. * Testing function for wc_AesSetKey().
  16985. */
  16986. static int test_wc_AesSetKey(void)
  16987. {
  16988. EXPECT_DECLS;
  16989. #ifndef NO_AES
  16990. Aes aes;
  16991. byte key16[] = {
  16992. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16993. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16994. };
  16995. #ifdef WOLFSSL_AES_192
  16996. byte key24[] = {
  16997. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16998. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16999. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17000. };
  17001. #endif
  17002. #ifdef WOLFSSL_AES_256
  17003. byte key32[] = {
  17004. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17005. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17006. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17007. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17008. };
  17009. #endif
  17010. byte badKey16[] = {
  17011. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17012. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17013. };
  17014. byte iv[] = "1234567890abcdef";
  17015. XMEMSET(&aes, 0, sizeof(Aes));
  17016. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17017. #ifdef WOLFSSL_AES_128
  17018. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  17019. iv, AES_ENCRYPTION), 0);
  17020. #endif
  17021. #ifdef WOLFSSL_AES_192
  17022. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  17023. iv, AES_ENCRYPTION), 0);
  17024. #endif
  17025. #ifdef WOLFSSL_AES_256
  17026. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  17027. iv, AES_ENCRYPTION), 0);
  17028. #endif
  17029. /* Pass in bad args. */
  17030. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  17031. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17032. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  17033. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  17034. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17035. wc_AesFree(&aes);
  17036. #endif
  17037. return EXPECT_RESULT();
  17038. } /* END test_wc_AesSetKey */
  17039. /*
  17040. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  17041. * and wc_AesCbcDecryptWithKey()
  17042. */
  17043. static int test_wc_AesCbcEncryptDecrypt(void)
  17044. {
  17045. EXPECT_DECLS;
  17046. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  17047. defined(WOLFSSL_AES_256)
  17048. Aes aes;
  17049. byte key32[] = {
  17050. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17051. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17052. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17053. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17054. };
  17055. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  17056. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  17057. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  17058. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  17059. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  17060. };
  17061. byte iv[] = "1234567890abcdef";
  17062. byte enc[sizeof(vector)];
  17063. byte dec[sizeof(vector)];
  17064. byte dec2[sizeof(vector)];
  17065. /* Init stack variables. */
  17066. XMEMSET(&aes, 0, sizeof(Aes));
  17067. XMEMSET(enc, 0, sizeof(enc));
  17068. XMEMSET(dec, 0, sizeof(vector));
  17069. XMEMSET(dec2, 0, sizeof(vector));
  17070. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17071. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17072. AES_ENCRYPTION), 0);
  17073. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  17074. /* Re init for decrypt and set flag. */
  17075. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17076. AES_DECRYPTION), 0);
  17077. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  17078. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17079. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  17080. sizeof(key32)/sizeof(byte), iv), 0);
  17081. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  17082. /* Pass in bad args */
  17083. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  17084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17085. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  17086. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17087. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  17088. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17089. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17090. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  17091. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17092. #endif
  17093. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17094. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  17095. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  17096. "mode (v2), skip test");
  17097. #else
  17098. /* Test passing in size of 0 */
  17099. XMEMSET(enc, 0, sizeof(enc));
  17100. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  17101. /* Check enc was not modified */
  17102. {
  17103. int i;
  17104. for (i = 0; i < (int)sizeof(enc); i++)
  17105. ExpectIntEQ(enc[i], 0);
  17106. }
  17107. #endif
  17108. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17109. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  17110. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17111. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  17112. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17113. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17114. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17115. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17116. #else
  17117. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17118. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17119. #endif
  17120. /* Test passing in size of 0 */
  17121. XMEMSET(dec, 0, sizeof(dec));
  17122. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  17123. /* Check dec was not modified */
  17124. {
  17125. int i;
  17126. for (i = 0; i < (int)sizeof(dec); i++)
  17127. ExpectIntEQ(dec[i], 0);
  17128. }
  17129. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  17130. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17131. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  17132. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17133. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17134. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17135. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17136. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17137. wc_AesFree(&aes);
  17138. #endif
  17139. return EXPECT_RESULT();
  17140. } /* END test_wc_AesCbcEncryptDecrypt */
  17141. /*
  17142. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  17143. */
  17144. static int test_wc_AesCtrEncryptDecrypt(void)
  17145. {
  17146. EXPECT_DECLS;
  17147. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  17148. Aes aesEnc;
  17149. Aes aesDec;
  17150. byte key32[] = {
  17151. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17152. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17153. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17154. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17155. };
  17156. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17157. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17158. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17159. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17160. };
  17161. byte iv[] = "1234567890abcdef";
  17162. byte enc[AES_BLOCK_SIZE * 2];
  17163. byte dec[AES_BLOCK_SIZE * 2];
  17164. /* Init stack variables. */
  17165. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17166. XMEMSET(&aesDec, 0, sizeof(Aes));
  17167. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  17168. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  17169. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17170. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17171. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  17172. AES_ENCRYPTION), 0);
  17173. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  17174. sizeof(vector)/sizeof(byte)), 0);
  17175. /* Decrypt with wc_AesCtrEncrypt() */
  17176. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  17177. AES_ENCRYPTION), 0);
  17178. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  17179. 0);
  17180. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17181. /* Test bad args. */
  17182. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  17183. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17184. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  17185. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17186. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  17187. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17188. wc_AesFree(&aesEnc);
  17189. wc_AesFree(&aesDec);
  17190. #endif
  17191. return EXPECT_RESULT();
  17192. } /* END test_wc_AesCtrEncryptDecrypt */
  17193. /*
  17194. * test function for wc_AesGcmSetKey()
  17195. */
  17196. static int test_wc_AesGcmSetKey(void)
  17197. {
  17198. EXPECT_DECLS;
  17199. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17200. Aes aes;
  17201. #ifdef WOLFSSL_AES_128
  17202. byte key16[] = {
  17203. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17204. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17205. };
  17206. #endif
  17207. #ifdef WOLFSSL_AES_192
  17208. byte key24[] = {
  17209. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17210. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17211. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17212. };
  17213. #endif
  17214. #ifdef WOLFSSL_AES_256
  17215. byte key32[] = {
  17216. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17217. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17218. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17219. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17220. };
  17221. #endif
  17222. byte badKey16[] = {
  17223. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17224. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17225. };
  17226. byte badKey24[] = {
  17227. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17228. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17229. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  17230. };
  17231. byte badKey32[] = {
  17232. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  17233. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17234. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17235. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17236. };
  17237. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17238. #ifdef WOLFSSL_AES_128
  17239. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  17240. #endif
  17241. #ifdef WOLFSSL_AES_192
  17242. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  17243. #endif
  17244. #ifdef WOLFSSL_AES_256
  17245. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17246. #endif
  17247. /* Pass in bad args. */
  17248. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  17249. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17250. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  17251. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17252. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  17253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17254. wc_AesFree(&aes);
  17255. #endif
  17256. return EXPECT_RESULT();
  17257. } /* END test_wc_AesGcmSetKey */
  17258. /*
  17259. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  17260. */
  17261. static int test_wc_AesGcmEncryptDecrypt(void)
  17262. {
  17263. EXPECT_DECLS;
  17264. /* WOLFSSL_AFALG requires 12 byte IV */
  17265. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  17266. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  17267. Aes aes;
  17268. byte key32[] = {
  17269. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17270. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17271. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17272. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17273. };
  17274. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17275. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17276. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17277. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17278. };
  17279. const byte a[] = {
  17280. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17281. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17282. 0xab, 0xad, 0xda, 0xd2
  17283. };
  17284. byte iv[] = "1234567890a";
  17285. byte longIV[] = "1234567890abcdefghij";
  17286. byte enc[sizeof(vector)];
  17287. byte resultT[AES_BLOCK_SIZE];
  17288. byte dec[sizeof(vector)];
  17289. /* Init stack variables. */
  17290. XMEMSET(&aes, 0, sizeof(Aes));
  17291. XMEMSET(enc, 0, sizeof(vector));
  17292. XMEMSET(dec, 0, sizeof(vector));
  17293. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  17294. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17295. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17296. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17297. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17298. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  17299. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17300. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17301. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  17302. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  17303. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17304. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17305. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17306. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17307. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17308. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17309. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  17310. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17311. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17312. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  17313. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17314. /* FIPS does not check the lower bound of ivSz */
  17315. #else
  17316. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  17317. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17318. #endif
  17319. /* This case is now considered good. Long IVs are now allowed.
  17320. * Except for the original FIPS release, it still has an upper
  17321. * bound on the IV length. */
  17322. #if (!defined(HAVE_FIPS) || \
  17323. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17324. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17325. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  17326. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17327. 0);
  17328. #else
  17329. (void)longIV;
  17330. #endif /* Old FIPS */
  17331. /* END wc_AesGcmEncrypt */
  17332. #ifdef HAVE_AES_DECRYPT
  17333. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17334. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17335. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17336. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  17337. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17338. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17339. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  17340. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17341. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17342. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  17343. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17344. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17345. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17346. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  17347. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17348. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  17349. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17350. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17351. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  17352. #else
  17353. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17354. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17355. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17356. #endif
  17357. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17358. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  17359. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17360. /* FIPS does not check the lower bound of ivSz */
  17361. #else
  17362. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  17363. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17364. #endif
  17365. #endif /* HAVE_AES_DECRYPT */
  17366. wc_AesFree(&aes);
  17367. #endif
  17368. return EXPECT_RESULT();
  17369. } /* END test_wc_AesGcmEncryptDecrypt */
  17370. /*
  17371. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  17372. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  17373. */
  17374. static int test_wc_AesGcmMixedEncDecLongIV(void)
  17375. {
  17376. EXPECT_DECLS;
  17377. #if (!defined(HAVE_FIPS) || \
  17378. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17379. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  17380. const byte key[] = {
  17381. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17382. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17383. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17384. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17385. };
  17386. const byte in[] = {
  17387. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17388. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17389. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17390. };
  17391. const byte aad[] = {
  17392. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17393. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17394. 0xab, 0xad, 0xda, 0xd2
  17395. };
  17396. Aes aesEnc;
  17397. Aes aesDec;
  17398. byte iv[] = "1234567890abcdefghij";
  17399. byte out[sizeof(in)];
  17400. byte plain[sizeof(in)];
  17401. byte tag[AES_BLOCK_SIZE];
  17402. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17403. XMEMSET(&aesDec, 0, sizeof(Aes));
  17404. XMEMSET(out, 0, sizeof(out));
  17405. XMEMSET(plain, 0, sizeof(plain));
  17406. XMEMSET(tag, 0, sizeof(tag));
  17407. /* Perform one-shot encryption using long IV */
  17408. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17409. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  17410. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  17411. tag, sizeof(tag), aad, sizeof(aad)), 0);
  17412. /* Perform streaming decryption using long IV */
  17413. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17414. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  17415. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  17416. sizeof(aad)), 0);
  17417. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  17418. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  17419. /* Free resources */
  17420. wc_AesFree(&aesEnc);
  17421. wc_AesFree(&aesDec);
  17422. #endif
  17423. return EXPECT_RESULT();
  17424. } /* END wc_AesGcmMixedEncDecLongIV */
  17425. /*
  17426. * unit test for wc_GmacSetKey()
  17427. */
  17428. static int test_wc_GmacSetKey(void)
  17429. {
  17430. EXPECT_DECLS;
  17431. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17432. Gmac gmac;
  17433. byte key16[] = {
  17434. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17435. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17436. };
  17437. #ifdef WOLFSSL_AES_192
  17438. byte key24[] = {
  17439. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17440. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17441. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17442. };
  17443. #endif
  17444. #ifdef WOLFSSL_AES_256
  17445. byte key32[] = {
  17446. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17447. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17448. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17449. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17450. };
  17451. #endif
  17452. byte badKey16[] = {
  17453. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17454. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17455. };
  17456. byte badKey24[] = {
  17457. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17458. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17459. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17460. };
  17461. byte badKey32[] = {
  17462. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17463. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17464. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17465. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17466. };
  17467. XMEMSET(&gmac, 0, sizeof(Gmac));
  17468. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17469. #ifdef WOLFSSL_AES_128
  17470. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17471. #endif
  17472. #ifdef WOLFSSL_AES_192
  17473. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17474. #endif
  17475. #ifdef WOLFSSL_AES_256
  17476. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17477. #endif
  17478. /* Pass in bad args. */
  17479. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17480. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17481. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17482. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17483. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17484. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17485. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17486. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17487. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17488. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17489. wc_AesFree(&gmac.aes);
  17490. #endif
  17491. return EXPECT_RESULT();
  17492. } /* END test_wc_GmacSetKey */
  17493. /*
  17494. * unit test for wc_GmacUpdate
  17495. */
  17496. static int test_wc_GmacUpdate(void)
  17497. {
  17498. EXPECT_DECLS;
  17499. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17500. Gmac gmac;
  17501. #ifdef WOLFSSL_AES_128
  17502. const byte key16[] = {
  17503. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17504. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17505. };
  17506. #endif
  17507. #ifdef WOLFSSL_AES_192
  17508. byte key24[] = {
  17509. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17510. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17511. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17512. };
  17513. #endif
  17514. #ifdef WOLFSSL_AES_256
  17515. byte key32[] = {
  17516. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17517. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17518. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17519. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17520. };
  17521. #endif
  17522. #ifdef WOLFSSL_AES_128
  17523. const byte authIn[] = {
  17524. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17525. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17526. };
  17527. #endif
  17528. #ifdef WOLFSSL_AES_192
  17529. const byte authIn2[] = {
  17530. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17531. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17532. };
  17533. #endif
  17534. const byte authIn3[] = {
  17535. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17536. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17537. };
  17538. #ifdef WOLFSSL_AES_128
  17539. const byte tag1[] = { /* Known. */
  17540. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17541. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17542. };
  17543. #endif
  17544. #ifdef WOLFSSL_AES_192
  17545. const byte tag2[] = { /* Known */
  17546. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17547. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17548. };
  17549. #endif
  17550. const byte tag3[] = { /* Known */
  17551. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17552. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17553. };
  17554. #ifdef WOLFSSL_AES_128
  17555. const byte iv[] = {
  17556. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17557. 0xe2, 0x8c, 0x8f, 0x16
  17558. };
  17559. #endif
  17560. #ifdef WOLFSSL_AES_192
  17561. const byte iv2[] = {
  17562. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17563. 0x7e, 0x1a, 0x6f, 0xbc
  17564. };
  17565. #endif
  17566. const byte iv3[] = {
  17567. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17568. 0xc3, 0xfb, 0x6c, 0x8a
  17569. };
  17570. byte tagOut[16];
  17571. byte tagOut2[24];
  17572. byte tagOut3[32];
  17573. /* Init stack variables. */
  17574. XMEMSET(&gmac, 0, sizeof(Gmac));
  17575. XMEMSET(tagOut, 0, sizeof(tagOut));
  17576. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17577. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17578. #ifdef WOLFSSL_AES_128
  17579. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17580. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17581. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17582. tagOut, sizeof(tag1)), 0);
  17583. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17584. wc_AesFree(&gmac.aes);
  17585. #endif
  17586. #ifdef WOLFSSL_AES_192
  17587. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17588. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17589. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17590. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17591. tagOut2, sizeof(tag2)), 0);
  17592. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17593. wc_AesFree(&gmac.aes);
  17594. #endif
  17595. #ifdef WOLFSSL_AES_256
  17596. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17597. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17598. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17599. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17600. tagOut3, sizeof(tag3)), 0);
  17601. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17602. wc_AesFree(&gmac.aes);
  17603. #endif
  17604. /* Pass bad args. */
  17605. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17606. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17607. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17608. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17609. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17610. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17611. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17612. wc_AesFree(&gmac.aes);
  17613. #endif
  17614. return EXPECT_RESULT();
  17615. } /* END test_wc_GmacUpdate */
  17616. /*
  17617. * testing wc_CamelliaSetKey
  17618. */
  17619. static int test_wc_CamelliaSetKey(void)
  17620. {
  17621. EXPECT_DECLS;
  17622. #ifdef HAVE_CAMELLIA
  17623. Camellia camellia;
  17624. /*128-bit key*/
  17625. static const byte key16[] = {
  17626. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17627. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17628. };
  17629. /* 192-bit key */
  17630. static const byte key24[] = {
  17631. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17632. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17633. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17634. };
  17635. /* 256-bit key */
  17636. static const byte key32[] = {
  17637. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17638. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17639. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17640. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17641. };
  17642. static const byte iv[] = {
  17643. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17644. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17645. };
  17646. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17647. 0);
  17648. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17649. NULL), 0);
  17650. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17651. 0);
  17652. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17653. NULL), 0);
  17654. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17655. 0);
  17656. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17657. NULL), 0);
  17658. /* Bad args. */
  17659. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17661. #endif
  17662. return EXPECT_RESULT();
  17663. } /* END test_wc_CammeliaSetKey */
  17664. /*
  17665. * Testing wc_CamelliaSetIV()
  17666. */
  17667. static int test_wc_CamelliaSetIV(void)
  17668. {
  17669. EXPECT_DECLS;
  17670. #ifdef HAVE_CAMELLIA
  17671. Camellia camellia;
  17672. static const byte iv[] = {
  17673. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17674. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17675. };
  17676. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17677. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17678. /* Bad args. */
  17679. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17680. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17681. #endif
  17682. return EXPECT_RESULT();
  17683. } /* END test_wc_CamelliaSetIV*/
  17684. /*
  17685. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17686. */
  17687. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17688. {
  17689. EXPECT_DECLS;
  17690. #ifdef HAVE_CAMELLIA
  17691. Camellia camellia;
  17692. static const byte key24[] = {
  17693. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17694. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17695. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17696. };
  17697. static const byte iv[] = {
  17698. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17699. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17700. };
  17701. static const byte plainT[] = {
  17702. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17703. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17704. };
  17705. byte enc[sizeof(plainT)];
  17706. byte dec[sizeof(enc)];
  17707. /* Init stack variables.*/
  17708. XMEMSET(enc, 0, 16);
  17709. XMEMSET(enc, 0, 16);
  17710. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17711. 0);
  17712. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17713. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17714. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17715. /* Pass bad args. */
  17716. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17717. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17719. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17720. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17721. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17722. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17723. #endif
  17724. return EXPECT_RESULT();
  17725. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17726. /*
  17727. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17728. */
  17729. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17730. {
  17731. EXPECT_DECLS;
  17732. #ifdef HAVE_CAMELLIA
  17733. Camellia camellia;
  17734. static const byte key24[] = {
  17735. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17736. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17737. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17738. };
  17739. static const byte plainT[] = {
  17740. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17741. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17742. };
  17743. byte enc[CAMELLIA_BLOCK_SIZE];
  17744. byte dec[CAMELLIA_BLOCK_SIZE];
  17745. /* Init stack variables. */
  17746. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17747. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17748. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17749. NULL), 0);
  17750. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17751. CAMELLIA_BLOCK_SIZE), 0);
  17752. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17753. NULL), 0);
  17754. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17755. 0);
  17756. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17757. /* Pass in bad args. */
  17758. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17759. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17760. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17761. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17762. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17763. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17764. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17765. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17766. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17767. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17768. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17769. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17770. #endif
  17771. return EXPECT_RESULT();
  17772. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17773. /*
  17774. * Testing wc_Arc4SetKey()
  17775. */
  17776. static int test_wc_Arc4SetKey(void)
  17777. {
  17778. EXPECT_DECLS;
  17779. #ifndef NO_RC4
  17780. Arc4 arc;
  17781. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17782. int keyLen = 8;
  17783. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17784. /* Test bad args. */
  17785. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17786. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17787. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17788. #endif
  17789. return EXPECT_RESULT();
  17790. } /* END test_wc_Arc4SetKey */
  17791. /*
  17792. * Testing wc_Arc4Process for ENC/DEC.
  17793. */
  17794. static int test_wc_Arc4Process(void)
  17795. {
  17796. EXPECT_DECLS;
  17797. #ifndef NO_RC4
  17798. Arc4 enc;
  17799. Arc4 dec;
  17800. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17801. int keyLen = 8;
  17802. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17803. byte cipher[8];
  17804. byte plain[8];
  17805. /* Init stack variables */
  17806. XMEMSET(&enc, 0, sizeof(Arc4));
  17807. XMEMSET(&dec, 0, sizeof(Arc4));
  17808. XMEMSET(cipher, 0, sizeof(cipher));
  17809. XMEMSET(plain, 0, sizeof(plain));
  17810. /* Use for async. */
  17811. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17812. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17813. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17814. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17815. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17816. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17817. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17818. /* Bad args. */
  17819. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17820. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17821. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17822. wc_Arc4Free(&enc);
  17823. wc_Arc4Free(&dec);
  17824. #endif
  17825. return EXPECT_RESULT();
  17826. } /* END test_wc_Arc4Process */
  17827. /*
  17828. * Testing wc_Init RsaKey()
  17829. */
  17830. static int test_wc_InitRsaKey(void)
  17831. {
  17832. EXPECT_DECLS;
  17833. #ifndef NO_RSA
  17834. RsaKey key;
  17835. XMEMSET(&key, 0, sizeof(RsaKey));
  17836. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17837. /* Test bad args. */
  17838. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17839. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17840. #endif
  17841. return EXPECT_RESULT();
  17842. } /* END test_wc_InitRsaKey */
  17843. /*
  17844. * Testing wc_RsaPrivateKeyDecode()
  17845. */
  17846. static int test_wc_RsaPrivateKeyDecode(void)
  17847. {
  17848. EXPECT_DECLS;
  17849. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17850. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17851. RsaKey key;
  17852. byte* tmp = NULL;
  17853. word32 idx = 0;
  17854. int bytes = 0;
  17855. XMEMSET(&key, 0, sizeof(RsaKey));
  17856. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17857. DYNAMIC_TYPE_TMP_BUFFER));
  17858. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17859. if (tmp != NULL) {
  17860. #ifdef USE_CERT_BUFFERS_1024
  17861. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17862. bytes = sizeof_client_key_der_1024;
  17863. #else
  17864. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17865. bytes = sizeof_client_key_der_2048;
  17866. #endif /* Use cert buffers. */
  17867. }
  17868. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17869. /* Test bad args. */
  17870. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  17871. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17872. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  17873. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17874. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17875. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17876. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17877. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17878. #endif
  17879. return EXPECT_RESULT();
  17880. } /* END test_wc_RsaPrivateKeyDecode */
  17881. /*
  17882. * Testing wc_RsaPublicKeyDecode()
  17883. */
  17884. static int test_wc_RsaPublicKeyDecode(void)
  17885. {
  17886. EXPECT_DECLS;
  17887. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17888. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17889. RsaKey keyPub;
  17890. byte* tmp = NULL;
  17891. word32 idx = 0;
  17892. int bytes = 0;
  17893. word32 keySz = 0;
  17894. word32 tstKeySz = 0;
  17895. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17896. XFILE f = XBADFILE;
  17897. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  17898. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  17899. byte buf[4096];
  17900. #endif
  17901. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  17902. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  17903. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  17904. if (tmp != NULL) {
  17905. #ifdef USE_CERT_BUFFERS_1024
  17906. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  17907. bytes = sizeof_client_keypub_der_1024;
  17908. keySz = 1024;
  17909. #else
  17910. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  17911. bytes = sizeof_client_keypub_der_2048;
  17912. keySz = 2048;
  17913. #endif
  17914. }
  17915. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  17916. /* Pass in bad args. */
  17917. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  17918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17919. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  17920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17921. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17923. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  17924. /* Test for getting modulus key size */
  17925. idx = 0;
  17926. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  17927. &tstKeySz, NULL, NULL), 0);
  17928. ExpectIntEQ(tstKeySz, keySz/8);
  17929. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17930. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  17931. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17932. if (f != XBADFILE) {
  17933. XFCLOSE(f);
  17934. f = XBADFILE;
  17935. }
  17936. idx = 0;
  17937. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17938. NULL), 0);
  17939. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  17940. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17941. if (f != XBADFILE)
  17942. XFCLOSE(f);
  17943. idx = 0;
  17944. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17945. NULL), 0);
  17946. #endif
  17947. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17948. #endif
  17949. return EXPECT_RESULT();
  17950. } /* END test_wc_RsaPublicKeyDecode */
  17951. /*
  17952. * Testing wc_RsaPublicKeyDecodeRaw()
  17953. */
  17954. static int test_wc_RsaPublicKeyDecodeRaw(void)
  17955. {
  17956. EXPECT_DECLS;
  17957. #if !defined(NO_RSA)
  17958. RsaKey key;
  17959. const byte n = 0x23;
  17960. const byte e = 0x03;
  17961. int nSz = sizeof(n);
  17962. int eSz = sizeof(e);
  17963. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17964. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  17965. /* Pass in bad args. */
  17966. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  17967. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17968. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  17969. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17970. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  17971. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17972. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17973. #endif
  17974. return EXPECT_RESULT();
  17975. } /* END test_wc_RsaPublicKeyDecodeRaw */
  17976. /*
  17977. * Testing wc_RsaPrivateKeyDecodeRaw()
  17978. */
  17979. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  17980. {
  17981. EXPECT_DECLS;
  17982. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  17983. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  17984. RsaKey key;
  17985. const byte n = 33;
  17986. const byte e = 3;
  17987. const byte d = 7;
  17988. const byte u = 2;
  17989. const byte p = 3;
  17990. const byte q = 11;
  17991. const byte dp = 1;
  17992. const byte dq = 7;
  17993. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17994. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17995. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17996. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17997. NULL, 0, &key), 0);
  17998. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17999. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18000. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18001. NULL, 0, &key), 0);
  18002. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18003. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18004. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  18005. &dq, sizeof(dq), &key), 0);
  18006. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18007. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18008. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18009. &dq, sizeof(dq), &key), 0);
  18010. /* Pass in bad args. */
  18011. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  18012. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18013. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18014. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18015. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  18016. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18017. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18018. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18019. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18020. NULL, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18021. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18022. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18023. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18024. &e, 0, &d, sizeof(d), &u, sizeof(u),
  18025. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18026. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18027. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18028. &e, sizeof(e), NULL, sizeof(d), &u, sizeof(u),
  18029. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18030. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18031. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18032. &e, sizeof(e), &d, 0, &u, sizeof(u),
  18033. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18034. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18035. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18036. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18037. NULL, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18038. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18039. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18040. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18041. &p, 0, &q, sizeof(q), &dp, sizeof(dp),
  18042. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18043. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18044. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18045. &p, sizeof(p), NULL, sizeof(q), &dp, sizeof(dp),
  18046. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18047. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18048. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18049. &p, sizeof(p), &q, 0, &dp, sizeof(dp),
  18050. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18051. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  18052. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18053. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18054. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18055. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18056. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18057. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  18058. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18059. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18060. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18061. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18062. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18063. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18064. #endif
  18065. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18066. #endif
  18067. return EXPECT_RESULT();
  18068. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  18069. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18070. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  18071. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  18072. * trying until it gets a probable prime. */
  18073. #ifdef HAVE_FIPS
  18074. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  18075. {
  18076. int ret;
  18077. for (;;) {
  18078. ret = wc_MakeRsaKey(key, size, e, rng);
  18079. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  18080. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  18081. "trying again.\n");
  18082. }
  18083. return ret;
  18084. }
  18085. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  18086. #else
  18087. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  18088. #endif
  18089. #endif
  18090. /*
  18091. * Testing wc_MakeRsaKey()
  18092. */
  18093. static int test_wc_MakeRsaKey(void)
  18094. {
  18095. EXPECT_DECLS;
  18096. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18097. RsaKey genKey;
  18098. WC_RNG rng;
  18099. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18100. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18101. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18102. int bits = 1024;
  18103. #else
  18104. int bits = 2048;
  18105. #endif
  18106. XMEMSET(&genKey, 0, sizeof(RsaKey));
  18107. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18108. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18109. ExpectIntEQ(wc_InitRng(&rng), 0);
  18110. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18111. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18112. /* Test bad args. */
  18113. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18114. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  18115. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18116. /* e < 3 */
  18117. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18118. /* e & 1 == 0 */
  18119. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18120. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18121. #endif
  18122. return EXPECT_RESULT();
  18123. } /* END test_wc_MakeRsaKey */
  18124. /*
  18125. * Test the bounds checking on the cipher text versus the key modulus.
  18126. * 1. Make a new RSA key.
  18127. * 2. Set c to 1.
  18128. * 3. Decrypt c into k. (error)
  18129. * 4. Copy the key modulus to c and sub 1 from the copy.
  18130. * 5. Decrypt c into k. (error)
  18131. * Valid bounds test cases are covered by all the other RSA tests.
  18132. */
  18133. static int test_RsaDecryptBoundsCheck(void)
  18134. {
  18135. EXPECT_DECLS;
  18136. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  18137. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  18138. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  18139. WC_RNG rng;
  18140. RsaKey key;
  18141. byte flatC[256];
  18142. word32 flatCSz;
  18143. byte out[256];
  18144. word32 outSz = sizeof(out);
  18145. XMEMSET(&key, 0, sizeof(RsaKey));
  18146. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18147. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18148. ExpectIntEQ(wc_InitRng(&rng), 0);
  18149. if (EXPECT_SUCCESS()) {
  18150. const byte* derKey;
  18151. word32 derKeySz;
  18152. word32 idx = 0;
  18153. #ifdef USE_CERT_BUFFERS_1024
  18154. derKey = server_key_der_1024;
  18155. derKeySz = (word32)sizeof_server_key_der_1024;
  18156. flatCSz = 128;
  18157. #else
  18158. derKey = server_key_der_2048;
  18159. derKeySz = (word32)sizeof_server_key_der_2048;
  18160. flatCSz = 256;
  18161. #endif
  18162. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  18163. }
  18164. if (EXPECT_SUCCESS()) {
  18165. XMEMSET(flatC, 0, flatCSz);
  18166. flatC[flatCSz-1] = 1;
  18167. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18168. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18169. if (EXPECT_SUCCESS()) {
  18170. mp_int c;
  18171. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  18172. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  18173. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  18174. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18175. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18176. mp_clear(&c);
  18177. }
  18178. }
  18179. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18180. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18181. #endif
  18182. return EXPECT_RESULT();
  18183. } /* END test_wc_RsaDecryptBoundsCheck */
  18184. /*
  18185. * Testing wc_SetKeyUsage()
  18186. */
  18187. static int test_wc_SetKeyUsage(void)
  18188. {
  18189. EXPECT_DECLS;
  18190. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  18191. Cert myCert;
  18192. ExpectIntEQ(wc_InitCert(&myCert), 0);
  18193. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  18194. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  18195. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  18196. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  18197. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  18198. /* Test bad args. */
  18199. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18200. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18201. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18202. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18203. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  18204. WC_NO_ERR_TRACE(KEYUSAGE_E));
  18205. #endif
  18206. return EXPECT_RESULT();
  18207. } /* END test_wc_SetKeyUsage */
  18208. /*
  18209. * Testing wc_CheckProbablePrime()
  18210. */
  18211. static int test_wc_CheckProbablePrime(void)
  18212. {
  18213. EXPECT_DECLS;
  18214. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18215. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  18216. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  18217. RsaKey key;
  18218. WC_RNG rng;
  18219. byte e[3];
  18220. word32 eSz = (word32)sizeof(e);
  18221. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18222. word32 nSz = (word32)sizeof(n);
  18223. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18224. word32 dSz = (word32)sizeof(d);
  18225. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18226. word32 pSz = (word32)sizeof(p);
  18227. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18228. word32 qSz = (word32)sizeof(q);
  18229. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  18230. int* isPrime;
  18231. int test[5];
  18232. isPrime = test;
  18233. XMEMSET(&key, 0, sizeof(RsaKey));
  18234. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18235. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18236. ExpectIntEQ(wc_InitRng(&rng), 0);
  18237. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18238. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  18239. WC_RSA_EXPONENT, &rng), 0);
  18240. PRIVATE_KEY_UNLOCK();
  18241. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  18242. &qSz), 0);
  18243. PRIVATE_KEY_LOCK();
  18244. /* Bad cases */
  18245. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  18246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18247. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  18248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18249. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  18250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18251. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  18252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18253. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  18254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18255. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  18256. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18257. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  18258. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18259. /* Good case */
  18260. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  18261. 0);
  18262. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18263. wc_FreeRng(&rng);
  18264. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  18265. #endif
  18266. return EXPECT_RESULT();
  18267. } /* END test_wc_CheckProbablePrime */
  18268. /*
  18269. * Testing wc_RsaPSS_Verify()
  18270. */
  18271. static int test_wc_RsaPSS_Verify(void)
  18272. {
  18273. EXPECT_DECLS;
  18274. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18275. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18276. RsaKey key;
  18277. WC_RNG rng;
  18278. int sz = 256;
  18279. const char* szMessage = "This is the string to be signed";
  18280. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18281. unsigned char pDecrypted[2048/8];
  18282. byte* pt = pDecrypted;
  18283. word32 outLen = sizeof(pDecrypted);
  18284. XMEMSET(&key, 0, sizeof(RsaKey));
  18285. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18286. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18287. ExpectIntEQ(wc_InitRng(&rng), 0);
  18288. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18289. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18290. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  18291. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  18292. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18293. /* Bad cases */
  18294. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  18295. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18296. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  18297. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18298. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  18299. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18300. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  18301. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18302. /* Good case */
  18303. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  18304. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18305. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18306. wc_FreeRng(&rng);
  18307. #endif
  18308. return EXPECT_RESULT();
  18309. } /* END test_wc_RsaPSS_Verify */
  18310. /*
  18311. * Testing wc_RsaPSS_VerifyCheck()
  18312. */
  18313. static int test_wc_RsaPSS_VerifyCheck(void)
  18314. {
  18315. EXPECT_DECLS;
  18316. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18317. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18318. RsaKey key;
  18319. WC_RNG rng;
  18320. int sz = 256; /* 2048/8 */
  18321. byte digest[32];
  18322. word32 digestSz = sizeof(digest);
  18323. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18324. word32 pSignatureSz = sizeof(pSignature);
  18325. unsigned char pDecrypted[2048/8];
  18326. byte* pt = pDecrypted;
  18327. word32 outLen = sizeof(pDecrypted);
  18328. XMEMSET(&key, 0, sizeof(RsaKey));
  18329. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18330. XMEMSET(digest, 0, sizeof(digest));
  18331. XMEMSET(pSignature, 0, sizeof(pSignature));
  18332. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18333. ExpectIntEQ(wc_InitRng(&rng), 0);
  18334. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18335. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18336. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18337. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18338. 0);
  18339. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  18340. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18341. /* Bad cases */
  18342. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  18343. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18344. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  18345. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18346. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  18347. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18348. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  18349. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18350. /* Good case */
  18351. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  18352. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18353. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18354. wc_FreeRng(&rng);
  18355. #endif
  18356. return EXPECT_RESULT();
  18357. } /* END test_wc_RsaPSS_VerifyCheck */
  18358. /*
  18359. * Testing wc_RsaPSS_VerifyCheckInline()
  18360. */
  18361. static int test_wc_RsaPSS_VerifyCheckInline(void)
  18362. {
  18363. EXPECT_DECLS;
  18364. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18365. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18366. RsaKey key;
  18367. WC_RNG rng;
  18368. int sz = 256;
  18369. byte digest[32];
  18370. word32 digestSz = sizeof(digest);
  18371. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18372. unsigned char pDecrypted[2048/8];
  18373. byte* pt = pDecrypted;
  18374. XMEMSET(&key, 0, sizeof(RsaKey));
  18375. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18376. XMEMSET(digest, 0, sizeof(digest));
  18377. XMEMSET(pSignature, 0, sizeof(pSignature));
  18378. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18379. ExpectIntEQ(wc_InitRng(&rng), 0);
  18380. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18381. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18382. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18383. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18384. 0);
  18385. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  18386. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18387. /* Bad Cases */
  18388. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  18389. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18390. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  18391. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18392. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  18393. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18394. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18395. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18396. /* Good case */
  18397. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18398. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18399. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18400. wc_FreeRng(&rng);
  18401. #endif
  18402. return EXPECT_RESULT();
  18403. } /* END test_wc_RsaPSS_VerifyCheckInline */
  18404. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18405. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  18406. {
  18407. (void)flag;
  18408. (void)type;
  18409. (void)file;
  18410. (void)line;
  18411. }
  18412. #endif
  18413. /*
  18414. * Testing wc_LockMutex_ex
  18415. */
  18416. static int test_wc_LockMutex_ex(void)
  18417. {
  18418. EXPECT_DECLS;
  18419. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18420. int flag = CRYPTO_LOCK;
  18421. int type = 0;
  18422. const char* file = "./test-LockMutex_ex.txt";
  18423. int line = 0;
  18424. /* without SetMutexCb */
  18425. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  18426. /* with SetMutexCb */
  18427. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18428. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  18429. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18430. #endif
  18431. return EXPECT_RESULT();
  18432. } /* End test_wc_LockMutex_ex*/
  18433. /*
  18434. * Testing wc_SetMutexCb
  18435. */
  18436. static int test_wc_SetMutexCb(void)
  18437. {
  18438. EXPECT_DECLS;
  18439. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18440. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18441. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18442. #endif
  18443. return EXPECT_RESULT();
  18444. } /* End test_wc_SetMutexCb*/
  18445. /*
  18446. * Testing wc_RsaKeyToDer()
  18447. */
  18448. static int test_wc_RsaKeyToDer(void)
  18449. {
  18450. EXPECT_DECLS;
  18451. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18452. RsaKey genKey;
  18453. WC_RNG rng;
  18454. byte* der = NULL;
  18455. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18456. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18457. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18458. int bits = 1024;
  18459. word32 derSz = 611;
  18460. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18461. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18462. #else
  18463. int bits = 2048;
  18464. word32 derSz = 1196;
  18465. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18466. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18467. #endif
  18468. XMEMSET(&rng, 0, sizeof(rng));
  18469. XMEMSET(&genKey, 0, sizeof(genKey));
  18470. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18471. /* Init structures. */
  18472. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18473. ExpectIntEQ(wc_InitRng(&rng), 0);
  18474. /* Make key. */
  18475. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18476. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18477. /* Pass good/bad args. */
  18478. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18479. /* Get just the output length */
  18480. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18481. /* Try Public Key. */
  18482. genKey.type = 0;
  18483. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18484. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18485. /* Put back to Private Key */
  18486. genKey.type = 1;
  18487. #endif
  18488. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18489. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18490. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18491. #endif
  18492. return EXPECT_RESULT();
  18493. } /* END test_wc_RsaKeyToDer */
  18494. /*
  18495. * Testing wc_RsaKeyToPublicDer()
  18496. */
  18497. static int test_wc_RsaKeyToPublicDer(void)
  18498. {
  18499. EXPECT_DECLS;
  18500. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18501. RsaKey key;
  18502. WC_RNG rng;
  18503. byte* der = NULL;
  18504. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18505. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18506. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18507. int bits = 1024;
  18508. word32 derLen = 162;
  18509. #else
  18510. int bits = 2048;
  18511. word32 derLen = 294;
  18512. #endif
  18513. int ret = 0;
  18514. XMEMSET(&rng, 0, sizeof(rng));
  18515. XMEMSET(&key, 0, sizeof(key));
  18516. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18517. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18518. ExpectIntEQ(wc_InitRng(&rng), 0);
  18519. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18520. /* test getting size only */
  18521. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18522. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18523. /* test getting size only */
  18524. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18525. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18526. /* Pass in bad args. */
  18527. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18528. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18529. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18530. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18531. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18532. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18533. #endif
  18534. return EXPECT_RESULT();
  18535. } /* END test_wc_RsaKeyToPublicDer */
  18536. /*
  18537. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18538. */
  18539. static int test_wc_RsaPublicEncryptDecrypt(void)
  18540. {
  18541. EXPECT_DECLS;
  18542. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18543. RsaKey key;
  18544. WC_RNG rng;
  18545. const char inStr[] = TEST_STRING;
  18546. const word32 plainLen = (word32)TEST_STRING_SZ;
  18547. const word32 inLen = (word32)TEST_STRING_SZ;
  18548. int bits = TEST_RSA_BITS;
  18549. const word32 cipherLen = TEST_RSA_BYTES;
  18550. word32 cipherLenResult = cipherLen;
  18551. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18552. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18553. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18554. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18555. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18556. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18557. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18558. ExpectNotNull(in);
  18559. ExpectNotNull(plain);
  18560. ExpectNotNull(cipher);
  18561. #endif
  18562. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18563. /* Initialize stack structures. */
  18564. XMEMSET(&key, 0, sizeof(RsaKey));
  18565. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18566. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18567. ExpectIntEQ(wc_InitRng(&rng), 0);
  18568. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18569. /* Encrypt. */
  18570. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18571. cipherLen, &key, &rng), 0);
  18572. /* Pass bad args - tested in another testing function.*/
  18573. /* Decrypt */
  18574. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18575. /* Bind rng */
  18576. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18577. #endif
  18578. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18579. &key), 0);
  18580. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18581. /* Pass bad args - tested in another testing function.*/
  18582. WC_FREE_VAR(in, NULL);
  18583. WC_FREE_VAR(plain, NULL);
  18584. WC_FREE_VAR(cipher, NULL);
  18585. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18586. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18587. #endif
  18588. return EXPECT_RESULT();
  18589. } /* END test_wc_RsaPublicEncryptDecrypt */
  18590. /*
  18591. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18592. */
  18593. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18594. {
  18595. EXPECT_DECLS;
  18596. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18597. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18598. RsaKey key;
  18599. WC_RNG rng;
  18600. const char inStr[] = TEST_STRING;
  18601. const word32 inLen = (word32)TEST_STRING_SZ;
  18602. const word32 plainSz = (word32)TEST_STRING_SZ;
  18603. byte* res = NULL;
  18604. int idx = 0;
  18605. int bits = TEST_RSA_BITS;
  18606. const word32 cipherSz = TEST_RSA_BYTES;
  18607. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18608. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18609. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18610. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18611. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18612. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18613. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18614. ExpectNotNull(in);
  18615. ExpectNotNull(plain);
  18616. ExpectNotNull(cipher);
  18617. #endif
  18618. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18619. /* Initialize stack structures. */
  18620. XMEMSET(&key, 0, sizeof(RsaKey));
  18621. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18622. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18623. ExpectIntEQ(wc_InitRng(&rng), 0);
  18624. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18625. /* Encrypt */
  18626. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18627. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18628. /* Pass bad args - tested in another testing function.*/
  18629. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18630. /* Decrypt */
  18631. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18632. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18633. #endif
  18634. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18635. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18636. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18637. /* Pass bad args - tested in another testing function.*/
  18638. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18639. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18640. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18641. #endif
  18642. WC_FREE_VAR(in, NULL);
  18643. WC_FREE_VAR(plain, NULL);
  18644. WC_FREE_VAR(cipher, NULL);
  18645. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18646. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18647. #endif
  18648. return EXPECT_RESULT();
  18649. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18650. /*
  18651. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18652. */
  18653. static int test_wc_RsaSSL_SignVerify(void)
  18654. {
  18655. EXPECT_DECLS;
  18656. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18657. RsaKey key;
  18658. WC_RNG rng;
  18659. const char inStr[] = TEST_STRING;
  18660. const word32 plainSz = (word32)TEST_STRING_SZ;
  18661. const word32 inLen = (word32)TEST_STRING_SZ;
  18662. word32 idx = 0;
  18663. int bits = TEST_RSA_BITS;
  18664. const word32 outSz = TEST_RSA_BYTES;
  18665. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18666. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18667. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18668. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18669. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18670. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18671. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18672. ExpectNotNull(in);
  18673. ExpectNotNull(out);
  18674. ExpectNotNull(plain);
  18675. #endif
  18676. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18677. XMEMSET(&key, 0, sizeof(RsaKey));
  18678. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18679. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18680. ExpectIntEQ(wc_InitRng(&rng), 0);
  18681. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18682. /* Sign. */
  18683. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18684. idx = (int)outSz;
  18685. /* Test bad args. */
  18686. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18687. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18688. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18689. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18690. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18691. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18692. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18693. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18694. /* Verify. */
  18695. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18696. /* Pass bad args. */
  18697. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18699. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18700. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18701. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18702. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18703. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18704. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18705. WC_FREE_VAR(in, NULL);
  18706. WC_FREE_VAR(out, NULL);
  18707. WC_FREE_VAR(plain, NULL);
  18708. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18709. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18710. #endif
  18711. return EXPECT_RESULT();
  18712. } /* END test_wc_RsaSSL_SignVerify */
  18713. /*
  18714. * Testing wc_RsaEncryptSize()
  18715. */
  18716. static int test_wc_RsaEncryptSize(void)
  18717. {
  18718. EXPECT_DECLS;
  18719. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18720. RsaKey key;
  18721. WC_RNG rng;
  18722. XMEMSET(&key, 0, sizeof(RsaKey));
  18723. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18724. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18725. ExpectIntEQ(wc_InitRng(&rng), 0);
  18726. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18727. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18728. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18729. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18730. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18731. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18732. #endif
  18733. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18734. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18735. /* Pass in bad arg. */
  18736. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18737. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18738. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18739. #endif
  18740. return EXPECT_RESULT();
  18741. } /* END test_wc_RsaEncryptSize*/
  18742. /*
  18743. * Testing wc_RsaFlattenPublicKey()
  18744. */
  18745. static int test_wc_RsaFlattenPublicKey(void)
  18746. {
  18747. EXPECT_DECLS;
  18748. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18749. RsaKey key;
  18750. WC_RNG rng;
  18751. byte e[256];
  18752. byte n[256];
  18753. word32 eSz = sizeof(e);
  18754. word32 nSz = sizeof(n);
  18755. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18756. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18757. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18758. int bits = 1024;
  18759. #else
  18760. int bits = 2048;
  18761. #endif
  18762. XMEMSET(&key, 0, sizeof(RsaKey));
  18763. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18764. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18765. ExpectIntEQ(wc_InitRng(&rng), 0);
  18766. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18767. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18768. /* Pass bad args. */
  18769. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18771. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18773. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18775. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18777. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18778. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18779. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18780. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18781. #endif
  18782. return EXPECT_RESULT();
  18783. } /* END test_wc_RsaFlattenPublicKey */
  18784. /*
  18785. * unit test for wc_AesCcmSetKey
  18786. */
  18787. static int test_wc_AesCcmSetKey(void)
  18788. {
  18789. EXPECT_DECLS;
  18790. #ifdef HAVE_AESCCM
  18791. Aes aes;
  18792. const byte key16[] = {
  18793. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18794. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18795. };
  18796. const byte key24[] = {
  18797. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18798. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18799. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18800. };
  18801. const byte key32[] = {
  18802. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18803. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18804. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18805. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18806. };
  18807. XMEMSET(&aes, 0, sizeof(Aes));
  18808. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18809. #ifdef WOLFSSL_AES_128
  18810. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18811. #endif
  18812. #ifdef WOLFSSL_AES_192
  18813. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18814. #endif
  18815. #ifdef WOLFSSL_AES_256
  18816. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18817. #endif
  18818. /* Test bad args. */
  18819. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18820. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18821. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18822. wc_AesFree(&aes);
  18823. #endif
  18824. return EXPECT_RESULT();
  18825. } /* END test_wc_AesCcmSetKey */
  18826. /*
  18827. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18828. */
  18829. static int test_wc_AesCcmEncryptDecrypt(void)
  18830. {
  18831. EXPECT_DECLS;
  18832. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18833. Aes aes;
  18834. const byte key16[] = {
  18835. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18836. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18837. };
  18838. /* plaintext */
  18839. const byte plainT[] = {
  18840. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18841. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18842. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18843. };
  18844. /* nonce */
  18845. const byte iv[] = {
  18846. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18847. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18848. };
  18849. const byte c[] = { /* cipher text. */
  18850. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18851. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18852. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18853. };
  18854. const byte t[] = { /* Auth tag */
  18855. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18856. };
  18857. const byte authIn[] = {
  18858. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18859. };
  18860. byte cipherOut[sizeof(plainT)];
  18861. byte authTag[sizeof(t)];
  18862. #ifdef HAVE_AES_DECRYPT
  18863. byte plainOut[sizeof(cipherOut)];
  18864. #endif
  18865. XMEMSET(&aes, 0, sizeof(Aes));
  18866. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18867. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18868. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18869. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  18870. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  18871. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  18872. #ifdef HAVE_AES_DECRYPT
  18873. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18874. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  18875. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  18876. #endif
  18877. /* Pass in bad args. Encrypt*/
  18878. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  18879. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18880. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18881. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  18882. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18883. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18884. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  18885. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18886. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18887. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18888. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18889. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18890. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18891. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  18892. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18893. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18894. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18895. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18896. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18897. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18898. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18899. #ifdef HAVE_AES_DECRYPT
  18900. /* Pass in bad args. Decrypt*/
  18901. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  18902. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18903. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18904. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  18905. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18907. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  18908. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18909. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18910. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18911. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18912. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18913. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18914. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  18915. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18916. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18917. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18919. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18920. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18921. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18922. #endif
  18923. wc_AesFree(&aes);
  18924. #endif /* HAVE_AESCCM */
  18925. return EXPECT_RESULT();
  18926. } /* END test_wc_AesCcmEncryptDecrypt */
  18927. #if defined(WOLFSSL_AES_EAX) && \
  18928. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  18929. /*
  18930. * Testing test_wc_AesEaxVectors()
  18931. */
  18932. static int test_wc_AesEaxVectors(void)
  18933. {
  18934. EXPECT_DECLS;
  18935. typedef struct {
  18936. byte key[AES_256_KEY_SIZE];
  18937. int key_length;
  18938. byte iv[AES_BLOCK_SIZE];
  18939. int iv_length;
  18940. byte aad[AES_BLOCK_SIZE * 2];
  18941. int aad_length;
  18942. byte msg[AES_BLOCK_SIZE * 5];
  18943. int msg_length;
  18944. byte ct[AES_BLOCK_SIZE * 5];
  18945. int ct_length;
  18946. byte tag[AES_BLOCK_SIZE];
  18947. int tag_length;
  18948. int valid;
  18949. } AadVector;
  18950. /* Test vectors obtained from Google wycheproof project
  18951. * https://github.com/google/wycheproof
  18952. * from testvectors/aes_eax_test.json
  18953. */
  18954. const AadVector vectors[] = {
  18955. {
  18956. /* key, key length */
  18957. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  18958. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  18959. /* iv, iv length */
  18960. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  18961. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  18962. /* aad, aad length */
  18963. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  18964. /* msg, msg length */
  18965. {0x00}, 0,
  18966. /* ct, ct length */
  18967. {0x00}, 0,
  18968. /* tag, tag length */
  18969. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  18970. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  18971. /* valid */
  18972. 1,
  18973. },
  18974. {
  18975. /* key, key length */
  18976. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  18977. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  18978. /* iv, iv length */
  18979. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  18980. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  18981. /* aad, aad length */
  18982. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  18983. /* msg, msg length */
  18984. {0xf7, 0xfb}, 2,
  18985. /* ct, ct length */
  18986. {0x19, 0xdd}, 2,
  18987. /* tag, tag length */
  18988. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  18989. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  18990. /* valid */
  18991. 1,
  18992. },
  18993. {
  18994. /* key, key length */
  18995. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  18996. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  18997. /* iv, iv length */
  18998. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  18999. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  19000. /* aad, aad length */
  19001. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  19002. /* msg, msg length */
  19003. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  19004. /* ct, ct length */
  19005. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  19006. /* tag, tag length */
  19007. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  19008. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  19009. /* valid */
  19010. 1,
  19011. },
  19012. {
  19013. /* key, key length */
  19014. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  19015. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  19016. /* iv, iv length */
  19017. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  19018. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  19019. /* aad, aad length */
  19020. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  19021. /* msg, msg length */
  19022. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  19023. /* ct, ct length */
  19024. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  19025. /* tag, tag length */
  19026. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  19027. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  19028. /* valid */
  19029. 1,
  19030. },
  19031. {
  19032. /* key, key length */
  19033. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  19034. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  19035. /* iv, iv length */
  19036. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  19037. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  19038. /* aad, aad length */
  19039. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  19040. /* msg, msg length */
  19041. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  19042. /* ct, ct length */
  19043. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  19044. /* tag, tag length */
  19045. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  19046. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  19047. /* valid */
  19048. 1,
  19049. },
  19050. {
  19051. /* key, key length */
  19052. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  19053. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  19054. /* iv, iv length */
  19055. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  19056. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  19057. /* aad, aad length */
  19058. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  19059. /* msg, msg length */
  19060. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  19061. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  19062. /* ct, ct length */
  19063. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  19064. 0x0e, 0x72, 0x84, 0x14}, 12,
  19065. /* tag, tag length */
  19066. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  19067. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  19068. /* valid */
  19069. 1,
  19070. },
  19071. {
  19072. /* key, key length */
  19073. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  19074. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  19075. /* iv, iv length */
  19076. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  19077. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  19078. /* aad, aad length */
  19079. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  19080. /* msg, msg length */
  19081. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  19082. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  19083. 0x36}, 17,
  19084. /* ct, ct length */
  19085. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  19086. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  19087. 0x30}, 17,
  19088. /* tag, tag length */
  19089. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  19090. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  19091. /* valid */
  19092. 1,
  19093. },
  19094. {
  19095. /* key, key length */
  19096. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  19097. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  19098. /* iv, iv length */
  19099. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  19100. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  19101. /* aad, aad length */
  19102. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  19103. /* msg, msg length */
  19104. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  19105. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  19106. 0x2d, 0x56}, 18,
  19107. /* ct, ct length */
  19108. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  19109. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  19110. 0x8c, 0xc3}, 18,
  19111. /* tag, tag length */
  19112. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  19113. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  19114. /* valid */
  19115. 1,
  19116. },
  19117. {
  19118. /* key, key length */
  19119. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  19120. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  19121. /* iv, iv length */
  19122. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  19123. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  19124. /* aad, aad length */
  19125. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  19126. /* msg, msg length */
  19127. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  19128. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  19129. 0xef, 0x11}, 18,
  19130. /* ct, ct length */
  19131. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  19132. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  19133. 0xb1, 0xe8}, 18,
  19134. /* tag, tag length */
  19135. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  19136. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  19137. /* valid */
  19138. 1,
  19139. },
  19140. {
  19141. /* key, key length */
  19142. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  19143. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  19144. /* iv, iv length */
  19145. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  19146. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  19147. /* aad, aad length */
  19148. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  19149. /* msg, msg length */
  19150. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  19151. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  19152. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  19153. /* ct, ct length */
  19154. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  19155. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  19156. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  19157. /* tag, tag length */
  19158. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  19159. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  19160. /* valid */
  19161. 1,
  19162. },
  19163. {
  19164. /* key, key length */
  19165. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19166. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19167. /* iv, iv length */
  19168. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  19169. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  19170. /* aad, aad length */
  19171. {0x00}, 0,
  19172. /* msg, msg length */
  19173. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19174. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19175. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19176. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19177. /* ct, ct length */
  19178. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  19179. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  19180. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  19181. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  19182. /* tag, tag length */
  19183. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  19184. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  19185. /* valid */
  19186. 1,
  19187. },
  19188. {
  19189. /* key, key length */
  19190. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19191. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19192. /* iv, iv length */
  19193. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  19194. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  19195. /* aad, aad length */
  19196. {0x00}, 0,
  19197. /* msg, msg length */
  19198. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19199. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19200. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19201. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19202. /* ct, ct length */
  19203. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  19204. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  19205. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  19206. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  19207. /* tag, tag length */
  19208. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  19209. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  19210. /* valid */
  19211. 1,
  19212. },
  19213. {
  19214. /* key, key length */
  19215. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19216. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19217. /* iv, iv length */
  19218. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  19219. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  19220. /* aad, aad length */
  19221. {0x00}, 0,
  19222. /* msg, msg length */
  19223. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19224. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19225. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19226. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19227. /* ct, ct length */
  19228. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  19229. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  19230. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  19231. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  19232. /* tag, tag length */
  19233. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  19234. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  19235. /* valid */
  19236. 1,
  19237. },
  19238. {
  19239. /* key, key length */
  19240. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19241. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19242. /* iv, iv length */
  19243. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  19244. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  19245. /* aad, aad length */
  19246. {0x00}, 0,
  19247. /* msg, msg length */
  19248. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19249. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19250. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19251. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19252. /* ct, ct length */
  19253. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  19254. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  19255. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  19256. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  19257. /* tag, tag length */
  19258. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  19259. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  19260. /* valid */
  19261. 1,
  19262. },
  19263. {
  19264. /* key, key length */
  19265. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19266. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19267. /* iv, iv length */
  19268. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  19269. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  19270. /* aad, aad length */
  19271. {0x00}, 0,
  19272. /* msg, msg length */
  19273. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19274. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19275. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19276. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19277. /* ct, ct length */
  19278. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  19279. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  19280. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  19281. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  19282. /* tag, tag length */
  19283. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  19284. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  19285. /* valid */
  19286. 1,
  19287. },
  19288. {
  19289. /* key, key length */
  19290. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19291. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19292. /* iv, iv length */
  19293. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  19294. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  19295. /* aad, aad length */
  19296. {0x00}, 0,
  19297. /* msg, msg length */
  19298. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19300. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19301. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19302. /* ct, ct length */
  19303. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  19304. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  19305. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  19306. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  19307. /* tag, tag length */
  19308. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  19309. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  19310. /* valid */
  19311. 1,
  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. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  19319. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  19320. /* aad, aad length */
  19321. {0x00}, 0,
  19322. /* msg, msg length */
  19323. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19324. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19325. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19326. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19327. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19328. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19329. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19330. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  19331. /* ct, ct length */
  19332. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  19333. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  19334. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  19335. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  19336. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  19337. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  19338. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  19339. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  19340. /* tag, tag length */
  19341. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  19342. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  19343. /* valid */
  19344. 1,
  19345. },
  19346. {
  19347. /* key, key length */
  19348. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19349. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19350. /* iv, iv length */
  19351. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  19352. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  19353. /* aad, aad length */
  19354. {0x00}, 0,
  19355. /* msg, msg length */
  19356. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19358. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19359. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19360. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19361. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19362. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19363. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19364. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  19365. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  19366. /* ct, ct length */
  19367. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  19368. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  19369. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  19370. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  19371. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  19372. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  19373. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  19374. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  19375. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  19376. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  19377. /* tag, tag length */
  19378. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  19379. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  19380. /* valid */
  19381. 1,
  19382. },
  19383. {
  19384. /* key, key length */
  19385. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  19386. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  19387. /* iv, iv length */
  19388. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  19389. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  19390. /* aad, aad length */
  19391. {0x00}, 0,
  19392. /* msg, msg length */
  19393. {0x00}, 0,
  19394. /* ct, ct length */
  19395. {0x00}, 0,
  19396. /* tag, tag length */
  19397. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  19398. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  19399. /* valid */
  19400. 1,
  19401. },
  19402. {
  19403. /* key, key length */
  19404. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  19405. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  19406. /* iv, iv length */
  19407. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  19408. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  19409. /* aad, aad length */
  19410. {0x00}, 0,
  19411. /* msg, msg length */
  19412. {0x01}, 1,
  19413. /* ct, ct length */
  19414. {0x1d}, 1,
  19415. /* tag, tag length */
  19416. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  19417. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  19418. /* valid */
  19419. 1,
  19420. },
  19421. {
  19422. /* key, key length */
  19423. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  19424. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  19425. /* iv, iv length */
  19426. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  19427. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  19428. /* aad, aad length */
  19429. {0x00}, 0,
  19430. /* msg, msg length */
  19431. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  19432. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  19433. /* ct, ct length */
  19434. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  19435. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  19436. /* tag, tag length */
  19437. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  19438. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  19439. /* valid */
  19440. 1,
  19441. },
  19442. {
  19443. /* key, key length */
  19444. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  19445. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  19446. /* iv, iv length */
  19447. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  19448. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  19449. /* aad, aad length */
  19450. {0x00}, 0,
  19451. /* msg, msg length */
  19452. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19453. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19454. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19455. /* ct, ct length */
  19456. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19457. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19458. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19459. /* tag, tag length */
  19460. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19461. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19462. /* valid */
  19463. 1,
  19464. },
  19465. {
  19466. /* key, key length */
  19467. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19468. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19469. /* iv, iv length */
  19470. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19471. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19472. /* aad, aad length */
  19473. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19474. /* msg, msg length */
  19475. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19476. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19477. /* ct, ct length */
  19478. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19479. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19480. /* tag, tag length */
  19481. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19482. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19483. /* valid */
  19484. 1,
  19485. },
  19486. {
  19487. /* key, key length */
  19488. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19489. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19490. /* iv, iv length */
  19491. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19492. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19493. /* aad, aad length */
  19494. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19495. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19496. /* msg, msg length */
  19497. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19498. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19499. /* ct, ct length */
  19500. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19501. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19502. /* tag, tag length */
  19503. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19504. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19505. /* valid */
  19506. 1,
  19507. },
  19508. {
  19509. /* key, key length */
  19510. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19511. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19512. /* iv, iv length */
  19513. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19514. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19515. /* aad, aad length */
  19516. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19517. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19518. /* msg, msg length */
  19519. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19520. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19521. /* ct, ct length */
  19522. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19523. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19524. /* tag, tag length */
  19525. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19526. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19527. /* valid */
  19528. 1,
  19529. },
  19530. {
  19531. /* key, key length */
  19532. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19533. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19534. /* iv, iv length */
  19535. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19536. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19537. /* aad, aad length */
  19538. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19539. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19540. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19541. /* msg, msg length */
  19542. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19543. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19544. /* ct, ct length */
  19545. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19546. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19547. /* tag, tag length */
  19548. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19549. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19550. /* valid */
  19551. 1,
  19552. },
  19553. {
  19554. /* key, key length */
  19555. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19556. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19557. /* iv, iv length */
  19558. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19559. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19560. /* aad, aad length */
  19561. {0x00}, 0,
  19562. /* msg, msg length */
  19563. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19564. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19565. /* ct, ct length */
  19566. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19567. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19568. /* tag, tag length */
  19569. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19570. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19571. /* valid */
  19572. 0,
  19573. },
  19574. {
  19575. /* key, key length */
  19576. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19577. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19578. /* iv, iv length */
  19579. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19580. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19581. /* aad, aad length */
  19582. {0x00}, 0,
  19583. /* msg, msg length */
  19584. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19585. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19586. /* ct, ct length */
  19587. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19588. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19589. /* tag, tag length */
  19590. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19591. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19592. /* valid */
  19593. 0,
  19594. },
  19595. {
  19596. /* key, key length */
  19597. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19598. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19599. /* iv, iv length */
  19600. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19601. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19602. /* aad, aad length */
  19603. {0x00}, 0,
  19604. /* msg, msg length */
  19605. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19606. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19607. /* ct, ct length */
  19608. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19609. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19610. /* tag, tag length */
  19611. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19612. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19613. /* valid */
  19614. 0,
  19615. },
  19616. {
  19617. /* key, key length */
  19618. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19619. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19620. /* iv, iv length */
  19621. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19622. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19623. /* aad, aad length */
  19624. {0x00}, 0,
  19625. /* msg, msg length */
  19626. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19627. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19628. /* ct, ct length */
  19629. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19630. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19631. /* tag, tag length */
  19632. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19633. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19634. /* valid */
  19635. 0,
  19636. },
  19637. {
  19638. /* key, key length */
  19639. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19640. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19641. /* iv, iv length */
  19642. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19643. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19644. /* aad, aad length */
  19645. {0x00}, 0,
  19646. /* msg, msg length */
  19647. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19648. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19649. /* ct, ct length */
  19650. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19651. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19652. /* tag, tag length */
  19653. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19654. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19655. /* valid */
  19656. 0,
  19657. },
  19658. {
  19659. /* key, key length */
  19660. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19661. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19662. /* iv, iv length */
  19663. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19664. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19665. /* aad, aad length */
  19666. {0x00}, 0,
  19667. /* msg, msg length */
  19668. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19669. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19670. /* ct, ct length */
  19671. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19672. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19673. /* tag, tag length */
  19674. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19675. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19676. /* valid */
  19677. 0,
  19678. },
  19679. {
  19680. /* key, key length */
  19681. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19682. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19683. /* iv, iv length */
  19684. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19685. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19686. /* aad, aad length */
  19687. {0x00}, 0,
  19688. /* msg, msg length */
  19689. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19690. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19691. /* ct, ct length */
  19692. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19693. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19694. /* tag, tag length */
  19695. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19696. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19697. /* valid */
  19698. 0,
  19699. },
  19700. {
  19701. /* key, key length */
  19702. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19703. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19704. /* iv, iv length */
  19705. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19706. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19707. /* aad, aad length */
  19708. {0x00}, 0,
  19709. /* msg, msg length */
  19710. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19711. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19712. /* ct, ct length */
  19713. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19714. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19715. /* tag, tag length */
  19716. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19717. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19718. /* valid */
  19719. 0,
  19720. },
  19721. {
  19722. /* key, key length */
  19723. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19724. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19725. /* iv, iv length */
  19726. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19727. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19728. /* aad, aad length */
  19729. {0x00}, 0,
  19730. /* msg, msg length */
  19731. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19732. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19733. /* ct, ct length */
  19734. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19735. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19736. /* tag, tag length */
  19737. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19738. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19739. /* valid */
  19740. 0,
  19741. },
  19742. {
  19743. /* key, key length */
  19744. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19745. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19746. /* iv, iv length */
  19747. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19748. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19749. /* aad, aad length */
  19750. {0x00}, 0,
  19751. /* msg, msg length */
  19752. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19753. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19754. /* ct, ct length */
  19755. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19756. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19757. /* tag, tag length */
  19758. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19759. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19760. /* valid */
  19761. 0,
  19762. },
  19763. {
  19764. /* key, key length */
  19765. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19766. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19767. /* iv, iv length */
  19768. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19769. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19770. /* aad, aad length */
  19771. {0x00}, 0,
  19772. /* msg, msg length */
  19773. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19774. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19775. /* ct, ct length */
  19776. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19777. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19778. /* tag, tag length */
  19779. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19780. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19781. /* valid */
  19782. 0,
  19783. },
  19784. {
  19785. /* key, key length */
  19786. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19787. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19788. /* iv, iv length */
  19789. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19790. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19791. /* aad, aad length */
  19792. {0x00}, 0,
  19793. /* msg, msg length */
  19794. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19795. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19796. /* ct, ct length */
  19797. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19798. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19799. /* tag, tag length */
  19800. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19801. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19802. /* valid */
  19803. 0,
  19804. },
  19805. {
  19806. /* key, key length */
  19807. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19808. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19809. /* iv, iv length */
  19810. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19811. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19812. /* aad, aad length */
  19813. {0x00}, 0,
  19814. /* msg, msg length */
  19815. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19816. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19817. /* ct, ct length */
  19818. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19819. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19820. /* tag, tag length */
  19821. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19822. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19823. /* valid */
  19824. 0,
  19825. },
  19826. {
  19827. /* key, key length */
  19828. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19829. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19830. /* iv, iv length */
  19831. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19832. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19833. /* aad, aad length */
  19834. {0x00}, 0,
  19835. /* msg, msg length */
  19836. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19837. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19838. /* ct, ct length */
  19839. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19840. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19841. /* tag, tag length */
  19842. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19843. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19844. /* valid */
  19845. 0,
  19846. },
  19847. {
  19848. /* key, key length */
  19849. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19850. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19851. /* iv, iv length */
  19852. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19853. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19854. /* aad, aad length */
  19855. {0x00}, 0,
  19856. /* msg, msg length */
  19857. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19858. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19859. /* ct, ct length */
  19860. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19861. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19862. /* tag, tag length */
  19863. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19864. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19865. /* valid */
  19866. 0,
  19867. },
  19868. {
  19869. /* key, key length */
  19870. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19871. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19872. /* iv, iv length */
  19873. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19874. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19875. /* aad, aad length */
  19876. {0x00}, 0,
  19877. /* msg, msg length */
  19878. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19879. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19880. /* ct, ct length */
  19881. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19882. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19883. /* tag, tag length */
  19884. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19885. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  19886. /* valid */
  19887. 0,
  19888. },
  19889. {
  19890. /* key, key length */
  19891. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19892. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19893. /* iv, iv length */
  19894. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19895. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19896. /* aad, aad length */
  19897. {0x00}, 0,
  19898. /* msg, msg length */
  19899. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19900. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19901. /* ct, ct length */
  19902. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19903. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19904. /* tag, tag length */
  19905. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19906. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  19907. /* valid */
  19908. 0,
  19909. },
  19910. {
  19911. /* key, key length */
  19912. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19913. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19914. /* iv, iv length */
  19915. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19916. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19917. /* aad, aad length */
  19918. {0x00}, 0,
  19919. /* msg, msg length */
  19920. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19921. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19922. /* ct, ct length */
  19923. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19924. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19925. /* tag, tag length */
  19926. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19927. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  19928. /* valid */
  19929. 0,
  19930. },
  19931. {
  19932. /* key, key length */
  19933. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19934. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19935. /* iv, iv length */
  19936. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19937. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19938. /* aad, aad length */
  19939. {0x00}, 0,
  19940. /* msg, msg length */
  19941. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19942. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19943. /* ct, ct length */
  19944. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19945. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19946. /* tag, tag length */
  19947. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19948. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19949. /* valid */
  19950. 0,
  19951. },
  19952. {
  19953. /* key, key length */
  19954. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19955. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19956. /* iv, iv length */
  19957. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19958. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19959. /* aad, aad length */
  19960. {0x00}, 0,
  19961. /* msg, msg length */
  19962. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19963. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19964. /* ct, ct length */
  19965. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19966. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19967. /* tag, tag length */
  19968. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19969. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19970. /* valid */
  19971. 0,
  19972. },
  19973. {
  19974. /* key, key length */
  19975. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19976. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19977. /* iv, iv length */
  19978. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19979. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19980. /* aad, aad length */
  19981. {0x00}, 0,
  19982. /* msg, msg length */
  19983. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19984. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19985. /* ct, ct length */
  19986. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19987. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19988. /* tag, tag length */
  19989. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  19990. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19991. /* valid */
  19992. 0,
  19993. },
  19994. {
  19995. /* key, key length */
  19996. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19997. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19998. /* iv, iv length */
  19999. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20000. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20001. /* aad, aad length */
  20002. {0x00}, 0,
  20003. /* msg, msg length */
  20004. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20005. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20006. /* ct, ct length */
  20007. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20008. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20009. /* tag, tag length */
  20010. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  20011. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  20012. /* valid */
  20013. 0,
  20014. },
  20015. {
  20016. /* key, key length */
  20017. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20018. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20019. /* iv, iv length */
  20020. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20021. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20022. /* aad, aad length */
  20023. {0x00}, 0,
  20024. /* msg, msg length */
  20025. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20026. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20027. /* ct, ct length */
  20028. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20029. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20030. /* tag, tag length */
  20031. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  20032. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  20033. /* valid */
  20034. 0,
  20035. },
  20036. {
  20037. /* key, key length */
  20038. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20039. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20040. /* iv, iv length */
  20041. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20042. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20043. /* aad, aad length */
  20044. {0x00}, 0,
  20045. /* msg, msg length */
  20046. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20047. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20048. /* ct, ct length */
  20049. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20050. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20051. /* tag, tag length */
  20052. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20053. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  20054. /* valid */
  20055. 0,
  20056. },
  20057. {
  20058. /* key, key length */
  20059. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20060. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20061. /* iv, iv length */
  20062. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20063. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20064. /* aad, aad length */
  20065. {0x00}, 0,
  20066. /* msg, msg length */
  20067. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20068. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20069. /* ct, ct length */
  20070. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20071. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20072. /* tag, tag length */
  20073. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  20074. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  20075. /* valid */
  20076. 0,
  20077. },
  20078. {
  20079. /* key, key length */
  20080. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20081. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20082. /* iv, iv length */
  20083. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20084. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20085. /* aad, aad length */
  20086. {0x00}, 0,
  20087. /* msg, msg length */
  20088. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20089. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20090. /* ct, ct length */
  20091. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20092. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20093. /* tag, tag length */
  20094. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  20095. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  20096. /* valid */
  20097. 0,
  20098. },
  20099. {
  20100. /* key, key length */
  20101. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20102. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20103. /* iv, iv length */
  20104. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20105. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20106. /* aad, aad length */
  20107. {0x00}, 0,
  20108. /* msg, msg length */
  20109. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20110. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20111. /* ct, ct length */
  20112. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20113. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20114. /* tag, tag length */
  20115. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  20116. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  20117. /* valid */
  20118. 0,
  20119. },
  20120. };
  20121. byte ciphertext[sizeof(vectors[0].ct)];
  20122. byte authtag[sizeof(vectors[0].tag)];
  20123. int i;
  20124. int len;
  20125. int ret;
  20126. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  20127. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20128. len = sizeof(authtag);
  20129. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  20130. ciphertext,
  20131. vectors[i].msg, vectors[i].msg_length,
  20132. vectors[i].iv, vectors[i].iv_length,
  20133. authtag, len,
  20134. vectors[i].aad, vectors[i].aad_length),
  20135. 0);
  20136. /* check ciphertext matches vector */
  20137. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  20138. 0);
  20139. /* check that computed tag matches vector only for vectors marked as valid */
  20140. ret = XMEMCMP(authtag, vectors[i].tag, len);
  20141. if (vectors[i].valid) {
  20142. ExpectIntEQ(ret, 0);
  20143. }
  20144. else {
  20145. ExpectIntNE(ret, 0);
  20146. }
  20147. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20148. /* Decrypt, checking that the computed auth tags match */
  20149. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  20150. ciphertext,
  20151. vectors[i].ct, vectors[i].ct_length,
  20152. vectors[i].iv, vectors[i].iv_length,
  20153. authtag, len,
  20154. vectors[i].aad, vectors[i].aad_length),
  20155. 0);
  20156. /* check decrypted ciphertext matches vector plaintext */
  20157. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  20158. 0);
  20159. }
  20160. return EXPECT_RESULT();
  20161. } /* END test_wc_AesEaxVectors */
  20162. /*
  20163. * Testing test_wc_AesEaxEncryptAuth()
  20164. */
  20165. static int test_wc_AesEaxEncryptAuth(void)
  20166. {
  20167. EXPECT_DECLS;
  20168. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20169. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20170. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20171. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20172. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20173. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20174. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20175. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20176. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20177. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20178. byte ciphertext[sizeof(msg)];
  20179. byte authtag[AES_BLOCK_SIZE];
  20180. int i;
  20181. int len;
  20182. len = sizeof(authtag);
  20183. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20184. ciphertext,
  20185. msg, sizeof(msg),
  20186. iv, sizeof(iv),
  20187. authtag, (word32)len,
  20188. aad, sizeof(aad)),
  20189. 0);
  20190. /* Test null checking */
  20191. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  20192. ciphertext,
  20193. msg, sizeof(msg),
  20194. iv, sizeof(iv),
  20195. authtag, (word32)len,
  20196. aad, sizeof(aad)),
  20197. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20198. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20199. NULL,
  20200. msg, sizeof(msg),
  20201. iv, sizeof(iv),
  20202. authtag, (word32)len,
  20203. aad, sizeof(aad)),
  20204. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20205. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20206. ciphertext,
  20207. NULL, sizeof(msg),
  20208. iv, sizeof(iv),
  20209. authtag, (word32)len,
  20210. aad, sizeof(aad)),
  20211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20212. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20213. ciphertext,
  20214. msg, sizeof(msg),
  20215. NULL, sizeof(iv),
  20216. authtag, (word32)len,
  20217. aad, sizeof(aad)),
  20218. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20219. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20220. ciphertext,
  20221. msg, sizeof(msg),
  20222. iv, sizeof(iv),
  20223. NULL, (word32)len,
  20224. aad, sizeof(aad)),
  20225. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20226. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20227. ciphertext,
  20228. msg, sizeof(msg),
  20229. iv, sizeof(iv),
  20230. authtag, (word32)len,
  20231. NULL, sizeof(aad)),
  20232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20233. /* Test bad key lengths */
  20234. for (i = 0; i <= 32; i++) {
  20235. int exp_ret;
  20236. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20237. || i == AES_256_KEY_SIZE) {
  20238. exp_ret = 0;
  20239. }
  20240. else {
  20241. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20242. }
  20243. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  20244. ciphertext,
  20245. msg, sizeof(msg),
  20246. iv, sizeof(iv),
  20247. authtag, (word32)len,
  20248. aad, sizeof(aad)),
  20249. exp_ret);
  20250. }
  20251. /* Test auth tag size out of range */
  20252. len = AES_BLOCK_SIZE + 1;
  20253. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20254. ciphertext,
  20255. msg, sizeof(msg),
  20256. iv, sizeof(iv),
  20257. authtag, (word32)len,
  20258. aad, sizeof(aad)),
  20259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20260. return EXPECT_RESULT();
  20261. } /* END test_wc_AesEaxEncryptAuth() */
  20262. /*
  20263. * Testing test_wc_AesEaxDecryptAuth()
  20264. */
  20265. static int test_wc_AesEaxDecryptAuth(void)
  20266. {
  20267. EXPECT_DECLS;
  20268. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20269. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20270. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20271. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20272. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20273. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20274. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20275. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20276. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20277. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20278. /* Garbage tag that should always fail for above aad */
  20279. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  20280. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  20281. byte plaintext[sizeof(ct)];
  20282. int i;
  20283. int len;
  20284. len = sizeof(tag);
  20285. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20286. plaintext,
  20287. ct, sizeof(ct),
  20288. iv, sizeof(iv),
  20289. tag, (word32)len,
  20290. aad, sizeof(aad)),
  20291. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  20292. /* Test null checking */
  20293. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  20294. plaintext,
  20295. ct, sizeof(ct),
  20296. iv, sizeof(iv),
  20297. tag, (word32)len,
  20298. aad, sizeof(aad)),
  20299. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20300. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20301. NULL,
  20302. ct, sizeof(ct),
  20303. iv, sizeof(iv),
  20304. tag, (word32)len,
  20305. aad, sizeof(aad)),
  20306. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20307. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20308. plaintext,
  20309. NULL, sizeof(ct),
  20310. iv, sizeof(iv),
  20311. tag, (word32)len,
  20312. aad, sizeof(aad)),
  20313. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20314. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20315. plaintext,
  20316. ct, sizeof(ct),
  20317. NULL, sizeof(iv),
  20318. tag, (word32)len,
  20319. aad, sizeof(aad)),
  20320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20321. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20322. plaintext,
  20323. ct, sizeof(ct),
  20324. iv, sizeof(iv),
  20325. NULL, (word32)len,
  20326. aad, sizeof(aad)),
  20327. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20328. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20329. plaintext,
  20330. ct, sizeof(ct),
  20331. iv, sizeof(iv),
  20332. tag, (word32)len,
  20333. NULL, sizeof(aad)),
  20334. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20335. /* Test bad key lengths */
  20336. for (i = 0; i <= 32; i++) {
  20337. int exp_ret;
  20338. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20339. || i == AES_256_KEY_SIZE) {
  20340. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  20341. }
  20342. else {
  20343. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20344. }
  20345. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  20346. plaintext,
  20347. ct, sizeof(ct),
  20348. iv, sizeof(iv),
  20349. tag, (word32)len,
  20350. aad, sizeof(aad)),
  20351. exp_ret);
  20352. }
  20353. /* Test auth tag size out of range */
  20354. len = AES_BLOCK_SIZE + 1;
  20355. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20356. plaintext,
  20357. ct, sizeof(ct),
  20358. iv, sizeof(iv),
  20359. tag, (word32)len,
  20360. aad, sizeof(aad)),
  20361. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20362. return EXPECT_RESULT();
  20363. } /* END test_wc_AesEaxDecryptAuth() */
  20364. #endif /* WOLFSSL_AES_EAX &&
  20365. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  20366. */
  20367. /*
  20368. * Testing wc_InitDsaKey()
  20369. */
  20370. static int test_wc_InitDsaKey(void)
  20371. {
  20372. EXPECT_DECLS;
  20373. #ifndef NO_DSA
  20374. DsaKey key;
  20375. XMEMSET(&key, 0, sizeof(DsaKey));
  20376. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20377. /* Pass in bad args. */
  20378. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20379. wc_FreeDsaKey(&key);
  20380. #endif
  20381. return EXPECT_RESULT();
  20382. } /* END test_wc_InitDsaKey */
  20383. /*
  20384. * Testing wc_DsaSign() and wc_DsaVerify()
  20385. */
  20386. static int test_wc_DsaSignVerify(void)
  20387. {
  20388. EXPECT_DECLS;
  20389. #if !defined(NO_DSA)
  20390. DsaKey key;
  20391. WC_RNG rng;
  20392. wc_Sha sha;
  20393. byte signature[DSA_SIG_SIZE];
  20394. byte hash[WC_SHA_DIGEST_SIZE];
  20395. word32 idx = 0;
  20396. word32 bytes;
  20397. int answer;
  20398. #ifdef USE_CERT_BUFFERS_1024
  20399. byte tmp[ONEK_BUF];
  20400. XMEMSET(tmp, 0, sizeof(tmp));
  20401. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20402. bytes = sizeof_dsa_key_der_1024;
  20403. #elif defined(USE_CERT_BUFFERS_2048)
  20404. byte tmp[TWOK_BUF];
  20405. XMEMSET(tmp, 0, sizeof(tmp));
  20406. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20407. bytes = sizeof_dsa_key_der_2048;
  20408. #else
  20409. byte tmp[TWOK_BUF];
  20410. XFILE fp = XBADFILE;
  20411. XMEMSET(tmp, 0, sizeof(tmp));
  20412. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20413. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20414. if (fp != XBADFILE)
  20415. XFCLOSE(fp);
  20416. #endif /* END USE_CERT_BUFFERS_1024 */
  20417. ExpectIntEQ(wc_InitSha(&sha), 0);
  20418. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  20419. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  20420. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20421. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20422. ExpectIntEQ(wc_InitRng(&rng), 0);
  20423. /* Sign. */
  20424. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  20425. /* Test bad args. */
  20426. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20427. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20428. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20429. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20430. /* Verify. */
  20431. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  20432. ExpectIntEQ(answer, 1);
  20433. /* Pass in bad args. */
  20434. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20435. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20436. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20437. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20438. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  20439. /* hard set q to 0 and test fail case */
  20440. mp_free(&key.q);
  20441. mp_init(&key.q);
  20442. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20443. mp_set(&key.q, 1);
  20444. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20445. #endif
  20446. DoExpectIntEQ(wc_FreeRng(&rng),0);
  20447. wc_FreeDsaKey(&key);
  20448. wc_ShaFree(&sha);
  20449. #endif
  20450. return EXPECT_RESULT();
  20451. } /* END test_wc_DsaSign */
  20452. /*
  20453. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20454. */
  20455. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20456. {
  20457. EXPECT_DECLS;
  20458. #if !defined(NO_DSA)
  20459. DsaKey key;
  20460. word32 bytes = 0;
  20461. word32 idx = 0;
  20462. int ret = 0;
  20463. #ifdef USE_CERT_BUFFERS_1024
  20464. byte tmp[ONEK_BUF];
  20465. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20466. bytes = sizeof_dsa_key_der_1024;
  20467. #elif defined(USE_CERT_BUFFERS_2048)
  20468. byte tmp[TWOK_BUF];
  20469. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20470. bytes = sizeof_dsa_key_der_2048;
  20471. #else
  20472. byte tmp[TWOK_BUF];
  20473. XFILE fp = XBADFILE;
  20474. XMEMSET(tmp, 0, sizeof(tmp));
  20475. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20476. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20477. if (fp != XBADFILE)
  20478. XFCLOSE(fp);
  20479. #endif /* END USE_CERT_BUFFERS_1024 */
  20480. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20481. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20482. /* Test bad args. */
  20483. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20484. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20485. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20486. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20487. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20488. wc_FreeDsaKey(&key);
  20489. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20490. idx = 0; /* Reset */
  20491. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20492. /* Test bad args. */
  20493. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20494. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20495. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20496. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20497. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20498. wc_FreeDsaKey(&key);
  20499. #endif /* !NO_DSA */
  20500. return EXPECT_RESULT();
  20501. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20502. /*
  20503. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20504. */
  20505. static int test_wc_MakeDsaKey(void)
  20506. {
  20507. EXPECT_DECLS;
  20508. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20509. DsaKey genKey;
  20510. WC_RNG rng;
  20511. XMEMSET(&genKey, 0, sizeof(genKey));
  20512. XMEMSET(&rng, 0, sizeof(rng));
  20513. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20514. ExpectIntEQ(wc_InitRng(&rng), 0);
  20515. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20516. /* Test bad args. */
  20517. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20518. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20519. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20520. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20521. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20522. /* Test bad args. */
  20523. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20524. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20525. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20526. wc_FreeDsaKey(&genKey);
  20527. #endif
  20528. return EXPECT_RESULT();
  20529. } /* END test_wc_MakeDsaKey */
  20530. /*
  20531. * Testing wc_DsaKeyToDer()
  20532. */
  20533. static int test_wc_DsaKeyToDer(void)
  20534. {
  20535. EXPECT_DECLS;
  20536. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20537. DsaKey key;
  20538. word32 bytes;
  20539. word32 idx = 0;
  20540. #ifdef USE_CERT_BUFFERS_1024
  20541. byte tmp[ONEK_BUF];
  20542. byte der[ONEK_BUF];
  20543. XMEMSET(tmp, 0, sizeof(tmp));
  20544. XMEMSET(der, 0, sizeof(der));
  20545. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20546. bytes = sizeof_dsa_key_der_1024;
  20547. #elif defined(USE_CERT_BUFFERS_2048)
  20548. byte tmp[TWOK_BUF];
  20549. byte der[TWOK_BUF];
  20550. XMEMSET(tmp, 0, sizeof(tmp));
  20551. XMEMSET(der, 0, sizeof(der));
  20552. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20553. bytes = sizeof_dsa_key_der_2048;
  20554. #else
  20555. byte tmp[TWOK_BUF];
  20556. byte der[TWOK_BUF];
  20557. XFILE fp = XBADFILE;
  20558. XMEMSET(tmp, 0, sizeof(tmp));
  20559. XMEMSET(der, 0, sizeof(der));
  20560. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20561. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20562. if (fp != XBADFILE)
  20563. XFCLOSE(fp);
  20564. #endif /* END USE_CERT_BUFFERS_1024 */
  20565. XMEMSET(&key, 0, sizeof(DsaKey));
  20566. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20567. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20568. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20569. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20570. /* Test bad args. */
  20571. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20572. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20573. wc_FreeDsaKey(&key);
  20574. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20575. return EXPECT_RESULT();
  20576. } /* END test_wc_DsaKeyToDer */
  20577. /*
  20578. * Testing wc_DsaKeyToPublicDer()
  20579. * (indirectly testing setDsaPublicKey())
  20580. */
  20581. static int test_wc_DsaKeyToPublicDer(void)
  20582. {
  20583. EXPECT_DECLS;
  20584. #ifndef HAVE_SELFTEST
  20585. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20586. DsaKey key;
  20587. WC_RNG rng;
  20588. byte* der = NULL;
  20589. word32 sz = 0;
  20590. word32 idx = 0;
  20591. XMEMSET(&key, 0, sizeof(DsaKey));
  20592. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20593. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20594. DYNAMIC_TYPE_TMP_BUFFER));
  20595. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20596. ExpectIntEQ(wc_InitRng(&rng), 0);
  20597. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20598. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20599. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20600. wc_FreeDsaKey(&key);
  20601. idx = 0;
  20602. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20603. /* Test without the SubjectPublicKeyInfo header */
  20604. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20605. wc_FreeDsaKey(&key);
  20606. idx = 0;
  20607. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20608. /* Test bad args. */
  20609. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20610. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20611. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20612. wc_FreeDsaKey(&key);
  20613. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20614. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20615. #endif /* !HAVE_SELFTEST */
  20616. return EXPECT_RESULT();
  20617. } /* END test_wc_DsaKeyToPublicDer */
  20618. /*
  20619. * Testing wc_DsaImportParamsRaw()
  20620. */
  20621. static int test_wc_DsaImportParamsRaw(void)
  20622. {
  20623. EXPECT_DECLS;
  20624. #if !defined(NO_DSA)
  20625. DsaKey key;
  20626. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20627. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20628. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20629. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20630. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20631. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20632. "80a0093113a8bd73";
  20633. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20634. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20635. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20636. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20637. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20638. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20639. "76341a7e7d9";
  20640. /* invalid p and q parameters */
  20641. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20642. const char* invalidQ = "96c5390a";
  20643. XMEMSET(&key, 0, sizeof(DsaKey));
  20644. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20645. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20646. /* test bad args */
  20647. /* null key struct */
  20648. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20649. /* null param pointers */
  20650. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20651. /* illegal p length */
  20652. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20653. /* illegal q length */
  20654. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20655. wc_FreeDsaKey(&key);
  20656. #endif
  20657. return EXPECT_RESULT();
  20658. } /* END test_wc_DsaImportParamsRaw */
  20659. /*
  20660. * Testing wc_DsaImportParamsRawCheck()
  20661. */
  20662. static int test_wc_DsaImportParamsRawCheck(void)
  20663. {
  20664. EXPECT_DECLS;
  20665. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20666. DsaKey key;
  20667. int trusted = 0;
  20668. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20669. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20670. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20671. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20672. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20673. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20674. "80a0093113a8bd73";
  20675. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20676. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20677. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20678. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20679. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20680. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20681. "76341a7e7d9";
  20682. /* invalid p and q parameters */
  20683. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20684. const char* invalidQ = "96c5390a";
  20685. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20686. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20687. /* test bad args */
  20688. /* null key struct */
  20689. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20690. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20691. /* null param pointers */
  20692. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20693. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20694. /* illegal p length */
  20695. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20696. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20697. /* illegal q length */
  20698. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20699. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20700. wc_FreeDsaKey(&key);
  20701. #endif
  20702. return EXPECT_RESULT();
  20703. } /* END test_wc_DsaImportParamsRawCheck */
  20704. /*
  20705. * Testing wc_DsaExportParamsRaw()
  20706. */
  20707. static int test_wc_DsaExportParamsRaw(void)
  20708. {
  20709. EXPECT_DECLS;
  20710. #if !defined(NO_DSA)
  20711. DsaKey key;
  20712. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20713. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20714. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20715. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20716. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20717. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20718. "80a0093113a8bd73";
  20719. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20720. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20721. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20722. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20723. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20724. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20725. "76341a7e7d9";
  20726. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20727. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20728. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20729. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20730. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20731. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20732. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20733. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20734. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20735. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20736. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20737. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20738. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20739. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20740. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20741. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20742. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20743. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20744. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20745. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20746. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20747. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20748. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20749. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20750. byte pOut[MAX_DSA_PARAM_SIZE];
  20751. byte qOut[MAX_DSA_PARAM_SIZE];
  20752. byte gOut[MAX_DSA_PARAM_SIZE];
  20753. word32 pOutSz;
  20754. word32 qOutSz;
  20755. word32 gOutSz;
  20756. XMEMSET(&key, 0, sizeof(DsaKey));
  20757. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20758. /* first test using imported raw parameters, for expected */
  20759. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20760. pOutSz = sizeof(pOut);
  20761. qOutSz = sizeof(qOut);
  20762. gOutSz = sizeof(gOut);
  20763. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20764. &gOutSz), 0);
  20765. /* validate exported parameters are correct */
  20766. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20767. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20768. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20769. /* test bad args */
  20770. /* null key struct */
  20771. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20772. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20773. /* null output pointers */
  20774. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20775. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20776. /* null output size pointers */
  20777. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20778. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20779. /* p output buffer size too small */
  20780. pOutSz = 1;
  20781. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20782. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20783. pOutSz = sizeof(pOut);
  20784. /* q output buffer size too small */
  20785. qOutSz = 1;
  20786. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20787. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20788. qOutSz = sizeof(qOut);
  20789. /* g output buffer size too small */
  20790. gOutSz = 1;
  20791. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20792. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20793. wc_FreeDsaKey(&key);
  20794. #endif
  20795. return EXPECT_RESULT();
  20796. } /* END test_wc_DsaExportParamsRaw */
  20797. /*
  20798. * Testing wc_DsaExportKeyRaw()
  20799. */
  20800. static int test_wc_DsaExportKeyRaw(void)
  20801. {
  20802. EXPECT_DECLS;
  20803. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20804. DsaKey key;
  20805. WC_RNG rng;
  20806. byte xOut[MAX_DSA_PARAM_SIZE];
  20807. byte yOut[MAX_DSA_PARAM_SIZE];
  20808. word32 xOutSz, yOutSz;
  20809. XMEMSET(&key, 0, sizeof(key));
  20810. XMEMSET(&rng, 0, sizeof(rng));
  20811. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20812. ExpectIntEQ(wc_InitRng(&rng), 0);
  20813. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20814. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20815. /* try successful export */
  20816. xOutSz = sizeof(xOut);
  20817. yOutSz = sizeof(yOut);
  20818. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20819. /* test bad args */
  20820. /* null key struct */
  20821. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20822. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20823. /* null output pointers */
  20824. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20825. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20826. /* null output size pointers */
  20827. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20828. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20829. /* x output buffer size too small */
  20830. xOutSz = 1;
  20831. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20832. WC_NO_ERR_TRACE(BUFFER_E));
  20833. xOutSz = sizeof(xOut);
  20834. /* y output buffer size too small */
  20835. yOutSz = 1;
  20836. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20837. WC_NO_ERR_TRACE(BUFFER_E));
  20838. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20839. wc_FreeDsaKey(&key);
  20840. #endif
  20841. return EXPECT_RESULT();
  20842. } /* END test_wc_DsaExportParamsRaw */
  20843. /*
  20844. * Testing wc_ed25519_make_key().
  20845. */
  20846. static int test_wc_ed25519_make_key(void)
  20847. {
  20848. EXPECT_DECLS;
  20849. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20850. ed25519_key key;
  20851. WC_RNG rng;
  20852. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20853. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20854. XMEMSET(&key, 0, sizeof(ed25519_key));
  20855. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20856. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20857. ExpectIntEQ(wc_InitRng(&rng), 0);
  20858. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20859. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20860. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20861. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20862. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20863. /* Test bad args. */
  20864. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20865. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20866. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20867. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20868. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20869. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20870. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  20871. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20872. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20873. wc_ed25519_free(&key);
  20874. #endif
  20875. return EXPECT_RESULT();
  20876. } /* END test_wc_ed25519_make_key */
  20877. /*
  20878. * Testing wc_ed25519_init()
  20879. */
  20880. static int test_wc_ed25519_init(void)
  20881. {
  20882. EXPECT_DECLS;
  20883. #if defined(HAVE_ED25519)
  20884. ed25519_key key;
  20885. XMEMSET(&key, 0, sizeof(ed25519_key));
  20886. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20887. /* Test bad args. */
  20888. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20889. wc_ed25519_free(&key);
  20890. #endif
  20891. return EXPECT_RESULT();
  20892. } /* END test_wc_ed25519_init */
  20893. /*
  20894. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  20895. */
  20896. static int test_wc_ed25519_sign_msg(void)
  20897. {
  20898. EXPECT_DECLS;
  20899. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  20900. WC_RNG rng;
  20901. ed25519_key key;
  20902. byte msg[] = "Everybody gets Friday off.\n";
  20903. byte sig[ED25519_SIG_SIZE+1];
  20904. word32 msglen = sizeof(msg);
  20905. word32 siglen = ED25519_SIG_SIZE;
  20906. word32 badSigLen = ED25519_SIG_SIZE - 1;
  20907. #ifdef HAVE_ED25519_VERIFY
  20908. int verify_ok = 0; /*1 = Verify success.*/
  20909. #endif
  20910. /* Initialize stack variables. */
  20911. XMEMSET(&key, 0, sizeof(ed25519_key));
  20912. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20913. XMEMSET(sig, 0, sizeof(sig));
  20914. /* Initialize key. */
  20915. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20916. ExpectIntEQ(wc_InitRng(&rng), 0);
  20917. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20918. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  20919. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20920. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  20921. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20922. /* Test bad args. */
  20923. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  20924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20925. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  20926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20927. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  20928. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20929. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  20930. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20931. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  20932. WC_NO_ERR_TRACE(BUFFER_E));
  20933. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  20934. badSigLen -= 1;
  20935. #ifdef HAVE_ED25519_VERIFY
  20936. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20937. &key), 0);
  20938. ExpectIntEQ(verify_ok, 1);
  20939. /* Test bad args. */
  20940. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  20941. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20942. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  20943. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20944. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  20945. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20946. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  20947. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20948. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  20949. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20950. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20951. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20952. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  20953. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20954. #endif /* Verify. */
  20955. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20956. wc_ed25519_free(&key);
  20957. #endif
  20958. return EXPECT_RESULT();
  20959. } /* END test_wc_ed25519_sign_msg */
  20960. /*
  20961. * Testing wc_ed25519_import_public()
  20962. */
  20963. static int test_wc_ed25519_import_public(void)
  20964. {
  20965. EXPECT_DECLS;
  20966. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20967. ed25519_key pubKey;
  20968. WC_RNG rng;
  20969. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  20970. word32 inlen = sizeof(in);
  20971. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  20972. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20973. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  20974. ExpectIntEQ(wc_InitRng(&rng), 0);
  20975. #ifdef HAVE_ED25519_MAKE_KEY
  20976. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  20977. #endif
  20978. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  20979. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  20980. /* Test bad args. */
  20981. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20982. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20983. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20984. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20985. wc_ed25519_free(&pubKey);
  20986. #endif
  20987. return EXPECT_RESULT();
  20988. } /* END wc_ed25519_import_public */
  20989. /*
  20990. * Testing wc_ed25519_import_private_key()
  20991. */
  20992. static int test_wc_ed25519_import_private_key(void)
  20993. {
  20994. EXPECT_DECLS;
  20995. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20996. ed25519_key key;
  20997. WC_RNG rng;
  20998. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  20999. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  21000. word32 privKeySz = sizeof(privKey);
  21001. word32 pubKeySz = sizeof(pubKey);
  21002. #ifdef HAVE_ED25519_KEY_EXPORT
  21003. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21004. word32 bothKeysSz = sizeof(bothKeys);
  21005. #endif
  21006. XMEMSET(&key, 0, sizeof(ed25519_key));
  21007. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21008. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21009. ExpectIntEQ(wc_InitRng(&rng), 0);
  21010. #ifdef HAVE_ED25519_MAKE_KEY
  21011. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21012. #endif
  21013. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  21014. pubKeySz, &key, 1), 0);
  21015. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21016. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21017. #ifdef HAVE_ED25519_KEY_EXPORT
  21018. PRIVATE_KEY_UNLOCK();
  21019. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  21020. PRIVATE_KEY_LOCK();
  21021. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21022. &key, 1), 0);
  21023. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21024. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21025. #endif
  21026. /* Test bad args. */
  21027. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21028. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21029. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  21030. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21031. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21032. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21033. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  21034. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21035. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21036. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21037. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  21038. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21039. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21040. wc_ed25519_free(&key);
  21041. #endif
  21042. return EXPECT_RESULT();
  21043. } /* END test_wc_ed25519_import_private_key */
  21044. /*
  21045. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  21046. */
  21047. static int test_wc_ed25519_export(void)
  21048. {
  21049. EXPECT_DECLS;
  21050. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21051. ed25519_key key;
  21052. WC_RNG rng;
  21053. byte priv[ED25519_PRV_KEY_SIZE];
  21054. byte pub[ED25519_PUB_KEY_SIZE];
  21055. word32 privSz = sizeof(priv);
  21056. word32 pubSz = sizeof(pub);
  21057. #ifndef HAVE_ED25519_MAKE_KEY
  21058. const byte privKey[] = {
  21059. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21060. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21061. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21062. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21063. };
  21064. const byte pubKey[] = {
  21065. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21066. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21067. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21068. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21069. };
  21070. #endif
  21071. XMEMSET(&key, 0, sizeof(ed25519_key));
  21072. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21073. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21074. ExpectIntEQ(wc_InitRng(&rng), 0);
  21075. #ifdef HAVE_ED25519_MAKE_KEY
  21076. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21077. #else
  21078. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21079. pubKey, sizeof(pubKey), &key, 1), 0);
  21080. #endif
  21081. PRIVATE_KEY_UNLOCK();
  21082. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  21083. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  21084. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21085. /* Test bad args. */
  21086. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21087. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21088. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21089. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  21090. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  21091. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21092. /* Test bad args. */
  21093. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  21094. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21095. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  21096. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21097. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  21098. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21099. PRIVATE_KEY_LOCK();
  21100. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21101. wc_ed25519_free(&key);
  21102. #endif
  21103. return EXPECT_RESULT();
  21104. } /* END test_wc_ed25519_export */
  21105. /*
  21106. * Testing wc_ed25519_size()
  21107. */
  21108. static int test_wc_ed25519_size(void)
  21109. {
  21110. EXPECT_DECLS;
  21111. #if defined(HAVE_ED25519)
  21112. ed25519_key key;
  21113. WC_RNG rng;
  21114. #ifndef HAVE_ED25519_MAKE_KEY
  21115. const byte privKey[] = {
  21116. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21117. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21118. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21119. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21120. };
  21121. const byte pubKey[] = {
  21122. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21123. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21124. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21125. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21126. };
  21127. #endif
  21128. XMEMSET(&key, 0, sizeof(ed25519_key));
  21129. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21130. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21131. ExpectIntEQ(wc_InitRng(&rng), 0);
  21132. #ifdef HAVE_ED25519_MAKE_KEY
  21133. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21134. #else
  21135. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21136. pubKey, sizeof(pubKey), &key, 1), 0);
  21137. #endif
  21138. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  21139. /* Test bad args. */
  21140. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21141. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  21142. /* Test bad args. */
  21143. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21144. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  21145. /* Test bad args. */
  21146. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21147. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  21148. /* Test bad args. */
  21149. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21150. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21151. wc_ed25519_free(&key);
  21152. #endif
  21153. return EXPECT_RESULT();
  21154. } /* END test_wc_ed25519_size */
  21155. /*
  21156. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  21157. */
  21158. static int test_wc_ed25519_exportKey(void)
  21159. {
  21160. EXPECT_DECLS;
  21161. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21162. WC_RNG rng;
  21163. ed25519_key key;
  21164. byte priv[ED25519_PRV_KEY_SIZE];
  21165. byte pub[ED25519_PUB_KEY_SIZE];
  21166. byte privOnly[ED25519_PRV_KEY_SIZE];
  21167. word32 privSz = sizeof(priv);
  21168. word32 pubSz = sizeof(pub);
  21169. word32 privOnlySz = sizeof(privOnly);
  21170. #ifndef HAVE_ED25519_MAKE_KEY
  21171. const byte privKey[] = {
  21172. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21173. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21174. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21175. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21176. };
  21177. const byte pubKey[] = {
  21178. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21179. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21180. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21181. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21182. };
  21183. #endif
  21184. XMEMSET(&key, 0, sizeof(ed25519_key));
  21185. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21186. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21187. ExpectIntEQ(wc_InitRng(&rng), 0);
  21188. #ifdef HAVE_ED25519_MAKE_KEY
  21189. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21190. #else
  21191. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21192. pubKey, sizeof(pubKey), &key, 1), 0);
  21193. #endif
  21194. PRIVATE_KEY_UNLOCK();
  21195. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  21196. /* Test bad args. */
  21197. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  21198. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21199. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  21200. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21201. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21202. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21203. /* Test bad args. */
  21204. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  21205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21206. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  21207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21208. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  21209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21210. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  21211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21212. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  21213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21214. PRIVATE_KEY_LOCK();
  21215. /* Cross check output. */
  21216. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21217. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21218. wc_ed25519_free(&key);
  21219. #endif
  21220. return EXPECT_RESULT();
  21221. } /* END test_wc_ed25519_exportKey */
  21222. /*
  21223. * Testing wc_Ed25519PublicKeyToDer
  21224. */
  21225. static int test_wc_Ed25519PublicKeyToDer(void)
  21226. {
  21227. EXPECT_DECLS;
  21228. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  21229. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21230. ed25519_key key;
  21231. byte derBuf[1024];
  21232. XMEMSET(&key, 0, sizeof(ed25519_key));
  21233. /* Test bad args */
  21234. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21235. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21236. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21237. wc_ed25519_free(&key);
  21238. /* Test good args */
  21239. if (EXPECT_SUCCESS()) {
  21240. WC_RNG rng;
  21241. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21242. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21243. ExpectIntEQ(wc_InitRng(&rng), 0);
  21244. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21245. /* length only */
  21246. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  21247. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  21248. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  21249. (word32)sizeof(derBuf), 1), 0);
  21250. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21251. wc_ed25519_free(&key);
  21252. }
  21253. #endif
  21254. return EXPECT_RESULT();
  21255. } /* END testing wc_Ed25519PublicKeyToDer */
  21256. /*
  21257. * Testing wc_curve25519_init and wc_curve25519_free.
  21258. */
  21259. static int test_wc_curve25519_init(void)
  21260. {
  21261. EXPECT_DECLS;
  21262. #if defined(HAVE_CURVE25519)
  21263. curve25519_key key;
  21264. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21265. /* Test bad args for wc_curve25519_init */
  21266. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21267. /* Test good args for wc_curve_25519_free */
  21268. wc_curve25519_free(&key);
  21269. /* Test bad args for wc_curve25519 free. */
  21270. wc_curve25519_free(NULL);
  21271. #endif
  21272. return EXPECT_RESULT();
  21273. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  21274. /*
  21275. * Testing test_wc_curve25519_size.
  21276. */
  21277. static int test_wc_curve25519_size(void)
  21278. {
  21279. EXPECT_DECLS;
  21280. #if defined(HAVE_CURVE25519)
  21281. curve25519_key key;
  21282. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21283. /* Test good args for wc_curve25519_size */
  21284. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21285. /* Test bad args for wc_curve25519_size */
  21286. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  21287. wc_curve25519_free(&key);
  21288. #endif
  21289. return EXPECT_RESULT();
  21290. } /* END test_wc_curve25519_size*/
  21291. /*
  21292. * Testing test_wc_curve25519_export_key_raw().
  21293. */
  21294. static int test_wc_curve25519_export_key_raw(void)
  21295. {
  21296. EXPECT_DECLS;
  21297. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21298. curve25519_key key;
  21299. WC_RNG rng;
  21300. byte privateKey[CURVE25519_KEYSIZE];
  21301. byte publicKey[CURVE25519_KEYSIZE];
  21302. word32 prvkSz;
  21303. word32 pubkSz;
  21304. byte prik[CURVE25519_KEYSIZE];
  21305. byte pubk[CURVE25519_KEYSIZE];
  21306. word32 prksz;
  21307. word32 pbksz;
  21308. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21309. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21310. ExpectIntEQ(wc_InitRng(&rng), 0);
  21311. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21312. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21313. prvkSz = CURVE25519_KEYSIZE;
  21314. pubkSz = CURVE25519_KEYSIZE;
  21315. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  21316. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21317. prvkSz = CURVE25519_KEYSIZE;
  21318. pubkSz = CURVE25519_KEYSIZE;
  21319. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  21320. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21321. prvkSz = CURVE25519_KEYSIZE;
  21322. pubkSz = CURVE25519_KEYSIZE;
  21323. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  21324. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21325. /* prvkSz = CURVE25519_KEYSIZE; */
  21326. pubkSz = CURVE25519_KEYSIZE;
  21327. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21328. NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21329. prvkSz = CURVE25519_KEYSIZE;
  21330. pubkSz = CURVE25519_KEYSIZE;
  21331. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21332. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21333. /* cross-testing */
  21334. prksz = CURVE25519_KEYSIZE;
  21335. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  21336. pbksz = CURVE25519_KEYSIZE;
  21337. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  21338. prvkSz = CURVE25519_KEYSIZE;
  21339. /* pubkSz = CURVE25519_KEYSIZE; */
  21340. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21341. publicKey, &pubkSz), 0);
  21342. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21343. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21344. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21345. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21346. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21347. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21348. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21349. wc_curve25519_free(&key);
  21350. #endif
  21351. return EXPECT_RESULT();
  21352. } /* end of test_wc_curve25519_export_key_raw */
  21353. /*
  21354. * Testing test_wc_curve25519_export_key_raw_ex().
  21355. */
  21356. static int test_wc_curve25519_export_key_raw_ex(void)
  21357. {
  21358. EXPECT_DECLS;
  21359. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21360. curve25519_key key;
  21361. WC_RNG rng;
  21362. byte privateKey[CURVE25519_KEYSIZE];
  21363. byte publicKey[CURVE25519_KEYSIZE];
  21364. word32 prvkSz;
  21365. word32 pubkSz;
  21366. byte prik[CURVE25519_KEYSIZE];
  21367. byte pubk[CURVE25519_KEYSIZE];
  21368. word32 prksz;
  21369. word32 pbksz;
  21370. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21371. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21372. ExpectIntEQ(wc_InitRng(&rng), 0);
  21373. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21374. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21375. prvkSz = CURVE25519_KEYSIZE;
  21376. pubkSz = CURVE25519_KEYSIZE;
  21377. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21378. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21379. prvkSz = CURVE25519_KEYSIZE;
  21380. pubkSz = CURVE25519_KEYSIZE;
  21381. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21382. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21383. prvkSz = CURVE25519_KEYSIZE;
  21384. pubkSz = CURVE25519_KEYSIZE;
  21385. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21386. NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21387. /* prvkSz = CURVE25519_KEYSIZE; */
  21388. pubkSz = CURVE25519_KEYSIZE;
  21389. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21390. &prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21391. prvkSz = CURVE25519_KEYSIZE;
  21392. pubkSz = CURVE25519_KEYSIZE;
  21393. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21394. &prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21395. prvkSz = CURVE25519_KEYSIZE;
  21396. /* pubkSz = CURVE25519_KEYSIZE; */
  21397. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21398. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21399. prvkSz = CURVE25519_KEYSIZE;
  21400. pubkSz = CURVE25519_KEYSIZE;
  21401. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21402. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21403. prvkSz = CURVE25519_KEYSIZE;
  21404. pubkSz = CURVE25519_KEYSIZE;
  21405. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21406. NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21407. /* prvkSz = CURVE25519_KEYSIZE; */
  21408. pubkSz = CURVE25519_KEYSIZE;
  21409. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21410. &prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21411. prvkSz = CURVE25519_KEYSIZE;
  21412. pubkSz = CURVE25519_KEYSIZE;
  21413. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21414. &prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21415. /* illegal value for endian */
  21416. prvkSz = CURVE25519_KEYSIZE;
  21417. /* pubkSz = CURVE25519_KEYSIZE; */
  21418. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21419. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21420. /* cross-testing */
  21421. prksz = CURVE25519_KEYSIZE;
  21422. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  21423. pbksz = CURVE25519_KEYSIZE;
  21424. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  21425. prvkSz = CURVE25519_KEYSIZE;
  21426. /* pubkSz = CURVE25519_KEYSIZE; */
  21427. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21428. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21429. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21430. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21431. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21432. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21433. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21434. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21435. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21436. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  21437. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21438. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21439. /* try once with another endian */
  21440. prvkSz = CURVE25519_KEYSIZE;
  21441. pubkSz = CURVE25519_KEYSIZE;
  21442. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  21443. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21444. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21445. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21446. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21447. wc_curve25519_free(&key);
  21448. #endif
  21449. return EXPECT_RESULT();
  21450. } /* end of test_wc_curve25519_export_key_raw_ex */
  21451. /*
  21452. * Testing wc_curve25519_make_key
  21453. */
  21454. static int test_wc_curve25519_make_key(void)
  21455. {
  21456. EXPECT_DECLS;
  21457. #if defined(HAVE_CURVE25519)
  21458. curve25519_key key;
  21459. WC_RNG rng;
  21460. int keysize = 0;
  21461. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21462. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21463. ExpectIntEQ(wc_InitRng(&rng), 0);
  21464. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21465. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21466. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21467. /* test bad cases*/
  21468. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21469. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21470. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21471. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21472. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21473. wc_curve25519_free(&key);
  21474. #endif
  21475. return EXPECT_RESULT();
  21476. } /* END test_wc_curve25519_make_key*/
  21477. /*
  21478. * Testing wc_curve25519_shared_secret_ex
  21479. */
  21480. static int test_wc_curve25519_shared_secret_ex(void)
  21481. {
  21482. EXPECT_DECLS;
  21483. #if defined(HAVE_CURVE25519)
  21484. curve25519_key private_key;
  21485. curve25519_key public_key;
  21486. WC_RNG rng;
  21487. byte out[CURVE25519_KEYSIZE];
  21488. word32 outLen = sizeof(out);
  21489. int endian = EC25519_BIG_ENDIAN;
  21490. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21491. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21492. ExpectIntEQ(wc_InitRng(&rng), 0);
  21493. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21494. 0);
  21495. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21496. 0);
  21497. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21498. &outLen, endian), 0);
  21499. /* test bad cases*/
  21500. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21501. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21502. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21503. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21504. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21505. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21506. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21507. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21508. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21509. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21510. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21511. * increasing to 0x8f checks for error being returned*/
  21512. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21513. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21514. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21515. outLen = outLen - 2;
  21516. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21517. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21518. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21519. wc_curve25519_free(&private_key);
  21520. wc_curve25519_free(&public_key);
  21521. #endif
  21522. return EXPECT_RESULT();
  21523. } /* END test_wc_curve25519_shared_secret_ex*/
  21524. /*
  21525. * Testing wc_curve25519_make_pub
  21526. */
  21527. static int test_wc_curve25519_make_pub(void)
  21528. {
  21529. EXPECT_DECLS;
  21530. #ifdef HAVE_CURVE25519
  21531. curve25519_key key;
  21532. WC_RNG rng;
  21533. byte out[CURVE25519_KEYSIZE];
  21534. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21535. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21536. ExpectIntEQ(wc_InitRng(&rng), 0);
  21537. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21538. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21539. (int)sizeof(key.k), key.k), 0);
  21540. /* test bad cases*/
  21541. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21542. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21543. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21544. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21545. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21546. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21547. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21548. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21549. /* verify clamping test */
  21550. key.k[0] |= ~248;
  21551. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21552. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21553. key.k[0] &= 248;
  21554. /* repeat the expected-to-succeed test. */
  21555. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21556. key.k), 0);
  21557. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21558. wc_curve25519_free(&key);
  21559. #endif
  21560. return EXPECT_RESULT();
  21561. } /* END test_wc_curve25519_make_pub */
  21562. /*
  21563. * Testing test_wc_curve25519_export_public_ex
  21564. */
  21565. static int test_wc_curve25519_export_public_ex(void)
  21566. {
  21567. EXPECT_DECLS;
  21568. #if defined(HAVE_CURVE25519)
  21569. curve25519_key key;
  21570. WC_RNG rng;
  21571. byte out[CURVE25519_KEYSIZE];
  21572. word32 outLen = sizeof(out);
  21573. int endian = EC25519_BIG_ENDIAN;
  21574. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21575. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21576. ExpectIntEQ(wc_InitRng(&rng), 0);
  21577. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21578. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21579. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21580. /* test bad cases*/
  21581. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21582. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21583. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21584. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21585. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21587. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21588. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21589. outLen = outLen - 2;
  21590. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21591. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21592. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21593. wc_curve25519_free(&key);
  21594. #endif
  21595. return EXPECT_RESULT();
  21596. } /* END test_wc_curve25519_export_public_ex*/
  21597. /*
  21598. * Testing test_wc_curve25519_import_private_raw_ex
  21599. */
  21600. static int test_wc_curve25519_import_private_raw_ex(void)
  21601. {
  21602. EXPECT_DECLS;
  21603. #if defined(HAVE_CURVE25519)
  21604. curve25519_key key;
  21605. WC_RNG rng;
  21606. byte priv[CURVE25519_KEYSIZE];
  21607. byte pub[CURVE25519_KEYSIZE];
  21608. word32 privSz = sizeof(priv);
  21609. word32 pubSz = sizeof(pub);
  21610. int endian = EC25519_BIG_ENDIAN;
  21611. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21612. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21613. ExpectIntEQ(wc_InitRng(&rng), 0);
  21614. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21615. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21616. endian), 0);
  21617. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21618. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21619. &key, endian), 0);
  21620. /* test bad cases*/
  21621. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21622. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21623. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21624. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21625. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21626. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21627. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21628. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21629. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21630. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21631. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21632. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21633. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21634. &key, EC25519_LITTLE_ENDIAN), 0);
  21635. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21636. wc_curve25519_free(&key);
  21637. #endif
  21638. return EXPECT_RESULT();
  21639. } /* END test_wc_curve25519_import_private_raw_ex*/
  21640. /*
  21641. * Testing test_wc_curve25519_import_private
  21642. */
  21643. static int test_wc_curve25519_import_private(void)
  21644. {
  21645. EXPECT_DECLS;
  21646. #if defined(HAVE_CURVE25519)
  21647. curve25519_key key;
  21648. WC_RNG rng;
  21649. byte priv[CURVE25519_KEYSIZE];
  21650. word32 privSz = sizeof(priv);
  21651. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21652. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21653. ExpectIntEQ(wc_InitRng(&rng), 0);
  21654. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21655. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21656. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21657. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21658. wc_curve25519_free(&key);
  21659. #endif
  21660. return EXPECT_RESULT();
  21661. } /* END test_wc_curve25519_import*/
  21662. /*
  21663. * Testing test_wc_curve25519_export_private_raw_ex
  21664. */
  21665. static int test_wc_curve25519_export_private_raw_ex(void)
  21666. {
  21667. EXPECT_DECLS;
  21668. #if defined(HAVE_CURVE25519)
  21669. curve25519_key key;
  21670. byte out[CURVE25519_KEYSIZE];
  21671. word32 outLen = sizeof(out);
  21672. int endian = EC25519_BIG_ENDIAN;
  21673. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21674. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21675. 0);
  21676. /* test bad cases*/
  21677. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21678. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21679. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21680. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21681. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21682. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21683. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21684. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21685. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21686. EC25519_LITTLE_ENDIAN), 0);
  21687. outLen = outLen - 2;
  21688. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21689. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21690. wc_curve25519_free(&key);
  21691. #endif
  21692. return EXPECT_RESULT();
  21693. } /* END test_wc_curve25519_export_private_raw_ex*/
  21694. /*
  21695. * Testing wc_ed448_make_key().
  21696. */
  21697. static int test_wc_ed448_make_key(void)
  21698. {
  21699. EXPECT_DECLS;
  21700. #if defined(HAVE_ED448)
  21701. ed448_key key;
  21702. WC_RNG rng;
  21703. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21704. XMEMSET(&key, 0, sizeof(ed448_key));
  21705. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21706. ExpectIntEQ(wc_ed448_init(&key), 0);
  21707. ExpectIntEQ(wc_InitRng(&rng), 0);
  21708. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21709. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21710. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21711. /* Test bad args. */
  21712. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21713. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21714. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21715. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21716. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21717. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21718. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21719. wc_ed448_free(&key);
  21720. #endif
  21721. return EXPECT_RESULT();
  21722. } /* END test_wc_ed448_make_key */
  21723. /*
  21724. * Testing wc_ed448_init()
  21725. */
  21726. static int test_wc_ed448_init(void)
  21727. {
  21728. EXPECT_DECLS;
  21729. #if defined(HAVE_ED448)
  21730. ed448_key key;
  21731. XMEMSET(&key, 0, sizeof(ed448_key));
  21732. ExpectIntEQ(wc_ed448_init(&key), 0);
  21733. /* Test bad args. */
  21734. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21735. wc_ed448_free(&key);
  21736. #endif
  21737. return EXPECT_RESULT();
  21738. } /* END test_wc_ed448_init */
  21739. /*
  21740. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21741. */
  21742. static int test_wc_ed448_sign_msg(void)
  21743. {
  21744. EXPECT_DECLS;
  21745. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21746. ed448_key key;
  21747. WC_RNG rng;
  21748. byte msg[] = "Everybody gets Friday off.\n";
  21749. byte sig[ED448_SIG_SIZE];
  21750. word32 msglen = sizeof(msg);
  21751. word32 siglen = sizeof(sig);
  21752. word32 badSigLen = sizeof(sig) - 1;
  21753. #ifdef HAVE_ED448_VERIFY
  21754. int verify_ok = 0; /*1 = Verify success.*/
  21755. #endif
  21756. /* Initialize stack variables. */
  21757. XMEMSET(&key, 0, sizeof(ed448_key));
  21758. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21759. XMEMSET(sig, 0, siglen);
  21760. /* Initialize key. */
  21761. ExpectIntEQ(wc_ed448_init(&key), 0);
  21762. ExpectIntEQ(wc_InitRng(&rng), 0);
  21763. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21764. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21765. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21766. /* Test bad args. */
  21767. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21768. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21769. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21771. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21773. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21775. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21776. WC_NO_ERR_TRACE(BUFFER_E));
  21777. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21778. badSigLen -= 1;
  21779. #ifdef HAVE_ED448_VERIFY
  21780. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21781. NULL, 0), 0);
  21782. ExpectIntEQ(verify_ok, 1);
  21783. /* Test bad args. */
  21784. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21785. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21786. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21787. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21788. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21789. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21790. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21791. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21792. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21793. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21794. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21795. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21796. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21797. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21798. #endif /* Verify. */
  21799. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21800. wc_ed448_free(&key);
  21801. #endif
  21802. return EXPECT_RESULT();
  21803. } /* END test_wc_ed448_sign_msg */
  21804. /*
  21805. * Testing wc_ed448_import_public()
  21806. */
  21807. static int test_wc_ed448_import_public(void)
  21808. {
  21809. EXPECT_DECLS;
  21810. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21811. ed448_key pubKey;
  21812. WC_RNG rng;
  21813. const byte in[] =
  21814. "Ed448PublicKeyUnitTest.................................\n";
  21815. word32 inlen = sizeof(in);
  21816. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21817. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21818. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21819. ExpectIntEQ(wc_InitRng(&rng), 0);
  21820. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21821. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21822. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21823. /* Test bad args. */
  21824. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21825. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21826. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21827. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21828. wc_ed448_free(&pubKey);
  21829. #endif
  21830. return EXPECT_RESULT();
  21831. } /* END wc_ed448_import_public */
  21832. /*
  21833. * Testing wc_ed448_import_private_key()
  21834. */
  21835. static int test_wc_ed448_import_private_key(void)
  21836. {
  21837. EXPECT_DECLS;
  21838. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21839. ed448_key key;
  21840. WC_RNG rng;
  21841. const byte privKey[] =
  21842. "Ed448PrivateKeyUnitTest................................\n";
  21843. const byte pubKey[] =
  21844. "Ed448PublicKeyUnitTest.................................\n";
  21845. word32 privKeySz = sizeof(privKey);
  21846. word32 pubKeySz = sizeof(pubKey);
  21847. #ifdef HAVE_ED448_KEY_EXPORT
  21848. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21849. word32 bothKeysSz = sizeof(bothKeys);
  21850. #endif
  21851. XMEMSET(&key, 0, sizeof(ed448_key));
  21852. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21853. ExpectIntEQ(wc_ed448_init(&key), 0);
  21854. ExpectIntEQ(wc_InitRng(&rng), 0);
  21855. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21856. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21857. pubKeySz, &key, 1), 0);
  21858. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21859. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21860. #ifdef HAVE_ED448_KEY_EXPORT
  21861. PRIVATE_KEY_UNLOCK();
  21862. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21863. PRIVATE_KEY_LOCK();
  21864. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21865. &key, 1), 0);
  21866. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21867. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21868. #endif
  21869. /* Test bad args. */
  21870. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21871. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21872. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  21873. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21874. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21875. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21876. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  21877. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21878. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21879. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21880. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  21881. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21882. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21883. wc_ed448_free(&key);
  21884. #endif
  21885. return EXPECT_RESULT();
  21886. } /* END test_wc_ed448_import_private_key */
  21887. /*
  21888. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  21889. */
  21890. static int test_wc_ed448_export(void)
  21891. {
  21892. EXPECT_DECLS;
  21893. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21894. ed448_key key;
  21895. WC_RNG rng;
  21896. byte priv[ED448_PRV_KEY_SIZE];
  21897. byte pub[ED448_PUB_KEY_SIZE];
  21898. word32 privSz = sizeof(priv);
  21899. word32 pubSz = sizeof(pub);
  21900. XMEMSET(&key, 0, sizeof(ed448_key));
  21901. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21902. ExpectIntEQ(wc_ed448_init(&key), 0);
  21903. ExpectIntEQ(wc_InitRng(&rng), 0);
  21904. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21905. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  21906. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  21907. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21908. /* Test bad args. */
  21909. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21910. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21911. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21912. PRIVATE_KEY_UNLOCK();
  21913. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  21914. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  21915. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21916. /* Test bad args. */
  21917. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  21918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21919. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  21920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21921. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21922. PRIVATE_KEY_LOCK();
  21923. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21924. wc_ed448_free(&key);
  21925. #endif
  21926. return EXPECT_RESULT();
  21927. } /* END test_wc_ed448_export */
  21928. /*
  21929. * Testing wc_ed448_size()
  21930. */
  21931. static int test_wc_ed448_size(void)
  21932. {
  21933. EXPECT_DECLS;
  21934. #if defined(HAVE_ED448)
  21935. ed448_key key;
  21936. WC_RNG rng;
  21937. XMEMSET(&key, 0, sizeof(ed448_key));
  21938. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21939. ExpectIntEQ(wc_ed448_init(&key), 0);
  21940. ExpectIntEQ(wc_InitRng(&rng), 0);
  21941. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21942. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  21943. /* Test bad args. */
  21944. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21945. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  21946. /* Test bad args. */
  21947. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21948. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  21949. /* Test bad args. */
  21950. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21951. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  21952. /* Test bad args. */
  21953. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21954. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21955. wc_ed448_free(&key);
  21956. #endif
  21957. return EXPECT_RESULT();
  21958. } /* END test_wc_ed448_size */
  21959. /*
  21960. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  21961. */
  21962. static int test_wc_ed448_exportKey(void)
  21963. {
  21964. EXPECT_DECLS;
  21965. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21966. ed448_key key;
  21967. WC_RNG rng;
  21968. byte priv[ED448_PRV_KEY_SIZE];
  21969. byte pub[ED448_PUB_KEY_SIZE];
  21970. byte privOnly[ED448_PRV_KEY_SIZE];
  21971. word32 privSz = sizeof(priv);
  21972. word32 pubSz = sizeof(pub);
  21973. word32 privOnlySz = sizeof(privOnly);
  21974. XMEMSET(&key, 0, sizeof(ed448_key));
  21975. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21976. ExpectIntEQ(wc_ed448_init(&key), 0);
  21977. ExpectIntEQ(wc_InitRng(&rng), 0);
  21978. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21979. PRIVATE_KEY_UNLOCK();
  21980. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  21981. /* Test bad args. */
  21982. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  21983. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21984. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21985. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21986. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21987. /* Test bad args. */
  21988. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  21989. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21990. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  21991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21992. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  21993. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21994. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  21995. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21996. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  21997. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21998. PRIVATE_KEY_LOCK();
  21999. /* Cross check output. */
  22000. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  22001. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22002. wc_ed448_free(&key);
  22003. #endif
  22004. return EXPECT_RESULT();
  22005. } /* END test_wc_ed448_exportKey */
  22006. /*
  22007. * Testing wc_Ed448PublicKeyToDer
  22008. */
  22009. static int test_wc_Ed448PublicKeyToDer(void)
  22010. {
  22011. EXPECT_DECLS;
  22012. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  22013. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  22014. ed448_key key;
  22015. byte derBuf[1024];
  22016. XMEMSET(&key, 0, sizeof(ed448_key));
  22017. /* Test bad args */
  22018. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22019. ExpectIntEQ(wc_ed448_init(&key), 0);
  22020. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  22021. wc_ed448_free(&key);
  22022. /* Test good args */
  22023. if (EXPECT_SUCCESS()) {
  22024. WC_RNG rng;
  22025. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22026. ExpectIntEQ(wc_ed448_init(&key), 0);
  22027. ExpectIntEQ(wc_InitRng(&rng), 0);
  22028. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22029. /* length only */
  22030. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  22031. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  22032. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  22033. (word32)sizeof(derBuf), 1), 0);
  22034. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22035. wc_ed448_free(&key);
  22036. }
  22037. #endif
  22038. return EXPECT_RESULT();
  22039. } /* END testing wc_Ed448PublicKeyToDer */
  22040. /*
  22041. * Testing wc_curve448_init and wc_curve448_free.
  22042. */
  22043. static int test_wc_curve448_init(void)
  22044. {
  22045. EXPECT_DECLS;
  22046. #if defined(HAVE_CURVE448)
  22047. curve448_key key;
  22048. /* Test bad args for wc_curve448_init */
  22049. ExpectIntEQ(wc_curve448_init(&key), 0);
  22050. /* Test bad args for wc_curve448_init */
  22051. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22052. /* Test good args for wc_curve_448_free */
  22053. wc_curve448_free(&key);
  22054. /* Test bad args for wc_curve448_free */
  22055. wc_curve448_free(NULL);
  22056. #endif
  22057. return EXPECT_RESULT();
  22058. } /* END test_wc_curve448_init and wc_curve_448_free*/
  22059. /*
  22060. * Testing wc_curve448_make_key
  22061. */
  22062. static int test_wc_curve448_make_key(void)
  22063. {
  22064. EXPECT_DECLS;
  22065. #if defined(HAVE_CURVE448)
  22066. curve448_key key;
  22067. WC_RNG rng;
  22068. int keysize = 0;
  22069. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22070. ExpectIntEQ(wc_curve448_init(&key), 0);
  22071. ExpectIntEQ(wc_InitRng(&rng), 0);
  22072. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22073. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22074. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  22075. /* test bad cases */
  22076. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22077. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22078. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22079. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22080. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22081. wc_curve448_free(&key);
  22082. #endif
  22083. return EXPECT_RESULT();
  22084. } /* END test_wc_curve448_make_key*/
  22085. /*
  22086. * Testing test_wc_curve448_shared_secret_ex
  22087. */
  22088. static int test_wc_curve448_shared_secret_ex(void)
  22089. {
  22090. EXPECT_DECLS;
  22091. #if defined(HAVE_CURVE448)
  22092. curve448_key private_key;
  22093. curve448_key public_key;
  22094. WC_RNG rng;
  22095. byte out[CURVE448_KEY_SIZE];
  22096. word32 outLen = sizeof(out);
  22097. int endian = EC448_BIG_ENDIAN;
  22098. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22099. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  22100. ExpectIntEQ(wc_InitRng(&rng), 0);
  22101. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  22102. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  22103. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  22104. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22105. &outLen, endian), 0);
  22106. /* test bad cases */
  22107. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  22108. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22109. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  22110. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22111. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  22112. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22113. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  22114. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22115. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22116. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22117. outLen = outLen - 2;
  22118. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22119. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22120. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22121. wc_curve448_free(&private_key);
  22122. wc_curve448_free(&public_key);
  22123. #endif
  22124. return EXPECT_RESULT();
  22125. } /* END test_wc_curve448_shared_secret_ex*/
  22126. /*
  22127. * Testing test_wc_curve448_export_public_ex
  22128. */
  22129. static int test_wc_curve448_export_public_ex(void)
  22130. {
  22131. EXPECT_DECLS;
  22132. #if defined(HAVE_CURVE448)
  22133. WC_RNG rng;
  22134. curve448_key key;
  22135. byte out[CURVE448_KEY_SIZE];
  22136. word32 outLen = sizeof(out);
  22137. int endian = EC448_BIG_ENDIAN;
  22138. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22139. ExpectIntEQ(wc_curve448_init(&key), 0);
  22140. ExpectIntEQ(wc_InitRng(&rng), 0);
  22141. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22142. ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
  22143. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  22144. /* test bad cases*/
  22145. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  22146. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22147. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  22148. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22149. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  22150. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22151. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  22152. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22153. outLen = outLen - 2;
  22154. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  22155. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22156. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22157. wc_curve448_free(&key);
  22158. #endif
  22159. return EXPECT_RESULT();
  22160. } /* END test_wc_curve448_export_public_ex*/
  22161. /*
  22162. * Testing test_wc_curve448_export_private_raw_ex
  22163. */
  22164. static int test_wc_curve448_export_private_raw_ex(void)
  22165. {
  22166. EXPECT_DECLS;
  22167. #if defined(HAVE_CURVE448)
  22168. curve448_key key;
  22169. byte out[CURVE448_KEY_SIZE];
  22170. word32 outLen = sizeof(out);
  22171. int endian = EC448_BIG_ENDIAN;
  22172. ExpectIntEQ(wc_curve448_init(&key), 0);
  22173. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22174. 0);
  22175. /* test bad cases*/
  22176. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  22177. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22178. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  22179. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22180. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  22181. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22182. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  22183. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22184. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  22185. EC448_LITTLE_ENDIAN), 0);
  22186. outLen = outLen - 2;
  22187. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22188. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22189. wc_curve448_free(&key);
  22190. #endif
  22191. return EXPECT_RESULT();
  22192. } /* END test_wc_curve448_export_private_raw_ex*/
  22193. /*
  22194. * Testing test_wc_curve448_import_private_raw_ex
  22195. */
  22196. static int test_wc_curve448_import_private_raw_ex(void)
  22197. {
  22198. EXPECT_DECLS;
  22199. #if defined(HAVE_CURVE448)
  22200. curve448_key key;
  22201. WC_RNG rng;
  22202. byte priv[CURVE448_KEY_SIZE];
  22203. byte pub[CURVE448_KEY_SIZE];
  22204. word32 privSz = sizeof(priv);
  22205. word32 pubSz = sizeof(pub);
  22206. int endian = EC448_BIG_ENDIAN;
  22207. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22208. ExpectIntEQ(wc_curve448_init(&key), 0);
  22209. ExpectIntEQ(wc_InitRng(&rng), 0);
  22210. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22211. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22212. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22213. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22214. &key, endian), 0);
  22215. /* test bad cases */
  22216. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  22217. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22218. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  22219. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22220. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  22221. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22222. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22223. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22224. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  22225. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22226. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  22227. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22228. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22229. &key, EC448_LITTLE_ENDIAN), 0);
  22230. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22231. wc_curve448_free(&key);
  22232. #endif
  22233. return EXPECT_RESULT();
  22234. } /* END test_wc_curve448_import_private_raw_ex*/
  22235. /*
  22236. * Testing test_curve448_export_key_raw
  22237. */
  22238. static int test_wc_curve448_export_key_raw(void)
  22239. {
  22240. EXPECT_DECLS;
  22241. #if defined(HAVE_CURVE448)
  22242. curve448_key key;
  22243. WC_RNG rng;
  22244. byte priv[CURVE448_KEY_SIZE];
  22245. byte pub[CURVE448_KEY_SIZE];
  22246. word32 privSz = sizeof(priv);
  22247. word32 pubSz = sizeof(pub);
  22248. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22249. ExpectIntEQ(wc_curve448_init(&key), 0);
  22250. ExpectIntEQ(wc_InitRng(&rng), 0);
  22251. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22252. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22253. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22254. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  22255. 0);
  22256. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22257. wc_curve448_free(&key);
  22258. #endif
  22259. return EXPECT_RESULT();
  22260. } /* END test_wc_curve448_import_private_raw_ex*/
  22261. /*
  22262. * Testing test_wc_curve448_import_private
  22263. */
  22264. static int test_wc_curve448_import_private(void)
  22265. {
  22266. EXPECT_DECLS;
  22267. #if defined(HAVE_CURVE448)
  22268. curve448_key key;
  22269. WC_RNG rng;
  22270. byte priv[CURVE448_KEY_SIZE];
  22271. word32 privSz = sizeof(priv);
  22272. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22273. ExpectIntEQ(wc_curve448_init(&key), 0);
  22274. ExpectIntEQ(wc_InitRng(&rng), 0);
  22275. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22276. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22277. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  22278. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22279. wc_curve448_free(&key);
  22280. #endif
  22281. return EXPECT_RESULT();
  22282. } /* END test_wc_curve448_import*/
  22283. /*
  22284. * Testing test_wc_curve448_size.
  22285. */
  22286. static int test_wc_curve448_size(void)
  22287. {
  22288. EXPECT_DECLS;
  22289. #if defined(HAVE_CURVE448)
  22290. curve448_key key;
  22291. ExpectIntEQ(wc_curve448_init(&key), 0);
  22292. /* Test good args for wc_curve448_size */
  22293. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22294. /* Test bad args for wc_curve448_size */
  22295. ExpectIntEQ(wc_curve448_size(NULL), 0);
  22296. wc_curve448_free(&key);
  22297. #endif
  22298. return EXPECT_RESULT();
  22299. } /* END test_wc_curve448_size*/
  22300. /*
  22301. * Testing wc_ecc_make_key.
  22302. */
  22303. static int test_wc_ecc_make_key(void)
  22304. {
  22305. EXPECT_DECLS;
  22306. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22307. ecc_key key;
  22308. WC_RNG rng;
  22309. int ret;
  22310. XMEMSET(&key, 0, sizeof(ecc_key));
  22311. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22312. ExpectIntEQ(wc_ecc_init(&key), 0);
  22313. ExpectIntEQ(wc_InitRng(&rng), 0);
  22314. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22315. #if defined(WOLFSSL_ASYNC_CRYPT)
  22316. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22317. #endif
  22318. ExpectIntEQ(ret, 0);
  22319. /* Pass in bad args. */
  22320. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22321. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22322. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22323. wc_ecc_free(&key);
  22324. #ifdef FP_ECC
  22325. wc_ecc_fp_free();
  22326. #endif
  22327. #endif
  22328. return EXPECT_RESULT();
  22329. } /* END test_wc_ecc_make_key */
  22330. /*
  22331. * Testing wc_ecc_init()
  22332. */
  22333. static int test_wc_ecc_init(void)
  22334. {
  22335. EXPECT_DECLS;
  22336. #ifdef HAVE_ECC
  22337. ecc_key key;
  22338. XMEMSET(&key, 0, sizeof(ecc_key));
  22339. ExpectIntEQ(wc_ecc_init(&key), 0);
  22340. /* Pass in bad args. */
  22341. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22342. wc_ecc_free(&key);
  22343. #endif
  22344. return EXPECT_RESULT();
  22345. } /* END test_wc_ecc_init */
  22346. /*
  22347. * Testing wc_ecc_check_key()
  22348. */
  22349. static int test_wc_ecc_check_key(void)
  22350. {
  22351. EXPECT_DECLS;
  22352. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22353. ecc_key key;
  22354. WC_RNG rng;
  22355. int ret;
  22356. XMEMSET(&rng, 0, sizeof(rng));
  22357. XMEMSET(&key, 0, sizeof(key));
  22358. ExpectIntEQ(wc_ecc_init(&key), 0);
  22359. ExpectIntEQ(wc_InitRng(&rng), 0);
  22360. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22361. #if defined(WOLFSSL_ASYNC_CRYPT)
  22362. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22363. #endif
  22364. ExpectIntEQ(ret, 0);
  22365. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  22366. /* Pass in bad args. */
  22367. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22368. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22369. wc_ecc_free(&key);
  22370. #ifdef FP_ECC
  22371. wc_ecc_fp_free();
  22372. #endif
  22373. #endif
  22374. return EXPECT_RESULT();
  22375. } /* END test_wc_ecc_check_key */
  22376. /*
  22377. * Testing wc_ecc_get_generator()
  22378. */
  22379. static int test_wc_ecc_get_generator(void)
  22380. {
  22381. EXPECT_DECLS;
  22382. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  22383. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  22384. ecc_point* pt = NULL;
  22385. ExpectNotNull(pt = wc_ecc_new_point());
  22386. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22387. MP_OKAY);
  22388. /* Test bad args. */
  22389. /* Returns Zero for bad arg. */
  22390. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  22391. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22392. MP_OKAY);
  22393. /* If we ever get to 1000 curves increase this number */
  22394. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  22395. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  22396. wc_ecc_del_point(pt);
  22397. #endif
  22398. return EXPECT_RESULT();
  22399. } /* END test_wc_ecc_get_generator */
  22400. /*
  22401. * Testing wc_ecc_size()
  22402. */
  22403. static int test_wc_ecc_size(void)
  22404. {
  22405. EXPECT_DECLS;
  22406. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22407. WC_RNG rng;
  22408. ecc_key key;
  22409. int ret;
  22410. XMEMSET(&key, 0, sizeof(ecc_key));
  22411. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22412. ExpectIntEQ(wc_ecc_init(&key), 0);
  22413. ExpectIntEQ(wc_InitRng(&rng), 0);
  22414. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22415. #if defined(WOLFSSL_ASYNC_CRYPT)
  22416. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22417. #endif
  22418. ExpectIntEQ(ret, 0);
  22419. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  22420. /* Test bad args. */
  22421. /* Returns Zero for bad arg. */
  22422. ExpectIntEQ(wc_ecc_size(NULL), 0);
  22423. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22424. wc_ecc_free(&key);
  22425. #endif
  22426. return EXPECT_RESULT();
  22427. } /* END test_wc_ecc_size */
  22428. static int test_wc_ecc_params(void)
  22429. {
  22430. EXPECT_DECLS;
  22431. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  22432. It was added after certifications */
  22433. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  22434. const ecc_set_type* ecc_set = NULL;
  22435. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  22436. /* Test for SECP256R1 curve */
  22437. int curve_id = ECC_SECP256R1;
  22438. int curve_idx;
  22439. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  22440. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  22441. ExpectIntEQ(ecc_set->id, curve_id);
  22442. #endif
  22443. /* Test case when SECP256R1 is not enabled */
  22444. /* Test that we get curve params for index 0 */
  22445. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  22446. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  22447. return EXPECT_RESULT();
  22448. }
  22449. /*
  22450. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22451. */
  22452. static int test_wc_ecc_signVerify_hash(void)
  22453. {
  22454. EXPECT_DECLS;
  22455. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22456. ecc_key key;
  22457. WC_RNG rng;
  22458. int ret;
  22459. #ifdef HAVE_ECC_VERIFY
  22460. int verify = 0;
  22461. #endif
  22462. word32 siglen = ECC_BUFSIZE;
  22463. byte sig[ECC_BUFSIZE];
  22464. byte adjustedSig[ECC_BUFSIZE+1];
  22465. byte digest[] = TEST_STRING;
  22466. word32 digestlen = (word32)TEST_STRING_SZ;
  22467. /* Init stack var */
  22468. XMEMSET(&key, 0, sizeof(ecc_key));
  22469. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22470. XMEMSET(sig, 0, siglen);
  22471. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22472. /* Init structs. */
  22473. ExpectIntEQ(wc_ecc_init(&key), 0);
  22474. ExpectIntEQ(wc_InitRng(&rng), 0);
  22475. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22476. #if defined(WOLFSSL_ASYNC_CRYPT)
  22477. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22478. #endif
  22479. ExpectIntEQ(ret, 0);
  22480. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22481. 0);
  22482. /* Check bad args. */
  22483. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22484. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22485. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22486. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22487. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22488. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22489. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22490. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22491. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22492. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22493. #ifdef HAVE_ECC_VERIFY
  22494. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22495. &key), 0);
  22496. ExpectIntEQ(verify, 1);
  22497. /* test check on length of signature passed in */
  22498. XMEMCPY(adjustedSig, sig, siglen);
  22499. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22500. #ifndef NO_STRICT_ECDSA_LEN
  22501. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22502. &verify, &key), 0);
  22503. #else
  22504. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22505. * is allowed */
  22506. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22507. &verify, &key), 0);
  22508. #endif
  22509. /* Test bad args. */
  22510. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22511. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22512. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22513. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22514. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22515. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22516. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22517. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22518. #endif /* HAVE_ECC_VERIFY */
  22519. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22520. wc_ecc_free(&key);
  22521. #ifdef FP_ECC
  22522. wc_ecc_fp_free();
  22523. #endif
  22524. #endif
  22525. return EXPECT_RESULT();
  22526. } /* END test_wc_ecc_sign_hash */
  22527. /*
  22528. * Testing wc_ecc_shared_secret()
  22529. */
  22530. static int test_wc_ecc_shared_secret(void)
  22531. {
  22532. EXPECT_DECLS;
  22533. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22534. ecc_key key;
  22535. ecc_key pubKey;
  22536. WC_RNG rng;
  22537. #if defined(NO_ECC256)
  22538. int ret;
  22539. #endif
  22540. byte out[KEY32];
  22541. int keySz = sizeof(out);
  22542. word32 outlen = (word32)sizeof(out);
  22543. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22544. const char* qx =
  22545. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22546. const char* qy =
  22547. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22548. const char* d =
  22549. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22550. const char* curveName = "SECP256R1";
  22551. const byte expected_shared_secret[] =
  22552. {
  22553. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22554. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22555. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22556. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22557. };
  22558. #endif
  22559. PRIVATE_KEY_UNLOCK();
  22560. /* Initialize variables. */
  22561. XMEMSET(&key, 0, sizeof(ecc_key));
  22562. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22563. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22564. XMEMSET(out, 0, keySz);
  22565. ExpectIntEQ(wc_ecc_init(&key), 0);
  22566. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22567. ExpectIntEQ(wc_InitRng(&rng), 0);
  22568. #if !defined(NO_ECC256)
  22569. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22570. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22571. #else
  22572. ret = wc_ecc_make_key(&rng, keySz, &key);
  22573. #if defined(WOLFSSL_ASYNC_CRYPT)
  22574. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22575. #endif
  22576. ExpectIntEQ(ret, 0);
  22577. ret = wc_ecc_make_key(&rng, keySz, &key);
  22578. #if defined(WOLFSSL_ASYNC_CRYPT)
  22579. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22580. #endif
  22581. ExpectIntEQ(ret, 0);
  22582. #endif
  22583. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22584. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22585. !defined(HAVE_SELFTEST)
  22586. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22587. #endif
  22588. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22589. #if !defined(NO_ECC256)
  22590. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22591. #endif
  22592. /* Test bad args. */
  22593. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22594. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22595. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22597. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22598. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22599. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22600. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22601. /* Invalid length */
  22602. outlen = 1;
  22603. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22604. WC_NO_ERR_TRACE(BUFFER_E));
  22605. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22606. wc_ecc_free(&pubKey);
  22607. wc_ecc_free(&key);
  22608. #ifdef FP_ECC
  22609. wc_ecc_fp_free();
  22610. #endif
  22611. PRIVATE_KEY_LOCK();
  22612. #endif
  22613. return EXPECT_RESULT();
  22614. } /* END tests_wc_ecc_shared_secret */
  22615. /*
  22616. * testint wc_ecc_export_x963()
  22617. */
  22618. static int test_wc_ecc_export_x963(void)
  22619. {
  22620. EXPECT_DECLS;
  22621. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22622. ecc_key key;
  22623. WC_RNG rng;
  22624. byte out[ECC_ASN963_MAX_BUF_SZ];
  22625. word32 outlen = sizeof(out);
  22626. int ret;
  22627. PRIVATE_KEY_UNLOCK();
  22628. /* Initialize variables. */
  22629. XMEMSET(&key, 0, sizeof(ecc_key));
  22630. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22631. XMEMSET(out, 0, outlen);
  22632. ExpectIntEQ(wc_ecc_init(&key), 0);
  22633. ExpectIntEQ(wc_InitRng(&rng), 0);
  22634. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22635. #if defined(WOLFSSL_ASYNC_CRYPT)
  22636. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22637. #endif
  22638. ExpectIntEQ(ret, 0);
  22639. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22640. /* Test bad args. */
  22641. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22642. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22643. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22644. key.idx = -4;
  22645. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22646. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22647. wc_ecc_free(&key);
  22648. #ifdef FP_ECC
  22649. wc_ecc_fp_free();
  22650. #endif
  22651. PRIVATE_KEY_LOCK();
  22652. #endif
  22653. return EXPECT_RESULT();
  22654. } /* END test_wc_ecc_export_x963 */
  22655. /*
  22656. * Testing wc_ecc_export_x963_ex()
  22657. * compile with --enable-compkey will use compression.
  22658. */
  22659. static int test_wc_ecc_export_x963_ex(void)
  22660. {
  22661. EXPECT_DECLS;
  22662. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22663. ecc_key key;
  22664. WC_RNG rng;
  22665. int ret;
  22666. byte out[ECC_ASN963_MAX_BUF_SZ];
  22667. word32 outlen = sizeof(out);
  22668. #ifdef HAVE_COMP_KEY
  22669. word32 badOutLen = 5;
  22670. #endif
  22671. /* Init stack variables. */
  22672. XMEMSET(&key, 0, sizeof(ecc_key));
  22673. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22674. XMEMSET(out, 0, outlen);
  22675. PRIVATE_KEY_UNLOCK();
  22676. ExpectIntEQ(wc_ecc_init(&key), 0);
  22677. ExpectIntEQ(wc_InitRng(&rng), 0);
  22678. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22679. #if defined(WOLFSSL_ASYNC_CRYPT)
  22680. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22681. #endif
  22682. ExpectIntEQ(ret, 0);
  22683. #ifdef HAVE_COMP_KEY
  22684. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22685. #else
  22686. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22687. #endif
  22688. /* Test bad args. */
  22689. #ifdef HAVE_COMP_KEY
  22690. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22691. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22692. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22693. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22694. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22695. #else
  22696. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22697. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22698. #endif
  22699. key.idx = -4;
  22700. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22701. #else
  22702. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22703. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22704. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22705. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22706. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22707. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22708. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22709. key.idx = -4;
  22710. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22711. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22712. #endif
  22713. PRIVATE_KEY_LOCK();
  22714. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22715. wc_ecc_free(&key);
  22716. #ifdef FP_ECC
  22717. wc_ecc_fp_free();
  22718. #endif
  22719. #endif
  22720. return EXPECT_RESULT();
  22721. } /* END test_wc_ecc_export_x963_ex */
  22722. /*
  22723. * testing wc_ecc_import_x963()
  22724. */
  22725. static int test_wc_ecc_import_x963(void)
  22726. {
  22727. EXPECT_DECLS;
  22728. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22729. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22730. ecc_key pubKey;
  22731. ecc_key key;
  22732. WC_RNG rng;
  22733. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22734. word32 x963Len = (word32)sizeof(x963);
  22735. int ret;
  22736. /* Init stack variables. */
  22737. XMEMSET(&key, 0, sizeof(ecc_key));
  22738. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22739. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22740. XMEMSET(x963, 0, x963Len);
  22741. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22742. ExpectIntEQ(wc_ecc_init(&key), 0);
  22743. ExpectIntEQ(wc_InitRng(&rng), 0);
  22744. #if FIPS_VERSION3_GE(6,0,0)
  22745. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22746. #else
  22747. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22748. #endif
  22749. #if defined(WOLFSSL_ASYNC_CRYPT)
  22750. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22751. #endif
  22752. ExpectIntEQ(ret, 0);
  22753. PRIVATE_KEY_UNLOCK();
  22754. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22755. PRIVATE_KEY_LOCK();
  22756. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22757. /* Test bad args. */
  22758. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22759. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22760. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22761. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22762. wc_ecc_free(&key);
  22763. wc_ecc_free(&pubKey);
  22764. #ifdef FP_ECC
  22765. wc_ecc_fp_free();
  22766. #endif
  22767. #endif
  22768. return EXPECT_RESULT();
  22769. } /* END wc_ecc_import_x963 */
  22770. /*
  22771. * testing wc_ecc_import_private_key()
  22772. */
  22773. static int test_wc_ecc_import_private_key(void)
  22774. {
  22775. EXPECT_DECLS;
  22776. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22777. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22778. ecc_key key;
  22779. ecc_key keyImp;
  22780. WC_RNG rng;
  22781. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22782. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22783. word32 privKeySz = (word32)sizeof(privKey);
  22784. word32 x963KeySz = (word32)sizeof(x963Key);
  22785. int ret;
  22786. /* Init stack variables. */
  22787. XMEMSET(&key, 0, sizeof(ecc_key));
  22788. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22789. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22790. XMEMSET(privKey, 0, privKeySz);
  22791. XMEMSET(x963Key, 0, x963KeySz);
  22792. PRIVATE_KEY_UNLOCK();
  22793. ExpectIntEQ(wc_ecc_init(&key), 0);
  22794. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22795. ExpectIntEQ(wc_InitRng(&rng), 0);
  22796. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22797. #if defined(WOLFSSL_ASYNC_CRYPT)
  22798. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22799. #endif
  22800. ExpectIntEQ(ret, 0);
  22801. PRIVATE_KEY_UNLOCK();
  22802. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22803. PRIVATE_KEY_LOCK();
  22804. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22805. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22806. x963KeySz, &keyImp), 0);
  22807. /* Pass in bad args. */
  22808. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22809. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22810. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22811. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22812. PRIVATE_KEY_LOCK();
  22813. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22814. wc_ecc_free(&keyImp);
  22815. wc_ecc_free(&key);
  22816. #ifdef FP_ECC
  22817. wc_ecc_fp_free();
  22818. #endif
  22819. #endif
  22820. return EXPECT_RESULT();
  22821. } /* END test_wc_ecc_import_private_key */
  22822. /*
  22823. * Testing wc_ecc_export_private_only()
  22824. */
  22825. static int test_wc_ecc_export_private_only(void)
  22826. {
  22827. EXPECT_DECLS;
  22828. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22829. ecc_key key;
  22830. WC_RNG rng;
  22831. byte out[ECC_PRIV_KEY_BUF];
  22832. word32 outlen = sizeof(out);
  22833. int ret;
  22834. /* Init stack variables. */
  22835. XMEMSET(&key, 0, sizeof(ecc_key));
  22836. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22837. XMEMSET(out, 0, outlen);
  22838. PRIVATE_KEY_UNLOCK();
  22839. ExpectIntEQ(wc_ecc_init(&key), 0);
  22840. ExpectIntEQ(wc_InitRng(&rng), 0);
  22841. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22842. #if defined(WOLFSSL_ASYNC_CRYPT)
  22843. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22844. #endif
  22845. ExpectIntEQ(ret, 0);
  22846. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22847. /* Pass in bad args. */
  22848. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22849. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22850. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22851. PRIVATE_KEY_LOCK();
  22852. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22853. wc_ecc_free(&key);
  22854. #ifdef FP_ECC
  22855. wc_ecc_fp_free();
  22856. #endif
  22857. #endif
  22858. return EXPECT_RESULT();
  22859. } /* END test_wc_ecc_export_private_only */
  22860. /*
  22861. * Testing wc_ecc_rs_to_sig()
  22862. */
  22863. static int test_wc_ecc_rs_to_sig(void)
  22864. {
  22865. EXPECT_DECLS;
  22866. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22867. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22868. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22869. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  22870. const char* zeroStr = "0";
  22871. byte sig[ECC_MAX_SIG_SIZE];
  22872. word32 siglen = (word32)sizeof(sig);
  22873. /* R and S max size is the order of curve. 2^192.*/
  22874. int keySz = KEY24;
  22875. byte r[KEY24];
  22876. byte s[KEY24];
  22877. word32 rlen = (word32)sizeof(r);
  22878. word32 slen = (word32)sizeof(s);
  22879. /* Init stack variables. */
  22880. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  22881. XMEMSET(r, 0, keySz);
  22882. XMEMSET(s, 0, keySz);
  22883. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  22884. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  22885. /* Test bad args. */
  22886. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22887. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22888. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22889. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22890. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22891. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22892. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  22893. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22894. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  22895. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22896. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  22897. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22898. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  22899. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22900. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  22901. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22902. #endif
  22903. return EXPECT_RESULT();
  22904. } /* END test_wc_ecc_rs_to_sig */
  22905. static int test_wc_ecc_import_raw(void)
  22906. {
  22907. EXPECT_DECLS;
  22908. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22909. ecc_key key;
  22910. const char* qx =
  22911. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22912. const char* qy =
  22913. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22914. const char* d =
  22915. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22916. const char* curveName = "SECP256R1";
  22917. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22918. const char* kNullStr = "";
  22919. int ret;
  22920. #endif
  22921. XMEMSET(&key, 0, sizeof(ecc_key));
  22922. ExpectIntEQ(wc_ecc_init(&key), 0);
  22923. /* Test good import */
  22924. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22925. /* Test bad args. */
  22926. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22927. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22928. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22929. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22930. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22931. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22932. wc_ecc_free(&key);
  22933. #endif
  22934. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  22935. curveName), 0);
  22936. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22937. #endif
  22938. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  22939. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22940. wc_ecc_free(&key);
  22941. #endif
  22942. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22943. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22944. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22945. #else
  22946. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22947. #endif
  22948. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22949. wc_ecc_free(&key);
  22950. #endif
  22951. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22952. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22953. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22954. #else
  22955. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22956. #endif
  22957. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22958. wc_ecc_free(&key);
  22959. #endif
  22960. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  22961. #endif
  22962. wc_ecc_free(&key);
  22963. #endif
  22964. return EXPECT_RESULT();
  22965. } /* END test_wc_ecc_import_raw */
  22966. static int test_wc_ecc_import_unsigned(void)
  22967. {
  22968. EXPECT_DECLS;
  22969. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  22970. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  22971. HAVE_FIPS_VERSION >= 2))
  22972. ecc_key key;
  22973. const byte qx[] = {
  22974. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  22975. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  22976. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  22977. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  22978. };
  22979. const byte qy[] = {
  22980. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  22981. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  22982. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  22983. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  22984. };
  22985. const byte d[] = {
  22986. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  22987. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  22988. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  22989. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  22990. };
  22991. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22992. const byte nullBytes[32] = {0};
  22993. int ret;
  22994. #endif
  22995. int curveId = ECC_SECP256R1;
  22996. XMEMSET(&key, 0, sizeof(ecc_key));
  22997. ExpectIntEQ(wc_ecc_init(&key), 0);
  22998. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22999. curveId), 0);
  23000. /* Test bad args. */
  23001. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  23002. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23003. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  23004. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23005. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  23006. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23007. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23008. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23009. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23010. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  23011. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  23012. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  23013. #endif
  23014. wc_ecc_free(&key);
  23015. #endif
  23016. return EXPECT_RESULT();
  23017. } /* END test_wc_ecc_import_unsigned */
  23018. /*
  23019. * Testing wc_ecc_sig_size()
  23020. */
  23021. static int test_wc_ecc_sig_size(void)
  23022. {
  23023. EXPECT_DECLS;
  23024. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23025. ecc_key key;
  23026. WC_RNG rng;
  23027. int keySz = KEY16;
  23028. int ret;
  23029. XMEMSET(&rng, 0, sizeof(rng));
  23030. XMEMSET(&key, 0, sizeof(key));
  23031. ExpectIntEQ(wc_ecc_init(&key), 0);
  23032. ExpectIntEQ(wc_InitRng(&rng), 0);
  23033. ret = wc_ecc_make_key(&rng, keySz, &key);
  23034. #if defined(WOLFSSL_ASYNC_CRYPT)
  23035. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23036. #endif
  23037. ExpectIntEQ(ret, 0);
  23038. ExpectIntLE(wc_ecc_sig_size(&key),
  23039. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  23040. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23041. wc_ecc_free(&key);
  23042. #endif
  23043. return EXPECT_RESULT();
  23044. } /* END test_wc_ecc_sig_size */
  23045. /*
  23046. * Testing wc_ecc_ctx_new()
  23047. */
  23048. static int test_wc_ecc_ctx_new(void)
  23049. {
  23050. EXPECT_DECLS;
  23051. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23052. WC_RNG rng;
  23053. ecEncCtx* cli = NULL;
  23054. ecEncCtx* srv = NULL;
  23055. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23056. ExpectIntEQ(wc_InitRng(&rng), 0);
  23057. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23058. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23059. wc_ecc_ctx_free(cli);
  23060. cli = NULL;
  23061. wc_ecc_ctx_free(srv);
  23062. /* Test bad args. */
  23063. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  23064. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  23065. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  23066. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23067. wc_ecc_ctx_free(cli);
  23068. #endif
  23069. return EXPECT_RESULT();
  23070. } /* END test_wc_ecc_ctx_new */
  23071. /*
  23072. * Tesing wc_ecc_reset()
  23073. */
  23074. static int test_wc_ecc_ctx_reset(void)
  23075. {
  23076. EXPECT_DECLS;
  23077. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23078. ecEncCtx* ctx = NULL;
  23079. WC_RNG rng;
  23080. XMEMSET(&rng, 0, sizeof(rng));
  23081. ExpectIntEQ(wc_InitRng(&rng), 0);
  23082. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23083. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  23084. /* Pass in bad args. */
  23085. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23086. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23087. wc_ecc_ctx_free(ctx);
  23088. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23089. #endif
  23090. return EXPECT_RESULT();
  23091. } /* END test_wc_ecc_ctx_reset */
  23092. /*
  23093. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  23094. */
  23095. static int test_wc_ecc_ctx_set_peer_salt(void)
  23096. {
  23097. EXPECT_DECLS;
  23098. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23099. WC_RNG rng;
  23100. ecEncCtx* cliCtx = NULL;
  23101. ecEncCtx* servCtx = NULL;
  23102. const byte* cliSalt = NULL;
  23103. const byte* servSalt = NULL;
  23104. XMEMSET(&rng, 0, sizeof(rng));
  23105. ExpectIntEQ(wc_InitRng(&rng), 0);
  23106. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23107. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23108. /* Test bad args. */
  23109. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  23110. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  23111. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  23112. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  23113. /* Test bad args. */
  23114. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23115. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23116. wc_ecc_ctx_free(cliCtx);
  23117. wc_ecc_ctx_free(servCtx);
  23118. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23119. #endif
  23120. return EXPECT_RESULT();
  23121. } /* END test_wc_ecc_ctx_set_peer_salt */
  23122. /*
  23123. * Testing wc_ecc_ctx_set_info()
  23124. */
  23125. static int test_wc_ecc_ctx_set_info(void)
  23126. {
  23127. EXPECT_DECLS;
  23128. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23129. ecEncCtx* ctx = NULL;
  23130. WC_RNG rng;
  23131. const char* optInfo = "Optional Test Info.";
  23132. int optInfoSz = (int)XSTRLEN(optInfo);
  23133. const char* badOptInfo = NULL;
  23134. XMEMSET(&rng, 0, sizeof(rng));
  23135. ExpectIntEQ(wc_InitRng(&rng), 0);
  23136. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23137. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  23138. /* Test bad args. */
  23139. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  23140. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23141. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  23142. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23143. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23144. wc_ecc_ctx_free(ctx);
  23145. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23146. #endif
  23147. return EXPECT_RESULT();
  23148. } /* END test_wc_ecc_ctx_set_info */
  23149. /*
  23150. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  23151. */
  23152. static int test_wc_ecc_encryptDecrypt(void)
  23153. {
  23154. EXPECT_DECLS;
  23155. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  23156. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  23157. ecc_key srvKey;
  23158. ecc_key cliKey;
  23159. ecc_key tmpKey;
  23160. WC_RNG rng;
  23161. int ret;
  23162. const char* msg = "EccBlock Size 16";
  23163. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  23164. #ifdef WOLFSSL_ECIES_OLD
  23165. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23166. #elif defined(WOLFSSL_ECIES_GEN_IV)
  23167. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  23168. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23169. #else
  23170. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  23171. WC_SHA256_DIGEST_SIZE];
  23172. #endif
  23173. word32 outSz = (word32)sizeof(out);
  23174. byte plain[sizeof("EccBlock Size 16")];
  23175. word32 plainSz = (word32)sizeof(plain);
  23176. int keySz = KEY20;
  23177. /* Init stack variables. */
  23178. XMEMSET(out, 0, outSz);
  23179. XMEMSET(plain, 0, plainSz);
  23180. XMEMSET(&rng, 0, sizeof(rng));
  23181. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  23182. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  23183. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  23184. ExpectIntEQ(wc_InitRng(&rng), 0);
  23185. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  23186. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  23187. #if defined(WOLFSSL_ASYNC_CRYPT)
  23188. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23189. #endif
  23190. ExpectIntEQ(ret, 0);
  23191. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  23192. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  23193. #if defined(WOLFSSL_ASYNC_CRYPT)
  23194. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23195. #endif
  23196. ExpectIntEQ(ret, 0);
  23197. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  23198. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23199. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23200. !defined(HAVE_SELFTEST)
  23201. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  23202. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  23203. #endif
  23204. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  23205. &outSz, NULL), 0);
  23206. /* Test bad args. */
  23207. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  23208. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23209. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  23210. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23211. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  23212. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23213. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  23214. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23215. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  23216. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23217. #ifdef WOLFSSL_ECIES_OLD
  23218. tmpKey.dp = cliKey.dp;
  23219. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  23220. #endif
  23221. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  23222. NULL), 0);
  23223. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  23224. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23225. #ifdef WOLFSSL_ECIES_OLD
  23226. /* NULL parameter allowed in new implementations - public key comes from
  23227. * the message. */
  23228. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  23229. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23230. #endif
  23231. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  23232. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23233. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  23234. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23235. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  23236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23237. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  23238. wc_ecc_free(&tmpKey);
  23239. wc_ecc_free(&srvKey);
  23240. wc_ecc_free(&cliKey);
  23241. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23242. #endif
  23243. return EXPECT_RESULT();
  23244. } /* END test_wc_ecc_encryptDecrypt */
  23245. /*
  23246. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  23247. */
  23248. static int test_wc_ecc_del_point(void)
  23249. {
  23250. EXPECT_DECLS;
  23251. #if defined(HAVE_ECC)
  23252. ecc_point* pt = NULL;
  23253. ExpectNotNull(pt = wc_ecc_new_point());
  23254. wc_ecc_del_point(pt);
  23255. #endif
  23256. return EXPECT_RESULT();
  23257. } /* END test_wc_ecc_del_point */
  23258. /*
  23259. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  23260. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  23261. * and wc_ecc_cmp_point()
  23262. */
  23263. static int test_wc_ecc_pointFns(void)
  23264. {
  23265. EXPECT_DECLS;
  23266. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  23267. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23268. !defined(WOLFSSL_ATECC608A)
  23269. ecc_key key;
  23270. WC_RNG rng;
  23271. int ret;
  23272. ecc_point* point = NULL;
  23273. ecc_point* cpypt = NULL;
  23274. int idx = 0;
  23275. int keySz = KEY32;
  23276. byte der[DER_SZ(KEY32)];
  23277. word32 derlenChk = 0;
  23278. word32 derSz = DER_SZ(KEY32);
  23279. /* Init stack variables. */
  23280. XMEMSET(der, 0, derSz);
  23281. XMEMSET(&key, 0, sizeof(ecc_key));
  23282. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23283. ExpectIntEQ(wc_InitRng(&rng), 0);
  23284. ExpectIntEQ(wc_ecc_init(&key), 0);
  23285. ret = wc_ecc_make_key(&rng, keySz, &key);
  23286. #if defined(WOLFSSL_ASYNC_CRYPT)
  23287. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23288. #endif
  23289. ExpectIntEQ(ret, 0);
  23290. ExpectNotNull(point = wc_ecc_new_point());
  23291. ExpectNotNull(cpypt = wc_ecc_new_point());
  23292. /* Export */
  23293. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  23294. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23295. /* Check length value. */
  23296. ExpectIntEQ(derSz, derlenChk);
  23297. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23298. &derSz), 0);
  23299. /* Test bad args. */
  23300. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  23301. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23302. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  23303. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23304. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23305. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23306. /* Import */
  23307. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  23308. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  23309. /* Test bad args. */
  23310. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  23311. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23312. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23313. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23314. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  23315. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23316. /* Copy */
  23317. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  23318. /* Test bad args. */
  23319. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23320. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23321. /* Compare point */
  23322. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  23323. /* Test bad args. */
  23324. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23325. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23326. /* At infinity if return == 1, otherwise return == 0. */
  23327. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  23328. /* Test bad args. */
  23329. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23330. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  23331. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  23332. #ifdef USE_ECC_B_PARAM
  23333. /* On curve if ret == 0 */
  23334. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  23335. /* Test bad args. */
  23336. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23337. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23338. #endif /* USE_ECC_B_PARAM */
  23339. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  23340. /* Free */
  23341. wc_ecc_del_point(point);
  23342. wc_ecc_del_point(cpypt);
  23343. wc_ecc_free(&key);
  23344. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23345. #endif
  23346. return EXPECT_RESULT();
  23347. } /* END test_wc_ecc_pointFns */
  23348. /*
  23349. * Testing wc_ecc_shared_secret_ssh()
  23350. */
  23351. static int test_wc_ecc_shared_secret_ssh(void)
  23352. {
  23353. EXPECT_DECLS;
  23354. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  23355. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23356. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  23357. !defined(WOLFSSL_CRYPTOCELL)
  23358. ecc_key key;
  23359. ecc_key key2;
  23360. WC_RNG rng;
  23361. int ret;
  23362. int keySz = KEY32;
  23363. #if FIPS_VERSION3_GE(6,0,0)
  23364. int key2Sz = KEY28;
  23365. #else
  23366. int key2Sz = KEY24;
  23367. #endif
  23368. byte secret[KEY32];
  23369. word32 secretLen = (word32)keySz;
  23370. /* Init stack variables. */
  23371. XMEMSET(&key, 0, sizeof(ecc_key));
  23372. XMEMSET(&key2, 0, sizeof(ecc_key));
  23373. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23374. XMEMSET(secret, 0, secretLen);
  23375. PRIVATE_KEY_UNLOCK();
  23376. /* Make keys */
  23377. ExpectIntEQ(wc_ecc_init(&key), 0);
  23378. ExpectIntEQ(wc_InitRng(&rng), 0);
  23379. ret = wc_ecc_make_key(&rng, keySz, &key);
  23380. #if defined(WOLFSSL_ASYNC_CRYPT)
  23381. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23382. #endif
  23383. ExpectIntEQ(ret, 0);
  23384. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23385. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23386. ExpectIntEQ(wc_InitRng(&rng), 0);
  23387. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  23388. #if defined(WOLFSSL_ASYNC_CRYPT)
  23389. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  23390. #endif
  23391. ExpectIntEQ(ret, 0);
  23392. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23393. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23394. !defined(HAVE_SELFTEST)
  23395. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  23396. #endif
  23397. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23398. &secretLen), 0);
  23399. /* Pass in bad args. */
  23400. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  23401. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23402. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  23403. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23404. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  23405. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23406. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  23407. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23408. key.type = ECC_PUBLICKEY;
  23409. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23410. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23411. PRIVATE_KEY_LOCK();
  23412. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23413. wc_ecc_free(&key);
  23414. wc_ecc_free(&key2);
  23415. #ifdef FP_ECC
  23416. wc_ecc_fp_free();
  23417. #endif
  23418. #endif
  23419. return EXPECT_RESULT();
  23420. } /* END test_wc_ecc_shared_secret_ssh */
  23421. /*
  23422. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  23423. */
  23424. static int test_wc_ecc_verify_hash_ex(void)
  23425. {
  23426. EXPECT_DECLS;
  23427. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  23428. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23429. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  23430. ecc_key key;
  23431. WC_RNG rng;
  23432. int ret;
  23433. mp_int r;
  23434. mp_int s;
  23435. mp_int z;
  23436. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  23437. unsigned char iHash[] = "Everyone gets Friday off.......";
  23438. unsigned char shortHash[] = TEST_STRING;
  23439. word32 hashlen = sizeof(hash);
  23440. word32 iHashLen = sizeof(iHash);
  23441. word32 shortHashLen = sizeof(shortHash);
  23442. int keySz = KEY32;
  23443. int verify_ok = 0;
  23444. XMEMSET(&key, 0, sizeof(ecc_key));
  23445. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23446. XMEMSET(&r, 0, sizeof(mp_int));
  23447. XMEMSET(&s, 0, sizeof(mp_int));
  23448. XMEMSET(&z, 0, sizeof(mp_int));
  23449. /* Initialize r, s and z. */
  23450. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23451. ExpectIntEQ(wc_ecc_init(&key), 0);
  23452. ExpectIntEQ(wc_InitRng(&rng), 0);
  23453. ret = wc_ecc_make_key(&rng, keySz, &key);
  23454. #if defined(WOLFSSL_ASYNC_CRYPT)
  23455. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23456. #endif
  23457. ExpectIntEQ(ret, 0);
  23458. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23459. /* verify_ok should be 1. */
  23460. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23461. 0);
  23462. ExpectIntEQ(verify_ok, 1);
  23463. /* verify_ok should be 0 */
  23464. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23465. &key), 0);
  23466. ExpectIntEQ(verify_ok, 0);
  23467. /* verify_ok should be 0. */
  23468. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23469. &verify_ok, &key), 0);
  23470. ExpectIntEQ(verify_ok, 0);
  23471. /* Test bad args. */
  23472. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23473. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23474. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23475. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23476. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23477. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23478. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23479. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23480. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23481. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23482. /* Test bad args. */
  23483. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23484. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23485. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23486. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23487. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23488. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23489. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23490. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23491. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23492. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23493. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23494. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23495. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23496. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23497. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23498. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23499. wc_ecc_free(&key);
  23500. mp_free(&r);
  23501. mp_free(&s);
  23502. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23503. #endif
  23504. return EXPECT_RESULT();
  23505. } /* END test_wc_ecc_verify_hash_ex */
  23506. /*
  23507. * Testing wc_ecc_mulmod()
  23508. */
  23509. static int test_wc_ecc_mulmod(void)
  23510. {
  23511. EXPECT_DECLS;
  23512. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23513. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23514. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23515. ecc_key key1;
  23516. ecc_key key2;
  23517. ecc_key key3;
  23518. WC_RNG rng;
  23519. int ret;
  23520. XMEMSET(&key1, 0, sizeof(ecc_key));
  23521. XMEMSET(&key2, 0, sizeof(ecc_key));
  23522. XMEMSET(&key3, 0, sizeof(ecc_key));
  23523. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23524. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23525. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23526. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23527. ExpectIntEQ(wc_InitRng(&rng), 0);
  23528. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23529. #if defined(WOLFSSL_ASYNC_CRYPT)
  23530. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23531. #endif
  23532. ExpectIntEQ(ret, 0);
  23533. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23534. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23535. key1.dp->Af, ECC_SECP256R1), 0);
  23536. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23537. key1.dp->prime, ECC_SECP256R1), 0);
  23538. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23539. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23540. 1), 0);
  23541. /* Test bad args. */
  23542. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23543. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23544. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23545. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23546. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23547. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23548. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23549. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23550. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23551. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23552. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23553. wc_ecc_free(&key1);
  23554. wc_ecc_free(&key2);
  23555. wc_ecc_free(&key3);
  23556. #ifdef FP_ECC
  23557. wc_ecc_fp_free();
  23558. #endif
  23559. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23560. return EXPECT_RESULT();
  23561. } /* END test_wc_ecc_mulmod */
  23562. /*
  23563. * Testing wc_ecc_is_valid_idx()
  23564. */
  23565. static int test_wc_ecc_is_valid_idx(void)
  23566. {
  23567. EXPECT_DECLS;
  23568. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23569. ecc_key key;
  23570. WC_RNG rng;
  23571. int ret;
  23572. int iVal = -2;
  23573. int iVal2 = 3000;
  23574. XMEMSET(&key, 0, sizeof(ecc_key));
  23575. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23576. ExpectIntEQ(wc_ecc_init(&key), 0);
  23577. ExpectIntEQ(wc_InitRng(&rng), 0);
  23578. ret = wc_ecc_make_key(&rng, 32, &key);
  23579. #if defined(WOLFSSL_ASYNC_CRYPT)
  23580. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23581. #endif
  23582. ExpectIntEQ(ret, 0);
  23583. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23584. /* Test bad args. */
  23585. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23586. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23587. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23588. wc_ecc_free(&key);
  23589. #ifdef FP_ECC
  23590. wc_ecc_fp_free();
  23591. #endif
  23592. #endif
  23593. return EXPECT_RESULT();
  23594. } /* END test_wc_ecc_is_valid_idx */
  23595. /*
  23596. * Testing wc_ecc_get_curve_id_from_oid()
  23597. */
  23598. static int test_wc_ecc_get_curve_id_from_oid(void)
  23599. {
  23600. EXPECT_DECLS;
  23601. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23602. !defined(HAVE_FIPS)
  23603. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23604. word32 len = sizeof(oid);
  23605. /* Bad Cases */
  23606. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23607. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23608. /* Good Case */
  23609. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23610. #endif
  23611. return EXPECT_RESULT();
  23612. } /* END test_wc_ecc_get_curve_id_from_oid */
  23613. /*
  23614. * Testing wc_ecc_sig_size_calc()
  23615. */
  23616. static int test_wc_ecc_sig_size_calc(void)
  23617. {
  23618. EXPECT_DECLS;
  23619. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23620. ecc_key key;
  23621. WC_RNG rng;
  23622. int sz = 0;
  23623. int ret;
  23624. XMEMSET(&key, 0, sizeof(ecc_key));
  23625. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23626. ExpectIntEQ(wc_ecc_init(&key), 0);
  23627. ExpectIntEQ(wc_InitRng(&rng), 0);
  23628. ret = wc_ecc_make_key(&rng, 16, &key);
  23629. #if defined(WOLFSSL_ASYNC_CRYPT)
  23630. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23631. #endif
  23632. #if FIPS_VERSION3_GE(6,0,0)
  23633. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23634. #else
  23635. ExpectIntEQ(ret, 0);
  23636. #endif
  23637. #if FIPS_VERSION3_LT(6,0,0)
  23638. sz = key.dp->size;
  23639. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23640. #else
  23641. (void) sz;
  23642. #endif
  23643. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23644. wc_ecc_free(&key);
  23645. #endif
  23646. return EXPECT_RESULT();
  23647. } /* END test_wc_ecc_sig_size_calc */
  23648. /*
  23649. * Testing wc_ecc_sm2_make_key()
  23650. */
  23651. static int test_wc_ecc_sm2_make_key(void)
  23652. {
  23653. int res = TEST_SKIPPED;
  23654. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23655. EXPECT_DECLS;
  23656. WC_RNG rng[1];
  23657. ecc_key key[1];
  23658. XMEMSET(rng, 0, sizeof(*rng));
  23659. XMEMSET(key, 0, sizeof(*key));
  23660. ExpectIntEQ(wc_InitRng(rng), 0);
  23661. ExpectIntEQ(wc_ecc_init(key), 0);
  23662. /* Test invalid parameters. */
  23663. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23664. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23665. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23667. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23668. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23669. /* Test valid parameters. */
  23670. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23671. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23672. wc_ecc_free(key);
  23673. wc_FreeRng(rng);
  23674. #ifdef FP_ECC
  23675. wc_ecc_fp_free();
  23676. #endif
  23677. res = EXPECT_RESULT();
  23678. #endif
  23679. return res;
  23680. }
  23681. /*
  23682. * Testing wc_ecc_sm2_shared_secret()
  23683. */
  23684. static int test_wc_ecc_sm2_shared_secret(void)
  23685. {
  23686. int res = TEST_SKIPPED;
  23687. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23688. EXPECT_DECLS;
  23689. WC_RNG rng[1];
  23690. ecc_key keyA[1];
  23691. ecc_key keyB[1];
  23692. byte outA[32];
  23693. byte outB[32];
  23694. word32 outALen = 32;
  23695. word32 outBLen = 32;
  23696. XMEMSET(rng, 0, sizeof(*rng));
  23697. XMEMSET(keyA, 0, sizeof(*keyA));
  23698. XMEMSET(keyB, 0, sizeof(*keyB));
  23699. ExpectIntEQ(wc_InitRng(rng), 0);
  23700. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23701. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23702. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23703. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23704. #ifdef ECC_TIMING_RESISTANT
  23705. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23706. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23707. #endif
  23708. /* Test invalid parameters. */
  23709. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23710. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23711. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23712. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23713. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23714. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23715. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23717. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23719. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23721. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23722. /* Test valid parameters. */
  23723. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23724. ExpectIntLE(outALen, 32);
  23725. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23726. ExpectIntLE(outBLen, 32);
  23727. ExpectIntEQ(outALen, outBLen);
  23728. ExpectBufEQ(outA, outB, outALen);
  23729. wc_ecc_free(keyB);
  23730. wc_ecc_free(keyA);
  23731. wc_FreeRng(rng);
  23732. #ifdef FP_ECC
  23733. wc_ecc_fp_free();
  23734. #endif
  23735. res = EXPECT_RESULT();
  23736. #endif
  23737. return res;
  23738. }
  23739. /*
  23740. * Testing wc_ecc_sm2_create_digest()
  23741. */
  23742. static int test_wc_ecc_sm2_create_digest(void)
  23743. {
  23744. int res = TEST_SKIPPED;
  23745. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23746. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23747. EXPECT_DECLS;
  23748. ecc_key key[1];
  23749. enum wc_HashType hashType;
  23750. unsigned char pub[] = {
  23751. 0x04,
  23752. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23753. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23754. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23755. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23756. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23757. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23758. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23759. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23760. };
  23761. unsigned char id[] = {
  23762. 0x01, 0x02, 0x03,
  23763. };
  23764. unsigned char msg[] = {
  23765. 0x01, 0x02, 0x03,
  23766. };
  23767. unsigned char hash[32];
  23768. #ifdef WOLFSSL_SM3
  23769. unsigned char expHash[32] = {
  23770. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23771. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23772. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23773. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23774. };
  23775. #else
  23776. unsigned char expHash[32] = {
  23777. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23778. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23779. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23780. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23781. };
  23782. #endif
  23783. #ifdef WOLFSSL_SM3
  23784. hashType = WC_HASH_TYPE_SM3;
  23785. #else
  23786. hashType = WC_HASH_TYPE_SHA256;
  23787. #endif
  23788. XMEMSET(key, 0, sizeof(*key));
  23789. ExpectIntEQ(wc_ecc_init(key), 0);
  23790. /* Test with no curve set. */
  23791. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23792. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23793. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23794. /* Test invalid parameters. */
  23795. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23796. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23797. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23798. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23799. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23800. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23801. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23802. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23803. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23804. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23805. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23806. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23807. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23808. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23809. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23810. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23811. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23812. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23813. /* Bad hash type. */
  23814. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23815. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23816. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23817. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23818. /* Bad hash size. */
  23819. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23820. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23821. /* Test valid parameters. */
  23822. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23823. hashType, hash, sizeof(hash), key), 0);
  23824. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23825. wc_ecc_free(key);
  23826. res = EXPECT_RESULT();
  23827. #endif
  23828. return res;
  23829. }
  23830. /*
  23831. * Testing wc_ecc_sm2_verify_hash_ex()
  23832. */
  23833. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23834. {
  23835. int res = TEST_SKIPPED;
  23836. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23837. defined(WOLFSSL_PUBLIC_MP)
  23838. EXPECT_DECLS;
  23839. ecc_key key[1];
  23840. mp_int r[1];
  23841. mp_int s[1];
  23842. int verified;
  23843. unsigned char pub[] = {
  23844. 0x04,
  23845. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23846. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23847. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23848. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23849. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23850. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23851. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23852. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23853. };
  23854. unsigned char hash[] = {
  23855. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23856. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23857. 0x50, 0x69, 0x5B, 0x20
  23858. };
  23859. unsigned char rData[] = {
  23860. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23861. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23862. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23863. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23864. };
  23865. unsigned char sData[] = {
  23866. 0x1D,
  23867. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23868. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23869. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23870. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23871. };
  23872. unsigned char rBadData[] = {
  23873. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23874. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23875. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23876. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  23877. };
  23878. XMEMSET(key, 0, sizeof(*key));
  23879. XMEMSET(r, 0, sizeof(*r));
  23880. XMEMSET(s, 0, sizeof(*s));
  23881. ExpectIntEQ(mp_init(r), 0);
  23882. ExpectIntEQ(mp_init(s), 0);
  23883. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  23884. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  23885. ExpectIntEQ(wc_ecc_init(key), 0);
  23886. /* Test with no curve set. */
  23887. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23888. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23889. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23890. /* Test invalid parameters. */
  23891. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23892. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23893. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  23894. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23895. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  23896. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23897. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  23898. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23899. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23900. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23901. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23902. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23903. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  23904. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23905. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  23906. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23907. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  23908. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23909. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23910. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23911. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23912. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23913. /* Make key not on the SM2 curve. */
  23914. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23915. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23916. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23917. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23918. /* Test valid parameters. */
  23919. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23920. &verified, key), 0);
  23921. ExpectIntEQ(verified, 1);
  23922. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  23923. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23924. &verified, key), 0);
  23925. ExpectIntEQ(verified, 0);
  23926. mp_free(s);
  23927. mp_free(r);
  23928. wc_ecc_free(key);
  23929. #ifdef FP_ECC
  23930. wc_ecc_fp_free();
  23931. #endif
  23932. res = EXPECT_RESULT();
  23933. #endif
  23934. return res;
  23935. }
  23936. /*
  23937. * Testing wc_ecc_sm2_verify_hash()
  23938. */
  23939. static int test_wc_ecc_sm2_verify_hash(void)
  23940. {
  23941. int res = TEST_SKIPPED;
  23942. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  23943. EXPECT_DECLS;
  23944. ecc_key key[1];
  23945. int verified;
  23946. unsigned char pub[] = {
  23947. 0x04,
  23948. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23949. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23950. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23951. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23952. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23953. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23954. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23955. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23956. };
  23957. unsigned char hash[] = {
  23958. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23959. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23960. 0x50, 0x69, 0x5B, 0x20
  23961. };
  23962. unsigned char sig[] = {
  23963. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23964. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23965. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23966. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23967. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23968. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23969. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23970. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23971. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23972. };
  23973. unsigned char sigBad[] = {
  23974. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23975. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23976. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23977. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23978. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23979. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23980. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23981. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23982. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  23983. };
  23984. XMEMSET(key, 0, sizeof(*key));
  23985. ExpectIntEQ(wc_ecc_init(key), 0);
  23986. /* Test with no curve set. */
  23987. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23988. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23989. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23990. /* Test invalid parameters. */
  23991. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23992. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23993. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23994. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23995. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23996. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23997. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23998. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23999. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24000. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24001. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  24002. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24003. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  24004. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24005. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24006. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24007. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24008. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24009. /* Make key not on the SM2 curve. */
  24010. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24011. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24012. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24013. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24014. /* Test valid parameters. */
  24015. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24016. &verified, key), 0);
  24017. ExpectIntEQ(verified, 1);
  24018. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  24019. sizeof(hash), &verified, key), 0);
  24020. ExpectIntEQ(verified, 0);
  24021. wc_ecc_free(key);
  24022. #ifdef FP_ECC
  24023. wc_ecc_fp_free();
  24024. #endif
  24025. res = EXPECT_RESULT();
  24026. #endif
  24027. return res;
  24028. }
  24029. /*
  24030. * Testing wc_ecc_sm2_verify_hash_ex()
  24031. */
  24032. static int test_wc_ecc_sm2_sign_hash_ex(void)
  24033. {
  24034. int res = TEST_SKIPPED;
  24035. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  24036. defined(WOLFSSL_PUBLIC_MP)
  24037. EXPECT_DECLS;
  24038. WC_RNG rng[1];
  24039. ecc_key key[1];
  24040. mp_int r[1];
  24041. mp_int s[1];
  24042. unsigned char hash[32];
  24043. #ifdef HAVE_ECC_VERIFY
  24044. int verified;
  24045. #endif
  24046. XMEMSET(rng, 0, sizeof(*rng));
  24047. XMEMSET(key, 0, sizeof(*key));
  24048. XMEMSET(r, 0, sizeof(*r));
  24049. XMEMSET(s, 0, sizeof(*s));
  24050. ExpectIntEQ(wc_InitRng(rng), 0);
  24051. ExpectIntEQ(mp_init(r), 0);
  24052. ExpectIntEQ(mp_init(s), 0);
  24053. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24054. ExpectIntEQ(wc_ecc_init(key), 0);
  24055. /* Test with no curve set. */
  24056. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24057. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24058. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24059. /* Test invalid parameters. */
  24060. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24061. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24062. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  24063. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24064. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  24065. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24066. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  24067. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24068. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  24069. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24070. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24071. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24072. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  24073. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24074. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  24075. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24076. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  24077. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24078. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  24079. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24080. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  24081. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24082. /* Make key not on the SM2 curve. */
  24083. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24084. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24085. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24086. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24087. #ifdef WOLFSSL_SP_MATH_ALL
  24088. {
  24089. mp_int smallR[1];
  24090. sp_init_size(smallR, 1);
  24091. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  24092. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  24093. smallR, s), 0);
  24094. }
  24095. #endif
  24096. /* Test valid parameters. */
  24097. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24098. 0);
  24099. #ifdef HAVE_ECC_VERIFY
  24100. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  24101. key), 0);
  24102. ExpectIntEQ(verified, 1);
  24103. #endif
  24104. mp_free(s);
  24105. mp_free(r);
  24106. wc_ecc_free(key);
  24107. wc_FreeRng(rng);
  24108. #ifdef FP_ECC
  24109. wc_ecc_fp_free();
  24110. #endif
  24111. res = EXPECT_RESULT();
  24112. #endif
  24113. return res;
  24114. }
  24115. /*
  24116. * Testing wc_ecc_sm2_verify_hash()
  24117. */
  24118. static int test_wc_ecc_sm2_sign_hash(void)
  24119. {
  24120. int res = TEST_SKIPPED;
  24121. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  24122. EXPECT_DECLS;
  24123. WC_RNG rng[1];
  24124. ecc_key key[1];
  24125. unsigned char hash[32];
  24126. unsigned char sig[72];
  24127. word32 sigSz = sizeof(sig);
  24128. #ifdef HAVE_ECC_VERIFY
  24129. int verified;
  24130. #endif
  24131. XMEMSET(rng, 0, sizeof(*rng));
  24132. XMEMSET(key, 0, sizeof(*key));
  24133. ExpectIntEQ(wc_InitRng(rng), 0);
  24134. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24135. ExpectIntEQ(wc_ecc_init(key), 0);
  24136. /* Test with no curve set. */
  24137. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24138. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24139. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24140. /* Test invalid parameters. */
  24141. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24142. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24143. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  24144. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24145. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  24146. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24147. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  24148. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24149. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  24150. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24151. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24152. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24153. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  24154. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24155. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  24156. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24157. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  24158. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24159. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  24160. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24161. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  24162. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24163. /* Make key not on the SM2 curve. */
  24164. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24165. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24166. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24167. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24168. /* Test valid parameters. */
  24169. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24170. 0);
  24171. #ifdef HAVE_ECC_VERIFY
  24172. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  24173. &verified, key), 0);
  24174. ExpectIntEQ(verified, 1);
  24175. #endif
  24176. wc_ecc_free(key);
  24177. wc_FreeRng(rng);
  24178. #ifdef FP_ECC
  24179. wc_ecc_fp_free();
  24180. #endif
  24181. res = EXPECT_RESULT();
  24182. #endif
  24183. return res;
  24184. }
  24185. /*
  24186. * Testing ToTraditional
  24187. */
  24188. static int test_ToTraditional(void)
  24189. {
  24190. EXPECT_DECLS;
  24191. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  24192. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  24193. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  24194. XFILE f = XBADFILE;
  24195. byte input[TWOK_BUF];
  24196. word32 sz = 0;
  24197. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  24198. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  24199. if (f != XBADFILE)
  24200. XFCLOSE(f);
  24201. /* Good case */
  24202. ExpectIntGT(ToTraditional(input, sz), 0);
  24203. /* Bad cases */
  24204. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24205. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24206. #ifdef WOLFSSL_ASN_TEMPLATE
  24207. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24208. #else
  24209. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  24210. #endif
  24211. #endif
  24212. return EXPECT_RESULT();
  24213. } /* End test_ToTraditional*/
  24214. /*
  24215. * Testing wc_EccPrivateKeyToDer
  24216. */
  24217. static int test_wc_EccPrivateKeyToDer(void)
  24218. {
  24219. EXPECT_DECLS;
  24220. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  24221. byte output[ONEK_BUF];
  24222. ecc_key eccKey;
  24223. WC_RNG rng;
  24224. word32 inLen;
  24225. word32 outLen = 0;
  24226. int ret;
  24227. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  24228. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24229. PRIVATE_KEY_UNLOCK();
  24230. ExpectIntEQ(wc_InitRng(&rng), 0);
  24231. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  24232. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  24233. #if defined(WOLFSSL_ASYNC_CRYPT)
  24234. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  24235. #endif
  24236. ExpectIntEQ(ret, 0);
  24237. inLen = (word32)sizeof(output);
  24238. /* Bad Cases */
  24239. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24240. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24241. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, NULL, inLen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  24242. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24243. /* Good Case */
  24244. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  24245. wc_ecc_free(&eccKey);
  24246. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24247. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  24248. {
  24249. /* test importing private only into a PKEY struct */
  24250. EC_KEY* ec = NULL;
  24251. EVP_PKEY* pkey = NULL;
  24252. const unsigned char* der;
  24253. der = output;
  24254. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  24255. der = output;
  24256. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  24257. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  24258. if (EXPECT_FAIL()) {
  24259. EC_KEY_free(ec);
  24260. }
  24261. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  24262. }
  24263. #endif
  24264. PRIVATE_KEY_LOCK();
  24265. #endif
  24266. return EXPECT_RESULT();
  24267. } /* End test_wc_EccPrivateKeyToDer*/
  24268. /*
  24269. * Testing wc_DhPublicKeyDecode
  24270. */
  24271. static int test_wc_DhPublicKeyDecode(void)
  24272. {
  24273. EXPECT_DECLS;
  24274. #ifndef NO_DH
  24275. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  24276. DhKey key;
  24277. word32 inOutIdx;
  24278. XMEMSET(&key, 0, sizeof(DhKey));
  24279. ExpectIntEQ(wc_InitDhKey(&key), 0);
  24280. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24281. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24282. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24283. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24284. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24285. inOutIdx = 0;
  24286. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  24287. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24288. inOutIdx = 0;
  24289. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  24290. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24291. inOutIdx = 0;
  24292. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  24293. sizeof_dh_pub_key_der_2048), 0);
  24294. ExpectIntNE(key.p.used, 0);
  24295. ExpectIntNE(key.g.used, 0);
  24296. ExpectIntEQ(key.q.used, 0);
  24297. ExpectIntNE(key.pub.used, 0);
  24298. ExpectIntEQ(key.priv.used, 0);
  24299. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  24300. #endif
  24301. #endif /* !NO_DH */
  24302. return EXPECT_RESULT();
  24303. }
  24304. /*
  24305. * Testing wc_Ed25519KeyToDer
  24306. */
  24307. static int test_wc_Ed25519KeyToDer(void)
  24308. {
  24309. EXPECT_DECLS;
  24310. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24311. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24312. byte output[ONEK_BUF];
  24313. ed25519_key ed25519Key;
  24314. WC_RNG rng;
  24315. word32 inLen;
  24316. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  24317. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24318. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  24319. ExpectIntEQ(wc_InitRng(&rng), 0);
  24320. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  24321. inLen = (word32)sizeof(output);
  24322. /* Bad Cases */
  24323. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24324. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24325. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24326. /* Good Cases */
  24327. /* length only */
  24328. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  24329. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  24330. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  24331. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24332. wc_ed25519_free(&ed25519Key);
  24333. #endif
  24334. return EXPECT_RESULT();
  24335. } /* End test_wc_Ed25519KeyToDer*/
  24336. /*
  24337. * Testing wc_Ed25519PrivateKeyToDer
  24338. */
  24339. static int test_wc_Ed25519PrivateKeyToDer(void)
  24340. {
  24341. EXPECT_DECLS;
  24342. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24343. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24344. byte output[ONEK_BUF];
  24345. ed25519_key ed25519PrivKey;
  24346. WC_RNG rng;
  24347. word32 inLen;
  24348. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  24349. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24350. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  24351. ExpectIntEQ(wc_InitRng(&rng), 0);
  24352. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  24353. 0);
  24354. inLen = (word32)sizeof(output);
  24355. /* Bad Cases */
  24356. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24357. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24358. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  24359. WC_NO_ERR_TRACE(BUFFER_E));
  24360. /* Good Cases */
  24361. /* length only */
  24362. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  24363. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  24364. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24365. wc_ed25519_free(&ed25519PrivKey);
  24366. #endif
  24367. return EXPECT_RESULT();
  24368. } /* End test_wc_Ed25519PrivateKeyToDer*/
  24369. /*
  24370. * Testing wc_Ed448KeyToDer
  24371. */
  24372. static int test_wc_Ed448KeyToDer(void)
  24373. {
  24374. EXPECT_DECLS;
  24375. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24376. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24377. byte output[ONEK_BUF];
  24378. ed448_key ed448Key;
  24379. WC_RNG rng;
  24380. word32 inLen;
  24381. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  24382. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24383. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  24384. ExpectIntEQ(wc_InitRng(&rng), 0);
  24385. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  24386. inLen = (word32)sizeof(output);
  24387. /* Bad Cases */
  24388. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24389. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24390. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24391. /* Good Cases */
  24392. /* length only */
  24393. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  24394. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  24395. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24396. wc_ed448_free(&ed448Key);
  24397. #endif
  24398. return EXPECT_RESULT();
  24399. } /* End test_wc_Ed448KeyToDer*/
  24400. /*
  24401. * Testing wc_Ed448PrivateKeyToDer
  24402. */
  24403. static int test_wc_Ed448PrivateKeyToDer(void)
  24404. {
  24405. EXPECT_DECLS;
  24406. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24407. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24408. byte output[ONEK_BUF];
  24409. ed448_key ed448PrivKey;
  24410. WC_RNG rng;
  24411. word32 inLen;
  24412. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  24413. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24414. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  24415. ExpectIntEQ(wc_InitRng(&rng), 0);
  24416. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  24417. 0);
  24418. inLen = (word32)sizeof(output);
  24419. /* Bad Cases */
  24420. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24421. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24422. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  24423. WC_NO_ERR_TRACE(BUFFER_E));
  24424. /* Good cases */
  24425. /* length only */
  24426. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  24427. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  24428. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24429. wc_ed448_free(&ed448PrivKey);
  24430. #endif
  24431. return EXPECT_RESULT();
  24432. } /* End test_wc_Ed448PrivateKeyToDer*/
  24433. /*
  24434. * Testing wc_Curve448PrivateKeyToDer
  24435. */
  24436. static int test_wc_Curve448PrivateKeyToDer(void)
  24437. {
  24438. EXPECT_DECLS;
  24439. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  24440. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24441. byte output[ONEK_BUF];
  24442. curve448_key curve448PrivKey;
  24443. WC_RNG rng;
  24444. word32 inLen;
  24445. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  24446. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24447. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  24448. ExpectIntEQ(wc_InitRng(&rng), 0);
  24449. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24450. 0);
  24451. inLen = (word32)sizeof(output);
  24452. /* Bad Cases */
  24453. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24454. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24455. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24456. WC_NO_ERR_TRACE(BUFFER_E));
  24457. /* Good cases */
  24458. /* length only */
  24459. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24460. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24461. /* Bad Cases */
  24462. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24463. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24464. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24465. WC_NO_ERR_TRACE(BUFFER_E));
  24466. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24467. WC_NO_ERR_TRACE(BUFFER_E));
  24468. /* Good cases */
  24469. /* length only */
  24470. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24471. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24472. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24473. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24474. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24475. wc_curve448_free(&curve448PrivKey);
  24476. #endif
  24477. return EXPECT_RESULT();
  24478. } /* End wc_Curve448PrivateKeyToDer*/
  24479. static int test_wc_kyber_make_key_kats(void)
  24480. {
  24481. EXPECT_DECLS;
  24482. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24483. !defined(WOLFSSL_KYBER_ORIGINAL)
  24484. KyberKey* key;
  24485. #ifndef WOLFSSL_NO_KYBER512
  24486. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24487. /* d */
  24488. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24489. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24490. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24491. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24492. /* z */
  24493. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24494. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24495. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24496. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24497. };
  24498. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24499. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24500. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24501. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24502. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24503. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24504. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24505. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24506. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24507. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24508. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24509. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24510. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24511. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24512. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24513. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24514. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24515. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24516. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24517. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24518. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24519. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24520. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24521. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24522. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24523. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24524. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24525. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24526. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24527. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24528. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24529. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24530. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24531. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24532. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24533. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24534. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24535. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24536. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24537. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24538. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24539. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24540. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24541. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24542. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24543. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24544. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24545. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24546. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24547. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24548. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24549. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24550. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24551. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24552. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24553. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24554. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24555. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24556. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24557. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24558. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24559. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24560. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24561. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24562. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24563. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24564. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24565. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24566. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24567. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24568. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24569. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24570. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24571. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24572. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24573. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24574. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24575. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24576. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24577. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24578. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24579. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24580. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24581. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24582. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24583. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24584. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24585. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24586. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24587. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24588. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24589. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24590. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24591. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24592. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24593. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24594. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24595. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24596. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24597. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24598. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24599. };
  24600. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24601. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24602. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24603. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24604. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24605. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24606. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24607. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24608. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24609. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24610. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24611. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24612. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24613. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24614. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24615. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24616. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24617. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24618. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24619. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24620. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24621. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24622. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24623. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24624. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24625. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24626. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24627. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24628. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24629. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24630. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24631. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24632. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24633. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24634. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24635. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24636. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24637. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24638. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24639. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24640. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24641. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24642. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24643. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24644. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24645. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24646. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24647. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24648. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24649. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24650. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24651. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24652. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24653. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24654. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24655. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24656. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24657. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24658. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24659. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24660. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24661. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24662. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24663. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24664. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24665. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24666. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24667. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24668. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24669. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24670. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24671. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24672. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24673. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24674. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24675. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24676. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24677. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24678. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24679. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24680. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24681. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24682. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24683. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24684. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24685. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24686. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24687. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24688. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24689. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24690. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24691. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24692. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24693. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24694. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24695. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24696. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24697. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24698. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24699. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24700. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24701. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24702. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24703. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24704. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24705. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24706. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24707. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24708. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24709. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24710. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24711. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24712. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24713. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24714. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24715. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24716. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24717. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24718. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24719. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24720. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24721. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24722. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24723. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24724. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24725. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24726. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24727. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24728. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24729. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24730. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24731. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24732. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24733. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24734. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24735. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24736. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24737. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24738. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24739. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24740. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24741. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24742. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24743. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24744. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24745. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24746. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24747. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24748. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24749. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24750. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24751. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24752. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24753. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24754. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24755. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24756. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24757. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24758. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24759. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24760. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24761. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24762. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24763. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24764. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24765. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24766. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24767. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24768. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24769. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24770. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24771. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24772. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24773. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24774. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24775. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24776. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24777. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24778. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24779. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24780. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24781. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24782. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24783. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24784. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24785. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24786. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24787. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24788. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24789. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24790. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24791. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24792. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24793. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24794. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24795. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24796. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24797. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24798. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24799. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24800. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24801. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24802. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24803. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24804. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24805. };
  24806. #endif
  24807. #ifndef WOLFSSL_NO_KYBER768
  24808. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24809. /* d */
  24810. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24811. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24812. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24813. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24814. /* z */
  24815. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24816. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24817. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24818. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24819. };
  24820. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24821. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24822. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24823. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24824. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24825. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24826. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24827. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24828. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24829. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24830. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24831. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24832. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24833. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24834. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24835. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24836. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24837. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24838. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24839. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24840. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24841. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24842. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24843. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24844. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24845. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24846. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24847. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24848. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24849. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24850. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24851. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24852. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24853. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24854. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24855. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24856. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24857. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24858. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24859. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24860. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24861. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24862. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24863. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24864. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24865. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24866. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24867. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24868. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24869. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24870. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24871. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24872. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24873. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24874. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24875. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24876. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24877. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24878. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24879. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24880. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24881. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24882. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24883. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24884. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24885. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24886. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24887. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24888. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24889. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24890. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24891. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24892. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24893. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24894. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24895. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24896. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24897. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24898. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24899. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24900. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24901. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24902. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24903. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24904. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24905. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24906. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24907. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24908. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24909. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24910. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24911. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24912. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24913. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24914. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24915. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24916. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24917. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24918. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24919. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24920. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24921. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24922. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24923. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24924. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24925. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24926. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24927. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24928. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24929. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24930. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24931. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24932. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24933. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24934. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24935. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24936. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24937. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24938. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24939. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24940. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24941. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24942. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24943. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24944. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24945. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24946. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24947. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24948. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24949. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24950. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24951. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24952. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24953. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24954. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24955. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24956. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24957. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24958. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24959. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24960. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24961. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24962. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24963. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24964. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24965. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24966. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24967. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24968. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  24969. };
  24970. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  24971. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  24972. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  24973. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  24974. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  24975. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  24976. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  24977. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  24978. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  24979. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  24980. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  24981. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  24982. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  24983. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  24984. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  24985. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  24986. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  24987. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  24988. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  24989. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  24990. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  24991. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  24992. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  24993. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  24994. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  24995. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  24996. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  24997. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  24998. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  24999. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  25000. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  25001. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  25002. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  25003. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  25004. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  25005. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  25006. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  25007. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  25008. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  25009. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  25010. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  25011. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  25012. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  25013. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  25014. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  25015. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  25016. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  25017. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  25018. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  25019. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  25020. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  25021. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  25022. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  25023. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  25024. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  25025. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  25026. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  25027. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  25028. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  25029. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  25030. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  25031. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  25032. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  25033. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  25034. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  25035. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  25036. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  25037. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  25038. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  25039. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  25040. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  25041. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  25042. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  25043. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  25044. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  25045. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  25046. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  25047. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  25048. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  25049. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  25050. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  25051. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  25052. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  25053. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  25054. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  25055. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  25056. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  25057. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  25058. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  25059. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  25060. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  25061. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  25062. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  25063. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  25064. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  25065. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  25066. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  25067. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  25068. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  25069. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  25070. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  25071. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  25072. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  25073. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  25074. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  25075. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  25076. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  25077. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  25078. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  25079. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  25080. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  25081. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  25082. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  25083. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  25084. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  25085. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  25086. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  25087. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  25088. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  25089. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  25090. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  25091. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  25092. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  25093. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  25094. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  25095. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  25096. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  25097. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  25098. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  25099. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  25100. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  25101. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  25102. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  25103. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  25104. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  25105. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  25106. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  25107. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  25108. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  25109. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  25110. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  25111. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  25112. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  25113. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  25114. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  25115. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  25116. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  25117. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  25118. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  25119. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  25120. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  25121. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  25122. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  25123. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  25124. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  25125. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  25126. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  25127. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  25128. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  25129. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  25130. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  25131. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  25132. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  25133. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  25134. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  25135. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  25136. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  25137. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  25138. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  25139. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  25140. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  25141. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  25142. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  25143. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  25144. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  25145. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  25146. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  25147. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  25148. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  25149. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  25150. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  25151. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  25152. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  25153. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  25154. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  25155. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  25156. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  25157. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  25158. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  25159. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  25160. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  25161. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  25162. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  25163. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  25164. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  25165. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  25166. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  25167. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  25168. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  25169. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  25170. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  25171. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  25172. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  25173. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  25174. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  25175. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  25176. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  25177. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  25178. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  25179. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  25180. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  25181. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  25182. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  25183. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  25184. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  25185. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  25186. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  25187. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  25188. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  25189. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  25190. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  25191. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  25192. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  25193. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  25194. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  25195. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  25196. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  25197. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  25198. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  25199. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  25200. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  25201. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  25202. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  25203. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  25204. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  25205. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  25206. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  25207. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  25208. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  25209. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  25210. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  25211. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  25212. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  25213. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  25214. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  25215. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  25216. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  25217. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  25218. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  25219. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  25220. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  25221. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  25222. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  25223. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  25224. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  25225. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  25226. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  25227. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  25228. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  25229. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  25230. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  25231. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25232. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25233. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25234. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25235. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25236. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25237. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25238. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25239. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25240. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25241. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25242. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25243. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25244. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25245. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25246. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25247. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25248. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25249. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25250. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25251. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25252. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25253. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25254. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25255. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25256. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25257. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25258. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25259. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25260. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25261. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25262. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  25263. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  25264. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  25265. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  25266. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  25267. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  25268. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  25269. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  25270. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  25271. };
  25272. #endif
  25273. #ifndef WOLFSSL_NO_KYBER1024
  25274. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  25275. /* d */
  25276. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  25277. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  25278. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  25279. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  25280. /* z */
  25281. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25282. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25283. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25284. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25285. };
  25286. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  25287. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25288. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25289. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25290. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25291. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25292. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25293. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25294. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25295. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25296. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25297. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25298. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25299. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25300. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25301. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25302. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25303. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25304. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25305. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25306. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25307. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25308. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25309. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25310. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25311. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25312. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25313. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25314. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25315. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25316. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25317. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25318. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25319. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25320. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25321. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25322. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25323. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25324. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25325. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25326. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25327. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25328. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25329. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25330. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25331. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25332. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25333. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25334. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25335. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25336. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25337. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25338. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25339. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25340. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25341. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25342. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25343. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25344. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25345. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25346. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25347. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25348. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25349. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25350. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25351. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25352. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25353. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25354. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25355. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25356. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25357. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25358. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25359. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25360. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25361. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25362. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25363. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25364. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25365. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25366. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25367. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25368. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25369. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25370. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25371. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25372. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25373. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25374. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25375. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25376. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25377. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25378. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25379. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25380. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25381. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25382. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25383. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25384. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25385. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25386. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25387. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25388. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25389. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25390. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25391. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25392. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25393. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25394. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25395. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25396. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25397. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25398. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25399. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25400. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25401. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25402. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25403. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25404. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25405. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25406. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25407. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25408. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25409. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25410. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25411. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25412. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25413. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25414. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25415. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25416. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25417. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25418. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25419. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25420. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25421. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25422. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25423. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25424. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25425. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25426. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25427. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25428. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25429. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25430. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25431. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25432. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25433. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25434. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25435. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25436. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25437. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25438. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25439. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25440. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25441. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25442. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25443. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25444. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25445. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25446. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25447. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25448. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25449. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25450. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25451. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25452. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25453. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25454. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25455. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25456. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25457. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25458. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25459. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25460. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25461. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25462. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25463. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25464. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25465. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25466. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25467. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25468. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25469. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25470. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25471. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25472. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25473. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25474. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25475. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25476. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25477. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25478. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25479. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25480. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25481. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25482. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25483. };
  25484. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25485. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25486. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25487. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25488. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25489. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25490. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25491. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25492. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25493. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25494. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25495. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25496. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25497. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25498. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25499. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25500. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25501. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25502. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25503. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25504. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25505. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25506. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25507. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25508. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25509. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25510. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25511. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25512. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25513. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25514. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25515. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25516. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25517. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25518. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25519. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25520. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25521. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25522. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25523. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25524. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25525. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25526. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25527. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25528. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25529. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25530. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25531. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25532. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25533. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25534. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25535. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25536. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25537. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25538. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25539. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25540. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25541. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25542. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25543. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25544. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25545. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25546. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25547. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25548. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25549. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25550. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25551. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25552. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25553. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25554. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25555. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25556. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25557. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25558. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25559. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25560. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25561. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25562. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25563. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25564. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25565. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25566. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25567. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25568. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25569. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25570. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25571. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25572. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25573. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25574. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25575. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25576. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25577. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25578. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25579. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25580. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25581. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25582. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25583. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25584. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25585. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25586. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25587. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25588. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25589. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25590. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25591. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25592. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25593. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25594. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25595. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25596. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25597. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25598. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25599. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25600. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25601. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25602. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25603. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25604. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25605. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25606. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25607. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25608. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25609. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25610. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25611. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25612. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25613. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25614. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25615. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25616. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25617. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25618. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25619. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25620. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25621. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25622. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25623. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25624. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25625. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25626. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25627. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25628. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25629. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25630. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25631. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25632. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25633. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25634. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25635. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25636. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25637. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25638. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25639. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25640. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25641. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25642. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25643. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25644. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25645. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25646. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25647. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25648. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25649. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25650. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25651. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25652. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25653. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25654. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25655. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25656. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25657. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25658. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25659. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25660. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25661. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25662. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25663. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25664. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25665. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25666. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25667. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25668. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25669. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25670. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25671. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25672. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25673. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25674. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25675. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25676. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25677. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25678. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25679. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25680. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25681. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25682. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25683. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25684. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25685. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25686. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25687. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25688. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25689. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25690. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25691. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25692. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25693. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25694. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25695. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25696. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25697. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25698. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25699. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25700. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25701. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25702. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25703. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25704. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25705. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25706. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25707. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25708. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25709. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25710. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25711. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25712. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25713. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25714. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25715. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25716. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25717. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25718. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25719. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25720. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25721. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25722. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25723. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25724. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25725. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25726. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25727. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25728. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25729. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25730. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25731. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25732. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25733. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25734. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25735. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25736. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25737. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25738. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25739. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25740. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25741. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25742. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25743. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25744. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25745. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25746. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25747. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25748. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25749. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25750. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25751. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25752. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25753. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25754. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25755. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25756. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25757. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25758. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25759. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25760. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25761. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25762. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25763. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25764. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25765. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25766. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25767. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25768. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25769. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25770. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25771. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25772. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25773. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25774. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25775. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25776. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25777. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25778. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25779. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25780. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25781. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25782. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25783. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25784. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25785. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25786. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25787. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25788. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25789. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25790. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25791. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25792. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25793. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25794. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25795. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25796. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25797. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25798. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25799. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25800. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25801. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25802. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25803. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25804. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25805. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25806. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25807. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25808. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25809. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25810. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25811. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25812. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25813. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25814. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25815. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25816. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25817. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25818. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25819. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25820. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25821. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25822. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25823. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25824. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25825. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25826. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25827. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25828. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25829. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25830. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25831. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25832. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25833. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25834. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25835. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25836. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25837. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25838. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25839. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25840. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25841. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25842. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25843. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25844. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25845. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25846. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25847. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25848. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25849. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25850. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25851. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25852. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25853. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25854. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25855. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25856. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25857. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25858. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25859. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25860. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25861. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25862. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25863. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25864. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25865. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25866. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25867. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25868. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25869. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25870. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25871. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25872. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  25873. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  25874. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  25875. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  25876. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  25877. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25878. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25879. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25880. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25881. };
  25882. #endif
  25883. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  25884. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  25885. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25886. ExpectNotNull(key);
  25887. if (key != NULL) {
  25888. XMEMSET(key, 0, sizeof(KyberKey));
  25889. }
  25890. #ifndef WOLFSSL_NO_KYBER512
  25891. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  25892. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  25893. 0);
  25894. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25895. KYBER512_PUBLIC_KEY_SIZE), 0);
  25896. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25897. KYBER512_PRIVATE_KEY_SIZE), 0);
  25898. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  25899. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  25900. wc_KyberKey_Free(key);
  25901. #endif
  25902. #ifndef WOLFSSL_NO_KYBER768
  25903. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  25904. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  25905. 0);
  25906. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25907. KYBER768_PUBLIC_KEY_SIZE), 0);
  25908. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25909. KYBER768_PRIVATE_KEY_SIZE), 0);
  25910. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  25911. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  25912. wc_KyberKey_Free(key);
  25913. #endif
  25914. #ifndef WOLFSSL_NO_KYBER1024
  25915. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  25916. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  25917. sizeof(seed_1024)), 0);
  25918. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25919. KYBER1024_PUBLIC_KEY_SIZE), 0);
  25920. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25921. KYBER1024_PRIVATE_KEY_SIZE), 0);
  25922. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  25923. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  25924. wc_KyberKey_Free(key);
  25925. #endif
  25926. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25927. #endif
  25928. return EXPECT_RESULT();
  25929. }
  25930. static int test_wc_kyber_encapsulate_kats(void)
  25931. {
  25932. EXPECT_DECLS;
  25933. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  25934. !defined(WOLFSSL_KYBER_ORIGINAL)
  25935. KyberKey* key;
  25936. #ifndef WOLFSSL_NO_KYBER512
  25937. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  25938. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  25939. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  25940. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  25941. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  25942. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  25943. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  25944. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  25945. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  25946. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  25947. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  25948. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  25949. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  25950. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  25951. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  25952. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  25953. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  25954. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  25955. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  25956. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  25957. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  25958. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  25959. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  25960. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  25961. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  25962. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  25963. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  25964. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  25965. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  25966. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  25967. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  25968. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  25969. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  25970. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  25971. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  25972. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  25973. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  25974. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  25975. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  25976. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  25977. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  25978. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  25979. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  25980. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  25981. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  25982. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  25983. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  25984. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  25985. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  25986. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  25987. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  25988. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  25989. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  25990. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  25991. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  25992. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  25993. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  25994. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  25995. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  25996. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  25997. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  25998. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  25999. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  26000. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  26001. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  26002. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  26003. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  26004. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  26005. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  26006. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  26007. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  26008. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  26009. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  26010. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  26011. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  26012. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  26013. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  26014. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  26015. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  26016. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  26017. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  26018. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  26019. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  26020. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  26021. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  26022. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  26023. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  26024. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  26025. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  26026. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  26027. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  26028. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  26029. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  26030. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  26031. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  26032. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  26033. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  26034. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  26035. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  26036. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  26037. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  26038. };
  26039. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  26040. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  26041. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  26042. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  26043. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  26044. };
  26045. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26046. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  26047. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  26048. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  26049. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  26050. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  26051. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  26052. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  26053. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  26054. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  26055. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  26056. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  26057. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  26058. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  26059. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  26060. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  26061. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  26062. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  26063. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  26064. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  26065. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  26066. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  26067. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  26068. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  26069. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  26070. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  26071. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  26072. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  26073. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  26074. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  26075. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  26076. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  26077. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  26078. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  26079. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  26080. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  26081. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  26082. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  26083. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  26084. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  26085. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  26086. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  26087. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  26088. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  26089. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  26090. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  26091. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  26092. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  26093. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  26094. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  26095. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  26096. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  26097. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  26098. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  26099. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  26100. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  26101. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  26102. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  26103. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  26104. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  26105. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  26106. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  26107. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  26108. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  26109. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  26110. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  26111. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  26112. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  26113. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  26114. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  26115. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  26116. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  26117. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  26118. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  26119. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  26120. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  26121. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  26122. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  26123. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  26124. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  26125. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  26126. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  26127. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  26128. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  26129. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  26130. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  26131. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  26132. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  26133. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  26134. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  26135. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  26136. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  26137. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  26138. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  26139. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  26140. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  26141. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  26142. };
  26143. static const byte k_512[KYBER_SS_SZ] = {
  26144. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  26145. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  26146. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  26147. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  26148. };
  26149. #endif
  26150. #ifndef WOLFSSL_NO_KYBER768
  26151. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  26152. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  26153. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  26154. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  26155. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  26156. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  26157. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  26158. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  26159. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  26160. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  26161. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  26162. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  26163. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  26164. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  26165. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  26166. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  26167. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  26168. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  26169. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  26170. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  26171. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  26172. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  26173. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  26174. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  26175. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  26176. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  26177. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  26178. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  26179. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  26180. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  26181. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  26182. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  26183. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  26184. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  26185. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  26186. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  26187. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  26188. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  26189. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  26190. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  26191. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  26192. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  26193. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  26194. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  26195. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  26196. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  26197. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  26198. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  26199. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  26200. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  26201. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  26202. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  26203. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  26204. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  26205. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  26206. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  26207. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  26208. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  26209. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  26210. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  26211. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  26212. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  26213. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  26214. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  26215. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  26216. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  26217. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  26218. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  26219. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  26220. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  26221. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  26222. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  26223. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  26224. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  26225. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  26226. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  26227. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  26228. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  26229. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  26230. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  26231. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  26232. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  26233. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  26234. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  26235. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  26236. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  26237. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  26238. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  26239. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  26240. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  26241. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  26242. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  26243. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  26244. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  26245. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  26246. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  26247. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  26248. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  26249. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  26250. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  26251. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  26252. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  26253. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  26254. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  26255. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  26256. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  26257. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  26258. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  26259. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  26260. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  26261. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  26262. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  26263. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  26264. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  26265. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  26266. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  26267. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  26268. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  26269. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  26270. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  26271. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  26272. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  26273. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  26274. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  26275. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  26276. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  26277. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  26278. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  26279. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  26280. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  26281. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  26282. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  26283. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  26284. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  26285. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  26286. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  26287. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  26288. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  26289. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  26290. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  26291. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  26292. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  26293. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  26294. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  26295. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  26296. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  26297. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  26298. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  26299. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  26300. };
  26301. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  26302. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  26303. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  26304. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  26305. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  26306. };
  26307. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  26308. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  26309. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  26310. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  26311. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  26312. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  26313. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  26314. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  26315. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  26316. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  26317. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  26318. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  26319. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  26320. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  26321. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  26322. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  26323. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  26324. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  26325. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  26326. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  26327. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  26328. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  26329. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  26330. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  26331. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  26332. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  26333. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  26334. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  26335. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  26336. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  26337. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  26338. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  26339. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  26340. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  26341. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  26342. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  26343. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  26344. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  26345. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  26346. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  26347. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  26348. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  26349. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  26350. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  26351. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  26352. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  26353. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  26354. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  26355. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  26356. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  26357. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  26358. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  26359. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  26360. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  26361. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  26362. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  26363. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  26364. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  26365. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  26366. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  26367. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  26368. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  26369. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  26370. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  26371. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  26372. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  26373. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  26374. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  26375. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  26376. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  26377. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  26378. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  26379. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  26380. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  26381. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  26382. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  26383. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  26384. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  26385. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  26386. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  26387. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  26388. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  26389. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  26390. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  26391. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  26392. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  26393. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  26394. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  26395. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  26396. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  26397. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  26398. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  26399. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  26400. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  26401. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  26402. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  26403. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  26404. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  26405. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  26406. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  26407. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  26408. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  26409. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  26410. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  26411. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  26412. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  26413. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  26414. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  26415. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  26416. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  26417. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  26418. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  26419. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  26420. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  26421. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  26422. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  26423. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  26424. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  26425. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  26426. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  26427. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  26428. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  26429. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  26430. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  26431. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  26432. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  26433. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  26434. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  26435. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  26436. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  26437. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  26438. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  26439. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  26440. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  26441. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  26442. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  26443. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  26444. };
  26445. static const byte k_768[KYBER_SS_SZ] = {
  26446. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  26447. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  26448. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  26449. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26450. };
  26451. #endif
  26452. #ifndef WOLFSSL_NO_KYBER1024
  26453. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26454. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26455. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26456. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26457. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26458. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26459. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26460. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26461. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26462. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26463. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26464. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26465. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26466. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26467. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26468. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26469. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26470. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26471. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26472. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26473. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26474. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26475. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26476. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26477. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26478. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26479. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26480. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26481. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26482. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26483. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26484. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26485. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26486. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26487. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26488. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26489. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26490. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26491. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26492. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26493. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26494. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26495. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26496. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26497. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26498. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26499. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26500. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26501. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26502. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26503. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26504. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26505. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26506. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26507. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26508. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26509. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26510. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26511. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26512. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26513. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26514. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26515. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26516. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26517. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26518. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26519. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26520. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26521. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26522. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26523. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26524. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26525. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26526. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26527. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26528. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26529. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26530. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26531. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26532. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26533. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26534. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26535. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26536. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26537. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26538. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26539. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26540. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26541. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26542. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26543. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26544. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26545. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26546. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26547. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26548. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26549. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26550. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26551. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26552. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26553. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26554. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26555. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26556. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26557. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26558. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26559. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26560. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26561. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26562. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26563. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26564. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26565. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26566. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26567. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26568. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26569. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26570. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26571. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26572. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26573. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26574. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26575. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26576. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26577. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26578. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26579. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26580. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26581. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26582. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26583. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26584. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26585. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26586. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26587. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26588. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26589. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26590. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26591. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26592. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26593. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26594. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26595. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26596. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26597. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26598. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26599. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26600. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26601. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26602. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26603. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26604. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26605. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26606. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26607. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26608. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26609. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26610. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26611. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26612. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26613. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26614. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26615. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26616. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26617. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26618. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26619. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26620. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26621. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26622. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26623. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26624. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26625. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26626. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26627. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26628. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26629. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26630. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26631. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26632. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26633. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26634. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26635. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26636. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26637. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26638. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26639. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26640. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26641. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26642. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26643. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26644. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26645. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26646. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26647. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26648. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26649. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26650. };
  26651. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26652. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26653. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26654. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26655. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26656. };
  26657. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26658. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26659. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26660. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26661. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26662. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26663. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26664. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26665. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26666. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26667. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26668. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26669. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26670. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26671. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26672. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26673. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26674. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26675. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26676. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26677. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26678. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26679. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26680. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26681. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26682. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26683. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26684. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26685. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26686. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26687. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26688. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26689. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26690. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26691. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26692. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26693. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26694. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26695. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26696. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26697. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26698. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26699. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26700. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26701. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26702. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26703. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26704. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26705. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26706. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26707. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26708. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26709. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26710. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26711. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26712. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26713. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26714. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26715. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26716. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26717. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26718. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26719. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26720. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26721. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26722. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26723. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26724. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26725. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26726. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26727. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26728. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26729. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26730. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26731. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26732. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26733. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26734. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26735. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26736. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26737. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26738. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26739. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26740. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26741. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26742. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26743. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26744. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26745. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26746. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26747. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26748. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26749. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26750. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26751. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26752. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26753. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26754. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26755. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26756. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26757. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26758. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26759. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26760. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26761. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26762. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26763. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26764. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26765. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26766. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26767. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26768. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26769. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26770. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26771. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26772. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26773. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26774. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26775. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26776. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26777. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26778. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26779. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26780. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26781. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26782. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26783. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26784. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26785. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26786. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26787. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26788. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26789. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26790. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26791. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26792. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26793. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26794. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26795. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26796. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26797. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26798. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26799. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26800. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26801. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26802. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26803. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26804. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26805. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26806. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26807. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26808. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26809. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26810. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26811. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26812. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26813. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26814. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26815. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26816. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26817. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26818. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26819. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26820. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26821. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26822. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26823. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26824. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26825. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26826. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26827. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26828. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26829. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26830. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26831. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26832. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26833. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26834. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26835. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26836. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26837. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26838. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26839. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26840. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26841. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26842. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26843. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26844. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26845. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26846. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26847. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26848. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26849. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26850. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26851. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26852. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26853. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26854. };
  26855. static const byte k_1024[KYBER_SS_SZ] = {
  26856. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26857. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26858. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26859. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26860. };
  26861. #endif
  26862. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26863. static byte ss[KYBER_SS_SZ];
  26864. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26865. ExpectNotNull(key);
  26866. if (key != NULL) {
  26867. XMEMSET(key, 0, sizeof(KyberKey));
  26868. }
  26869. #ifndef WOLFSSL_NO_KYBER512
  26870. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26871. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  26872. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  26873. sizeof(seed_512)), 0);
  26874. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  26875. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  26876. wc_KyberKey_Free(key);
  26877. #endif
  26878. #ifndef WOLFSSL_NO_KYBER768
  26879. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26880. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  26881. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  26882. sizeof(seed_768)), 0);
  26883. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  26884. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  26885. wc_KyberKey_Free(key);
  26886. #endif
  26887. #ifndef WOLFSSL_NO_KYBER1024
  26888. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26889. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  26890. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  26891. sizeof(seed_1024)), 0);
  26892. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  26893. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  26894. wc_KyberKey_Free(key);
  26895. #endif
  26896. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26897. #endif
  26898. return EXPECT_RESULT();
  26899. }
  26900. static int test_wc_kyber_decapsulate_kats(void)
  26901. {
  26902. EXPECT_DECLS;
  26903. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26904. !defined(WOLFSSL_KYBER_ORIGINAL)
  26905. KyberKey* key;
  26906. #ifndef WOLFSSL_NO_KYBER512
  26907. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  26908. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  26909. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  26910. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  26911. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  26912. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  26913. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  26914. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  26915. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  26916. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  26917. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  26918. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  26919. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  26920. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  26921. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  26922. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  26923. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  26924. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  26925. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  26926. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  26927. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  26928. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  26929. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  26930. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  26931. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  26932. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  26933. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  26934. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  26935. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  26936. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  26937. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  26938. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  26939. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  26940. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  26941. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  26942. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  26943. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  26944. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  26945. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  26946. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  26947. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  26948. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  26949. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  26950. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  26951. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  26952. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  26953. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  26954. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  26955. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  26956. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  26957. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  26958. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  26959. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  26960. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  26961. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  26962. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  26963. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  26964. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  26965. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  26966. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  26967. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  26968. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  26969. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  26970. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  26971. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  26972. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  26973. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  26974. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  26975. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  26976. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  26977. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  26978. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  26979. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  26980. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  26981. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  26982. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  26983. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  26984. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  26985. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  26986. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  26987. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  26988. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  26989. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  26990. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  26991. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  26992. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  26993. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  26994. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  26995. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  26996. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  26997. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  26998. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  26999. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  27000. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  27001. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  27002. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  27003. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  27004. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  27005. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  27006. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  27007. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  27008. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  27009. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  27010. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  27011. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  27012. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  27013. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  27014. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  27015. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  27016. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  27017. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  27018. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  27019. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  27020. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  27021. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  27022. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  27023. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  27024. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  27025. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  27026. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  27027. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  27028. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  27029. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  27030. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  27031. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  27032. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  27033. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  27034. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  27035. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  27036. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  27037. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  27038. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  27039. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  27040. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  27041. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  27042. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  27043. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  27044. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  27045. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  27046. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  27047. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  27048. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  27049. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  27050. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  27051. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  27052. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  27053. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  27054. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  27055. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  27056. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  27057. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  27058. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  27059. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  27060. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  27061. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  27062. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  27063. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  27064. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  27065. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  27066. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  27067. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  27068. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  27069. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  27070. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  27071. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  27072. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  27073. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  27074. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  27075. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  27076. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  27077. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  27078. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  27079. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  27080. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  27081. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  27082. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  27083. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  27084. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  27085. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  27086. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  27087. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  27088. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  27089. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  27090. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  27091. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  27092. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  27093. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  27094. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  27095. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  27096. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  27097. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  27098. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  27099. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  27100. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  27101. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  27102. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  27103. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  27104. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  27105. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  27106. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  27107. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  27108. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  27109. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  27110. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  27111. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  27112. };
  27113. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  27114. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  27115. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  27116. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  27117. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  27118. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  27119. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  27120. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  27121. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  27122. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  27123. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  27124. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  27125. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  27126. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  27127. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  27128. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  27129. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  27130. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  27131. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  27132. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  27133. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  27134. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  27135. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  27136. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  27137. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  27138. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  27139. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  27140. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  27141. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  27142. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  27143. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  27144. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  27145. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  27146. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  27147. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  27148. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  27149. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  27150. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  27151. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  27152. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  27153. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  27154. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  27155. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  27156. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  27157. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  27158. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  27159. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  27160. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  27161. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  27162. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  27163. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  27164. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  27165. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  27166. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  27167. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  27168. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  27169. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  27170. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  27171. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  27172. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  27173. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  27174. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  27175. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  27176. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  27177. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  27178. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  27179. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  27180. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  27181. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  27182. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  27183. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  27184. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  27185. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  27186. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  27187. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  27188. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  27189. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  27190. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  27191. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  27192. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  27193. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  27194. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  27195. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  27196. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  27197. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  27198. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  27199. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  27200. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  27201. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  27202. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  27203. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  27204. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  27205. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  27206. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  27207. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  27208. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  27209. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  27210. };
  27211. static const byte kprime_512[KYBER_SS_SZ] = {
  27212. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  27213. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  27214. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  27215. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  27216. };
  27217. #endif
  27218. #ifndef WOLFSSL_NO_KYBER768
  27219. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  27220. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  27221. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  27222. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  27223. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  27224. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  27225. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  27226. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  27227. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  27228. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  27229. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  27230. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  27231. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  27232. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  27233. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  27234. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  27235. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  27236. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  27237. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  27238. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  27239. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  27240. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  27241. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  27242. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  27243. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  27244. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  27245. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  27246. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  27247. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  27248. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  27249. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  27250. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  27251. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  27252. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  27253. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  27254. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  27255. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  27256. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  27257. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  27258. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  27259. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  27260. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  27261. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  27262. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  27263. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  27264. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  27265. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  27266. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  27267. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  27268. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  27269. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  27270. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  27271. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  27272. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  27273. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  27274. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  27275. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  27276. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  27277. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  27278. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  27279. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  27280. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  27281. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  27282. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  27283. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  27284. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  27285. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  27286. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  27287. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  27288. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  27289. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  27290. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  27291. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  27292. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  27293. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  27294. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  27295. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  27296. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  27297. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  27298. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  27299. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  27300. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  27301. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  27302. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  27303. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  27304. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  27305. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  27306. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  27307. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  27308. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  27309. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  27310. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  27311. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  27312. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  27313. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  27314. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  27315. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  27316. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  27317. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  27318. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  27319. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  27320. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  27321. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  27322. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  27323. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  27324. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  27325. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  27326. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  27327. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  27328. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  27329. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  27330. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  27331. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  27332. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  27333. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  27334. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  27335. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  27336. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  27337. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  27338. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  27339. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  27340. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  27341. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  27342. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  27343. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  27344. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  27345. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  27346. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  27347. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  27348. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  27349. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  27350. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  27351. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  27352. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  27353. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  27354. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  27355. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  27356. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  27357. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  27358. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  27359. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  27360. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  27361. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  27362. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  27363. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  27364. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  27365. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  27366. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  27367. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  27368. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  27369. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  27370. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  27371. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  27372. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  27373. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  27374. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  27375. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  27376. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  27377. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  27378. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  27379. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  27380. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  27381. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  27382. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  27383. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  27384. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  27385. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  27386. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  27387. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  27388. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  27389. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  27390. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  27391. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  27392. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  27393. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  27394. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  27395. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  27396. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  27397. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  27398. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  27399. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  27400. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  27401. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  27402. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  27403. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  27404. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  27405. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  27406. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  27407. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  27408. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  27409. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  27410. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  27411. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  27412. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  27413. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  27414. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  27415. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  27416. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  27417. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  27418. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  27419. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  27420. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  27421. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  27422. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  27423. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  27424. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  27425. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  27426. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  27427. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  27428. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  27429. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  27430. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  27431. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  27432. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  27433. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  27434. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  27435. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  27436. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  27437. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  27438. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  27439. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  27440. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  27441. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  27442. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  27443. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  27444. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  27445. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  27446. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  27447. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  27448. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  27449. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27450. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27451. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27452. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27453. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27454. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27455. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27456. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27457. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27458. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27459. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27460. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27461. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27462. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27463. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27464. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27465. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27466. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27467. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27468. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27469. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27470. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27471. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27472. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27473. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27474. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27475. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27476. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27477. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27478. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27479. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27480. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27481. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27482. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27483. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27484. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27485. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27486. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27487. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27488. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27489. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27490. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27491. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27492. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27493. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27494. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27495. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27496. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27497. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27498. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27499. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27500. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27501. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27502. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27503. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27504. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27505. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27506. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27507. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27508. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27509. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27510. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27511. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27512. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27513. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27514. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27515. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27516. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27517. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27518. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27519. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27520. };
  27521. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27522. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27523. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27524. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27525. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27526. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27527. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27528. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27529. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27530. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27531. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27532. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27533. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27534. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27535. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27536. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27537. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27538. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27539. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27540. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27541. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27542. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27543. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27544. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27545. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27546. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27547. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27548. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27549. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27550. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27551. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27552. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27553. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27554. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27555. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27556. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27557. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27558. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27559. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27560. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27561. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27562. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27563. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27564. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27565. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27566. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27567. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27568. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27569. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27570. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27571. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27572. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27573. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27574. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27575. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27576. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27577. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27578. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27579. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27580. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27581. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27582. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27583. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27584. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27585. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27586. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27587. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27588. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27589. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27590. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27591. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27592. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27593. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27594. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27595. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27596. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27597. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27598. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27599. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27600. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27601. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27602. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27603. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27604. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27605. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27606. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27607. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27608. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27609. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27610. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27611. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27612. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27613. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27614. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27615. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27616. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27617. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27618. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27619. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27620. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27621. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27622. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27623. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27624. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27625. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27626. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27627. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27628. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27629. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27630. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27631. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27632. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27633. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27634. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27635. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27636. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27637. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27638. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27639. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27640. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27641. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27642. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27643. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27644. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27645. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27646. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27647. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27648. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27649. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27650. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27651. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27652. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27653. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27654. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27655. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27656. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27657. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27658. };
  27659. static const byte kprime_768[KYBER_SS_SZ] = {
  27660. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27661. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27662. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27663. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27664. };
  27665. #endif
  27666. #ifndef WOLFSSL_NO_KYBER1024
  27667. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27668. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27669. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27670. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27671. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27672. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27673. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27674. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27675. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27676. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27677. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27678. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27679. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27680. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27681. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27682. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27683. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27684. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27685. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27686. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27687. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27688. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27689. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27690. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27691. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27692. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27693. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27694. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27695. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27696. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27697. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27698. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27699. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27700. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27701. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27702. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27703. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27704. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27705. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27706. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27707. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27708. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27709. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27710. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27711. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27712. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27713. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27714. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27715. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27716. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27717. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27718. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27719. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27720. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27721. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27722. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27723. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27724. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27725. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27726. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27727. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27728. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27729. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27730. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27731. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27732. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27733. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27734. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27735. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27736. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27737. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27738. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27739. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27740. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27741. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27742. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27743. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27744. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27745. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27746. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27747. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27748. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27749. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27750. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27751. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27752. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27753. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27754. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27755. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27756. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27757. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27758. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27759. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27760. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27761. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27762. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27763. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27764. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27765. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27766. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27767. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27768. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27769. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27770. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27771. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27772. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27773. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27774. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27775. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27776. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27777. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27778. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27779. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27780. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27781. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27782. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27783. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27784. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27785. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27786. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27787. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27788. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27789. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27790. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27791. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27792. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27793. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27794. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27795. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27796. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27797. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27798. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27799. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27800. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27801. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27802. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27803. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27804. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27805. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27806. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27807. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27808. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27809. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27810. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27811. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27812. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27813. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27814. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27815. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27816. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27817. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27818. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27819. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27820. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27821. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27822. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27823. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27824. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27825. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27826. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27827. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27828. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27829. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27830. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27831. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27832. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27833. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27834. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27835. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27836. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27837. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27838. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27839. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27840. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27841. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27842. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27843. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27844. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27845. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27846. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27847. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27848. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27849. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27850. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27851. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27852. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27853. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27854. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27855. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27856. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27857. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27858. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27859. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27860. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27861. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27862. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27863. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27864. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27865. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27866. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27867. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27868. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27869. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  27870. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  27871. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  27872. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  27873. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  27874. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  27875. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  27876. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  27877. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  27878. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  27879. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  27880. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  27881. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  27882. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  27883. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  27884. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  27885. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  27886. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  27887. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  27888. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  27889. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  27890. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  27891. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  27892. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  27893. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  27894. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  27895. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  27896. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  27897. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  27898. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  27899. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  27900. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  27901. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  27902. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  27903. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  27904. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  27905. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  27906. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  27907. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  27908. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  27909. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  27910. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  27911. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  27912. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  27913. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  27914. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  27915. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  27916. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  27917. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  27918. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  27919. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  27920. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  27921. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  27922. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  27923. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  27924. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  27925. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  27926. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  27927. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  27928. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  27929. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  27930. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  27931. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  27932. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  27933. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  27934. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  27935. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  27936. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  27937. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  27938. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  27939. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  27940. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  27941. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  27942. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  27943. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  27944. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  27945. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  27946. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  27947. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  27948. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  27949. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  27950. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  27951. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  27952. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  27953. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  27954. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  27955. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  27956. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  27957. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  27958. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  27959. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  27960. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  27961. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  27962. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  27963. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  27964. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  27965. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  27966. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  27967. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  27968. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  27969. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  27970. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  27971. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  27972. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  27973. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  27974. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  27975. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  27976. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  27977. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  27978. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  27979. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  27980. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  27981. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  27982. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  27983. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  27984. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  27985. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  27986. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  27987. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  27988. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  27989. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  27990. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  27991. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  27992. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  27993. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  27994. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  27995. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  27996. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  27997. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  27998. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  27999. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  28000. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  28001. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  28002. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  28003. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  28004. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  28005. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  28006. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  28007. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  28008. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  28009. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  28010. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  28011. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  28012. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  28013. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  28014. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  28015. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  28016. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  28017. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  28018. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  28019. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  28020. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  28021. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  28022. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  28023. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  28024. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  28025. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  28026. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  28027. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  28028. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  28029. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  28030. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  28031. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  28032. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  28033. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  28034. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  28035. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  28036. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  28037. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  28038. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  28039. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  28040. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  28041. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  28042. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  28043. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  28044. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  28045. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  28046. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  28047. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  28048. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  28049. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  28050. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  28051. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  28052. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  28053. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  28054. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  28055. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  28056. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  28057. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  28058. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  28059. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  28060. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  28061. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  28062. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  28063. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  28064. };
  28065. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  28066. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  28067. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  28068. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  28069. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  28070. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  28071. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  28072. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  28073. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  28074. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  28075. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  28076. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  28077. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  28078. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  28079. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  28080. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  28081. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  28082. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  28083. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  28084. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  28085. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  28086. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  28087. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  28088. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  28089. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  28090. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  28091. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  28092. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  28093. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  28094. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  28095. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  28096. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  28097. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  28098. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  28099. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  28100. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  28101. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  28102. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  28103. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  28104. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  28105. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  28106. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  28107. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  28108. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  28109. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  28110. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  28111. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  28112. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  28113. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  28114. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  28115. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  28116. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  28117. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  28118. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  28119. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  28120. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  28121. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  28122. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  28123. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  28124. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  28125. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  28126. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  28127. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  28128. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  28129. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  28130. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  28131. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  28132. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  28133. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  28134. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  28135. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  28136. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  28137. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  28138. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  28139. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  28140. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  28141. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  28142. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  28143. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  28144. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  28145. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  28146. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  28147. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  28148. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  28149. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  28150. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  28151. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  28152. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  28153. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  28154. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  28155. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  28156. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  28157. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  28158. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  28159. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  28160. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  28161. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  28162. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  28163. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  28164. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  28165. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  28166. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  28167. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  28168. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  28169. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  28170. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  28171. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  28172. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  28173. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  28174. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  28175. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  28176. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  28177. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  28178. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  28179. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  28180. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  28181. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  28182. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  28183. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  28184. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  28185. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  28186. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  28187. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  28188. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  28189. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  28190. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  28191. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  28192. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  28193. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  28194. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  28195. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  28196. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  28197. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  28198. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  28199. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  28200. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  28201. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  28202. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  28203. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  28204. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  28205. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  28206. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  28207. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  28208. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  28209. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  28210. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  28211. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  28212. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  28213. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  28214. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  28215. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  28216. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  28217. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  28218. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  28219. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  28220. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  28221. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  28222. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  28223. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  28224. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  28225. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  28226. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  28227. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  28228. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  28229. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  28230. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  28231. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  28232. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  28233. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  28234. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  28235. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  28236. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  28237. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  28238. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  28239. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  28240. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  28241. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  28242. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  28243. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  28244. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  28245. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  28246. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  28247. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  28248. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  28249. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  28250. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  28251. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  28252. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  28253. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  28254. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  28255. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  28256. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  28257. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  28258. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  28259. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  28260. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  28261. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  28262. };
  28263. static const byte kprime_1024[KYBER_SS_SZ] = {
  28264. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  28265. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  28266. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  28267. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  28268. };
  28269. #endif
  28270. static byte ss[KYBER_SS_SZ];
  28271. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28272. ExpectNotNull(key);
  28273. if (key != NULL) {
  28274. XMEMSET(key, 0, sizeof(KyberKey));
  28275. }
  28276. #ifndef WOLFSSL_NO_KYBER512
  28277. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  28278. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  28279. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  28280. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  28281. wc_KyberKey_Free(key);
  28282. #endif
  28283. #ifndef WOLFSSL_NO_KYBER768
  28284. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  28285. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  28286. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  28287. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  28288. wc_KyberKey_Free(key);
  28289. #endif
  28290. #ifndef WOLFSSL_NO_KYBER1024
  28291. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  28292. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  28293. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  28294. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  28295. wc_KyberKey_Free(key);
  28296. #endif
  28297. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28298. #endif
  28299. return EXPECT_RESULT();
  28300. }
  28301. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28302. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  28303. static const byte ml_dsa_44_pub_key[] = {
  28304. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  28305. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  28306. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  28307. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  28308. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  28309. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  28310. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  28311. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  28312. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  28313. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  28314. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  28315. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  28316. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  28317. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  28318. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  28319. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  28320. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  28321. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  28322. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  28323. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  28324. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  28325. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  28326. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  28327. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  28328. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  28329. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  28330. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  28331. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  28332. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  28333. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  28334. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  28335. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  28336. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  28337. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  28338. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  28339. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  28340. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  28341. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  28342. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  28343. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  28344. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  28345. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  28346. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  28347. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  28348. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  28349. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  28350. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  28351. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  28352. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  28353. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  28354. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  28355. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  28356. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  28357. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  28358. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  28359. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  28360. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  28361. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  28362. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  28363. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  28364. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  28365. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  28366. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  28367. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  28368. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  28369. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  28370. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  28371. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  28372. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  28373. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  28374. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  28375. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  28376. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  28377. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  28378. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  28379. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  28380. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  28381. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  28382. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  28383. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  28384. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  28385. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  28386. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  28387. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  28388. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  28389. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  28390. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  28391. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  28392. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  28393. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  28394. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  28395. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  28396. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  28397. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  28398. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  28399. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  28400. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  28401. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  28402. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  28403. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  28404. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  28405. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  28406. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  28407. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  28408. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  28409. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  28410. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  28411. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  28412. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  28413. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  28414. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  28415. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  28416. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  28417. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  28418. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  28419. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  28420. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  28421. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  28422. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  28423. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  28424. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  28425. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  28426. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  28427. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  28428. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  28429. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  28430. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  28431. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  28432. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  28433. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  28434. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  28435. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  28436. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  28437. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  28438. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  28439. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  28440. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  28441. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  28442. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  28443. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  28444. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  28445. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  28446. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  28447. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  28448. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  28449. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28450. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28451. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28452. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28453. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28454. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28455. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28456. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28457. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28458. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28459. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28460. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28461. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28462. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28463. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28464. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28465. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28466. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28467. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28468. };
  28469. static const byte ml_dsa_44_good_sig[] = {
  28470. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28471. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28472. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28473. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28474. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28475. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28476. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28477. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28478. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28479. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28480. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28481. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28482. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28483. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28484. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28485. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28486. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28487. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28488. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28489. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28490. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28491. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28492. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28493. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28494. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28495. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28496. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28497. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28498. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28499. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28500. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28501. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28502. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28503. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28504. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28505. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28506. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28507. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28508. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28509. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28510. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28511. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28512. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28513. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28514. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28515. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28516. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28517. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28518. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28519. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28520. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28521. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28522. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28523. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28524. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28525. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28526. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28527. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28528. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28529. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28530. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28531. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28532. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28533. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28534. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28535. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28536. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28537. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28538. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28539. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28540. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28541. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28542. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28543. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28544. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28545. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28546. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28547. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28548. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28549. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28550. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28551. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28552. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28553. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28554. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28555. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28556. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28557. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28558. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28559. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28560. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28561. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28562. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28563. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28564. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28565. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28566. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28567. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28568. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28569. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28570. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28571. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28572. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28573. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28574. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28575. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28576. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28577. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28578. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28579. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28580. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28581. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28582. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28583. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28584. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28585. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28586. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28587. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28588. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28589. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28590. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28591. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28592. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28593. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28594. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28595. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28596. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28597. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28598. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28599. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28600. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28601. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28602. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28603. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28604. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28605. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28606. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28607. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28608. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28609. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28610. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28611. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28612. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28613. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28614. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28615. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28616. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28617. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28618. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28619. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28620. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28621. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28622. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28623. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28624. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28625. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28626. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28627. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28628. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28629. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28630. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28631. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28632. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28633. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28634. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28635. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28636. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28637. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28638. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28639. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28640. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28641. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28642. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28643. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28644. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28645. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28646. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28647. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28648. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28649. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28650. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28651. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28652. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28653. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28654. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28655. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28656. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28657. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28658. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28659. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28660. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28661. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28662. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28663. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28664. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28665. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28666. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28667. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28668. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28669. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28670. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28671. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28672. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28673. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28674. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28675. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28676. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28677. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28678. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28679. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28680. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28681. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28682. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28683. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28684. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28685. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28686. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28687. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28688. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28689. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28690. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28691. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28692. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28693. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28694. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28695. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28696. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28697. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28698. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28699. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28700. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28701. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28702. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28703. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28704. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28705. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28706. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28707. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28708. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28709. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28710. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28711. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28712. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28713. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28714. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28715. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28716. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28717. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28718. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28719. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28720. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28721. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28722. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28723. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28724. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28725. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28726. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28727. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28728. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28729. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28730. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28731. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28732. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28733. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28734. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28735. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28736. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28737. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28738. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28739. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28740. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28741. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28742. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28743. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28744. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28745. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28746. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28747. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28748. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28749. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28750. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28751. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28752. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28753. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28754. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28755. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28756. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28757. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28758. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28759. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28760. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28761. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28762. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28763. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28764. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28765. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28766. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28767. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28768. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28769. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28770. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28771. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28772. 0x0f, 0x20, 0x30, 0x3e
  28773. };
  28774. #endif
  28775. static int test_wc_dilithium(void)
  28776. {
  28777. EXPECT_DECLS;
  28778. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28779. dilithium_key* key;
  28780. byte level;
  28781. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28782. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28783. WC_RNG rng;
  28784. #endif
  28785. byte* privKey = NULL;
  28786. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28787. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28788. #endif
  28789. byte* pubKey = NULL;
  28790. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28791. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28792. #endif
  28793. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28794. ExpectNotNull(key);
  28795. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28796. DYNAMIC_TYPE_TMP_BUFFER);
  28797. ExpectNotNull(privKey);
  28798. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28799. DYNAMIC_TYPE_TMP_BUFFER);
  28800. ExpectNotNull(pubKey);
  28801. if (key != NULL) {
  28802. XMEMSET(key, 0, sizeof(*key));
  28803. }
  28804. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28805. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28806. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28807. #endif
  28808. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28809. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28810. ExpectIntEQ(wc_InitRng(&rng), 0);
  28811. #endif
  28812. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28813. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28814. wc_dilithium_free(NULL);
  28815. ExpectIntEQ(wc_dilithium_init(key), 0);
  28816. wc_dilithium_free(key);
  28817. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28818. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28819. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28821. #endif
  28822. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28823. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28824. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28825. #endif
  28826. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28827. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28828. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28829. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28830. #endif
  28831. #endif
  28832. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28833. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28834. #endif
  28835. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28836. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28837. #endif
  28838. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28839. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28840. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28841. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28842. #endif
  28843. #endif
  28844. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28845. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28846. #endif
  28847. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28848. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28849. #endif
  28850. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28851. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28852. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28853. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28854. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28855. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28856. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28857. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28858. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28859. #ifndef WOLFSSL_NO_ML_DSA_87
  28860. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28861. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28862. ExpectIntEQ(level, WC_ML_DSA_87);
  28863. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28864. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28865. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28866. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28867. #endif
  28868. #endif
  28869. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28870. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28871. #endif
  28872. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28873. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  28874. #endif
  28875. #else
  28876. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28877. #endif
  28878. #ifndef WOLFSSL_NO_ML_DSA_65
  28879. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28880. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28881. ExpectIntEQ(level, WC_ML_DSA_65);
  28882. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28883. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  28884. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28885. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  28886. #endif
  28887. #endif
  28888. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28889. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28890. #endif
  28891. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28892. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  28893. #endif
  28894. #else
  28895. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28896. #endif
  28897. #ifndef WOLFSSL_NO_ML_DSA_44
  28898. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28899. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28900. ExpectIntEQ(level, WC_ML_DSA_44);
  28901. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28902. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  28903. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28904. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  28905. #endif
  28906. #endif
  28907. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28908. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28909. #endif
  28910. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28911. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  28912. #endif
  28913. #else
  28914. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28915. #endif
  28916. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28917. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28919. #endif
  28920. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28921. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28923. #endif
  28924. wc_dilithium_free(key);
  28925. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28926. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28927. wc_FreeRng(&rng);
  28928. #endif
  28929. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28930. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28931. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28932. #endif
  28933. return EXPECT_RESULT();
  28934. }
  28935. static int test_wc_dilithium_make_key(void)
  28936. {
  28937. EXPECT_DECLS;
  28938. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28939. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28940. dilithium_key* key;
  28941. WC_RNG rng;
  28942. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28943. ExpectNotNull(key);
  28944. if (key != NULL) {
  28945. XMEMSET(key, 0, sizeof(*key));
  28946. }
  28947. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28948. ExpectIntEQ(wc_InitRng(&rng), 0);
  28949. ExpectIntEQ(wc_dilithium_init(key), 0);
  28950. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  28951. #ifndef WOLFSSL_NO_ML_DSA_44
  28952. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28953. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28954. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28955. #else
  28956. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28957. #endif
  28958. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28959. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28960. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28961. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28962. wc_dilithium_free(key);
  28963. wc_FreeRng(&rng);
  28964. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28965. #endif
  28966. return EXPECT_RESULT();
  28967. }
  28968. static int test_wc_dilithium_sign(void)
  28969. {
  28970. EXPECT_DECLS;
  28971. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28972. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28973. dilithium_key* key;
  28974. dilithium_key* importKey = NULL;
  28975. WC_RNG rng;
  28976. byte* privKey = NULL;
  28977. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28978. word32 badKeyLen;
  28979. byte msg[32];
  28980. byte* sig = NULL;
  28981. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28982. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28983. ExpectNotNull(key);
  28984. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28985. DYNAMIC_TYPE_TMP_BUFFER);
  28986. ExpectNotNull(importKey);
  28987. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28988. DYNAMIC_TYPE_TMP_BUFFER);
  28989. ExpectNotNull(privKey);
  28990. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  28991. DYNAMIC_TYPE_TMP_BUFFER);
  28992. ExpectNotNull(sig);
  28993. if (key != NULL) {
  28994. XMEMSET(key, 0, sizeof(*key));
  28995. }
  28996. if (importKey != NULL) {
  28997. XMEMSET(importKey, 0, sizeof(*importKey));
  28998. }
  28999. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29000. XMEMSET(msg, 0x55, sizeof(msg));
  29001. ExpectIntEQ(wc_InitRng(&rng), 0);
  29002. ExpectIntEQ(wc_dilithium_init(key), 0);
  29003. #ifndef WOLFSSL_NO_ML_DSA_44
  29004. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29005. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29006. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29007. #else
  29008. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29009. #endif
  29010. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29011. #ifndef WOLFSSL_NO_ML_DSA_44
  29012. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  29013. sizeof_bench_dilithium_level2_key, key), 0);
  29014. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29015. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  29016. sizeof_bench_dilithium_level3_key, key), 0);
  29017. #else
  29018. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  29019. sizeof_bench_dilithium_level5_key, key), 0);
  29020. #endif
  29021. #else
  29022. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29023. #endif
  29024. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  29025. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29026. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  29027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29028. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  29029. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29030. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  29031. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29032. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  29033. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29034. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  29035. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29036. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  29037. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29038. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  29039. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29040. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  29041. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29042. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  29043. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29044. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  29045. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29046. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29047. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  29048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29049. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  29050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29051. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  29052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29053. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  29054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29055. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  29056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29057. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  29058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29059. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  29060. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29061. badKeyLen = 0;
  29062. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  29063. WC_NO_ERR_TRACE(BUFFER_E));
  29064. #ifndef WOLFSSL_NO_ML_DSA_44
  29065. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29066. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29067. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29068. #else
  29069. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29070. #endif
  29071. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  29072. 0);
  29073. #ifndef WOLFSSL_NO_ML_DSA_44
  29074. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29075. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29076. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29077. #else
  29078. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29079. #endif
  29080. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29081. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29083. #ifndef WOLFSSL_NO_ML_DSA_44
  29084. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29085. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29086. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29087. #else
  29088. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29089. #endif
  29090. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  29091. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29092. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  29093. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29094. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  29095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29096. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  29097. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29098. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  29099. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29100. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  29101. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29102. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  29103. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29104. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29105. 0);
  29106. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29107. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29108. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29109. #endif
  29110. wc_dilithium_free(importKey);
  29111. wc_dilithium_free(key);
  29112. wc_FreeRng(&rng);
  29113. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29114. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29115. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29116. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29117. #endif
  29118. return EXPECT_RESULT();
  29119. }
  29120. static int test_wc_dilithium_verify(void)
  29121. {
  29122. EXPECT_DECLS;
  29123. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29124. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  29125. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  29126. dilithium_key* key;
  29127. dilithium_key* importKey = NULL;
  29128. WC_RNG rng;
  29129. byte* pubKey = NULL;
  29130. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29131. word32 badKeyLen;
  29132. byte msg[32];
  29133. byte* sig = NULL;
  29134. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  29135. int res;
  29136. #ifndef WOLFSSL_NO_ML_DSA_44
  29137. byte b;
  29138. #endif
  29139. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29140. ExpectNotNull(key);
  29141. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  29142. DYNAMIC_TYPE_TMP_BUFFER);
  29143. ExpectNotNull(importKey);
  29144. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29145. DYNAMIC_TYPE_TMP_BUFFER);
  29146. ExpectNotNull(pubKey);
  29147. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29148. ExpectNotNull(sig);
  29149. if (key != NULL) {
  29150. XMEMSET(key, 0, sizeof(*key));
  29151. }
  29152. if (importKey != NULL) {
  29153. XMEMSET(importKey, 0, sizeof(*importKey));
  29154. }
  29155. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29156. XMEMSET(msg, 0x55, sizeof(msg));
  29157. ExpectIntEQ(wc_InitRng(&rng), 0);
  29158. ExpectIntEQ(wc_dilithium_init(key), 0);
  29159. #ifndef WOLFSSL_NO_ML_DSA_44
  29160. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29161. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29162. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29163. #else
  29164. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29165. #endif
  29166. #if !defined(WOLFSSL_NO_ML_DSA_44)
  29167. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  29168. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  29169. if (sig != NULL) {
  29170. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  29171. }
  29172. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  29173. #else
  29174. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29175. #ifndef WOLFSSL_NO_ML_DSA_65
  29176. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  29177. sizeof_bench_dilithium_level3_pub_key, key), 0);
  29178. #else
  29179. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  29180. sizeof_bench_dilithium_level5_pub_key, key), 0);
  29181. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  29182. #else
  29183. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29184. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  29185. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29186. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  29187. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  29188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29189. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  29190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29191. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  29192. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29193. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  29194. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29195. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  29196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29197. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  29198. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29199. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  29200. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29201. badKeyLen = 0;
  29202. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  29203. WC_NO_ERR_TRACE(BUFFER_E));
  29204. #ifndef WOLFSSL_NO_ML_DSA_44
  29205. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29206. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29207. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29208. #else
  29209. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29210. #endif
  29211. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  29212. #ifndef WOLFSSL_NO_ML_DSA_44
  29213. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29214. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29215. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29216. #else
  29217. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29218. #endif
  29219. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  29220. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29221. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  29222. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29223. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  29224. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29225. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  29226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29227. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  29228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29229. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  29230. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29231. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  29232. WC_NO_ERR_TRACE(BUFFER_E));
  29233. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  29234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29235. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  29236. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29237. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  29238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29239. res = 0;
  29240. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  29241. ExpectIntEQ(res, 1);
  29242. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29243. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  29244. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29245. #ifndef WOLFSSL_NO_ML_DSA_44
  29246. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29247. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29248. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29249. #else
  29250. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29251. #endif
  29252. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  29253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29254. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  29255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29256. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  29257. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29258. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  29259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29260. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  29261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29262. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  29263. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29264. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  29265. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29266. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  29267. res = 0;
  29268. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  29269. 0);
  29270. ExpectIntEQ(res, 1);
  29271. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29272. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29273. #endif
  29274. wc_dilithium_free(importKey);
  29275. #ifndef WOLFSSL_NO_ML_DSA_44
  29276. if (sig != NULL) {
  29277. if (sig[sigLen - 5] == 0) {
  29278. /* Unused hints meant to be 0. */
  29279. sig[sigLen - 5] = 0xff;
  29280. res = 1;
  29281. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29282. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29283. ExpectIntEQ(res, 0);
  29284. sig[sigLen - 5] = 0x00;
  29285. }
  29286. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  29287. b = sig[sigLen - 1];
  29288. sig[sigLen - 1] = 0xff;
  29289. res = 1;
  29290. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29291. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29292. ExpectIntEQ(res, 0);
  29293. sig[sigLen - 1] = b;
  29294. if (sig[sigLen - 4] > 1) {
  29295. /* Index must be less than previous. */
  29296. b = sig[sigLen - 84];
  29297. sig[sigLen - 84] = 0xff;
  29298. res = 1;
  29299. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29300. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29301. ExpectIntEQ(res, 0);
  29302. sig[sigLen - 84] = b;
  29303. }
  29304. /* Mess up commit hash. */
  29305. sig[0] ^= 0x80;
  29306. res = 1;
  29307. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29308. 0);
  29309. ExpectIntEQ(res, 0);
  29310. sig[0] ^= 0x80;
  29311. /* Mess up z. */
  29312. sig[100] ^= 0x80;
  29313. res = 1;
  29314. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29315. 0);
  29316. ExpectIntEQ(res, 0);
  29317. sig[100] ^= 0x80;
  29318. /* Set all indeces to 0. */
  29319. XMEMSET(sig + sigLen - 4, 0, 4);
  29320. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29321. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29322. ExpectIntEQ(res, 0);
  29323. }
  29324. #endif
  29325. wc_dilithium_free(key);
  29326. wc_FreeRng(&rng);
  29327. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29328. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29329. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29330. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29331. #endif
  29332. return EXPECT_RESULT();
  29333. }
  29334. static int test_wc_dilithium_sign_vfy(void)
  29335. {
  29336. EXPECT_DECLS;
  29337. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29338. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT) && \
  29339. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  29340. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29341. dilithium_key* key;
  29342. WC_RNG rng;
  29343. byte msg[64];
  29344. byte* sig = NULL;
  29345. word32 sigLen;
  29346. byte ctx[10];
  29347. int res;
  29348. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29349. ExpectNotNull(key);
  29350. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29351. ExpectNotNull(sig);
  29352. if (key != NULL) {
  29353. XMEMSET(key, 0, sizeof(*key));
  29354. }
  29355. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29356. XMEMSET(msg, 0xAA, sizeof(msg));
  29357. XMEMSET(ctx, 0x01, sizeof(ctx));
  29358. ExpectIntEQ(wc_InitRng(&rng), 0);
  29359. #ifndef WOLFSSL_NO_ML_DSA_44
  29360. ExpectIntEQ(wc_dilithium_init(key), 0);
  29361. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29362. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29363. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29364. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29365. sig, &sigLen, key, &rng), 0);
  29366. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29367. sizeof(msg), &res, key), 0);
  29368. ExpectIntEQ(res, 1);
  29369. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29370. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29371. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29372. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29373. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29374. ExpectIntEQ(res, 1);
  29375. wc_dilithium_free(key);
  29376. #endif
  29377. #ifndef WOLFSSL_NO_ML_DSA_65
  29378. ExpectIntEQ(wc_dilithium_init(key), 0);
  29379. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29380. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29381. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29382. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29383. sig, &sigLen, key, &rng), 0);
  29384. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29385. sizeof(msg), &res, key), 0);
  29386. ExpectIntEQ(res, 1);
  29387. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29388. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29389. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29390. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29391. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29392. ExpectIntEQ(res, 1);
  29393. wc_dilithium_free(key);
  29394. #endif
  29395. #ifndef WOLFSSL_NO_ML_DSA_87
  29396. ExpectIntEQ(wc_dilithium_init(key), 0);
  29397. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29398. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29399. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29400. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29401. sig, &sigLen, key, &rng), 0);
  29402. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29403. sizeof(msg), &res, key), 0);
  29404. ExpectIntEQ(res, 1);
  29405. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29406. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29407. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29408. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29409. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29410. ExpectIntEQ(res, 1);
  29411. wc_dilithium_free(key);
  29412. #endif
  29413. wc_FreeRng(&rng);
  29414. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29415. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29416. #endif
  29417. return EXPECT_RESULT();
  29418. }
  29419. static int test_wc_dilithium_check_key(void)
  29420. {
  29421. EXPECT_DECLS;
  29422. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29423. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  29424. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29425. dilithium_key* checkKey;
  29426. WC_RNG rng;
  29427. byte* privCheckKey = NULL;
  29428. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29429. byte* pubCheckKey = NULL;
  29430. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29431. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  29432. DYNAMIC_TYPE_TMP_BUFFER);
  29433. ExpectNotNull(checkKey);
  29434. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29435. DYNAMIC_TYPE_TMP_BUFFER);
  29436. ExpectNotNull(privCheckKey);
  29437. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29438. DYNAMIC_TYPE_TMP_BUFFER);
  29439. ExpectNotNull(pubCheckKey);
  29440. if (checkKey != NULL) {
  29441. XMEMSET(checkKey, 0, sizeof(*checkKey));
  29442. }
  29443. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29444. ExpectIntEQ(wc_InitRng(&rng), 0);
  29445. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29446. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  29447. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  29448. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29449. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29450. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29451. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29452. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29453. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29454. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29455. #ifndef WOLFSSL_NO_ML_DSA_44
  29456. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29457. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29458. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29459. #else
  29460. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29461. #endif
  29462. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29463. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29464. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29465. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29466. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29467. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29469. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29470. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29471. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29472. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29473. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29474. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29475. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29476. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29477. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29478. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29479. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29480. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29481. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29482. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29483. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29484. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29485. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29486. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29487. /* Modify hash. */
  29488. if (pubCheckKey != NULL) {
  29489. pubCheckKey[0] ^= 0x80;
  29490. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29491. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29492. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29493. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29494. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29495. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29496. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29497. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29498. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29499. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29500. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29501. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29502. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29503. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29504. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29505. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29506. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29507. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29508. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29509. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29510. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29511. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29513. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29514. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29515. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29516. pubCheckKey[0] ^= 0x80;
  29517. /* Modify encoded t1. */
  29518. pubCheckKey[48] ^= 0x80;
  29519. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29520. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29521. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29522. pubCheckKey[48] ^= 0x80;
  29523. }
  29524. wc_dilithium_free(checkKey);
  29525. wc_FreeRng(&rng);
  29526. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29527. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29528. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29529. #endif
  29530. return EXPECT_RESULT();
  29531. }
  29532. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29533. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29534. static const unsigned char dilithium_public_der[] = {
  29535. #ifndef WOLFSSL_NO_ML_DSA_44
  29536. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29537. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29538. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  29539. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  29540. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  29541. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  29542. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  29543. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  29544. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  29545. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  29546. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  29547. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  29548. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  29549. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  29550. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  29551. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  29552. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  29553. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  29554. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  29555. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  29556. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  29557. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  29558. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  29559. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  29560. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  29561. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  29562. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  29563. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  29564. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  29565. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  29566. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  29567. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  29568. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  29569. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  29570. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  29571. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  29572. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  29573. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  29574. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  29575. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  29576. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  29577. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  29578. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  29579. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  29580. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  29581. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  29582. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  29583. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  29584. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  29585. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  29586. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  29587. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  29588. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  29589. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  29590. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  29591. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  29592. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  29593. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  29594. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  29595. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  29596. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  29597. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  29598. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  29599. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  29600. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  29601. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  29602. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  29603. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  29604. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  29605. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  29606. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  29607. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  29608. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  29609. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  29610. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  29611. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  29612. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  29613. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  29614. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  29615. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  29616. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  29617. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  29618. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  29619. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  29620. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  29621. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  29622. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  29623. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  29624. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  29625. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  29626. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  29627. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  29628. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  29629. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  29630. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  29631. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  29632. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  29633. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  29634. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  29635. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  29636. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  29637. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  29638. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  29639. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  29640. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  29641. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  29642. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  29643. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  29644. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  29645. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  29646. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  29647. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  29648. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  29649. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  29650. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  29651. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  29652. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  29653. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  29654. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  29655. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  29656. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  29657. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  29658. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  29659. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  29660. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  29661. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  29662. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  29663. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  29664. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  29665. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  29666. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  29667. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  29668. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  29669. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  29670. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  29671. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  29672. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  29673. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  29674. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  29675. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  29676. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  29677. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  29678. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  29679. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  29680. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  29681. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  29682. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  29683. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  29684. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  29685. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  29686. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  29687. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  29688. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  29689. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  29690. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  29691. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  29692. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  29693. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  29694. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  29695. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  29696. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  29697. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  29698. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  29699. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  29700. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  29701. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  29702. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  29703. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29704. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  29705. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29706. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29707. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  29708. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  29709. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  29710. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  29711. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  29712. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  29713. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  29714. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  29715. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  29716. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  29717. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  29718. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  29719. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  29720. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  29721. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  29722. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  29723. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  29724. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  29725. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  29726. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  29727. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  29728. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  29729. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  29730. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  29731. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  29732. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  29733. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  29734. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  29735. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  29736. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  29737. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  29738. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  29739. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  29740. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  29741. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  29742. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  29743. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  29744. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  29745. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  29746. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  29747. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  29748. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  29749. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  29750. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  29751. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  29752. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  29753. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  29754. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  29755. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  29756. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  29757. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  29758. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  29759. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  29760. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  29761. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  29762. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  29763. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  29764. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  29765. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  29766. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  29767. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  29768. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  29769. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  29770. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  29771. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  29772. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  29773. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  29774. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  29775. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  29776. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  29777. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  29778. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  29779. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  29780. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  29781. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  29782. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  29783. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  29784. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  29785. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  29786. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  29787. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  29788. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  29789. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  29790. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  29791. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  29792. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  29793. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  29794. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  29795. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  29796. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  29797. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  29798. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  29799. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  29800. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  29801. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  29802. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  29803. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  29804. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  29805. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  29806. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  29807. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  29808. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  29809. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  29810. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  29811. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  29812. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  29813. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  29814. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  29815. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  29816. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  29817. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  29818. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  29819. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  29820. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  29821. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  29822. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  29823. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  29824. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  29825. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  29826. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  29827. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  29828. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  29829. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  29830. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  29831. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  29832. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  29833. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  29834. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  29835. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  29836. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  29837. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  29838. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  29839. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  29840. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  29841. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  29842. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  29843. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  29844. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  29845. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  29846. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  29847. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  29848. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  29849. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  29850. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  29851. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  29852. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  29853. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  29854. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  29855. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  29856. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  29857. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  29858. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  29859. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  29860. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  29861. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  29862. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  29863. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  29864. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  29865. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  29866. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  29867. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  29868. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  29869. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  29870. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  29871. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  29872. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  29873. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  29874. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  29875. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  29876. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  29877. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  29878. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  29879. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  29880. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  29881. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  29882. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  29883. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  29884. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  29885. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  29886. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  29887. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  29888. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  29889. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  29890. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  29891. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  29892. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  29893. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  29894. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  29895. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  29896. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  29897. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  29898. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  29899. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  29900. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  29901. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  29902. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  29903. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  29904. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  29905. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  29906. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  29907. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  29908. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  29909. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  29910. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  29911. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  29912. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  29913. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  29914. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  29915. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  29916. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  29917. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  29918. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  29919. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  29920. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  29921. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  29922. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  29923. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  29924. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  29925. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  29926. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  29927. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  29928. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  29929. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  29930. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  29931. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  29932. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  29933. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  29934. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  29935. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  29936. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  29937. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  29938. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  29939. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  29940. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  29941. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  29942. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  29943. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  29944. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  29945. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  29946. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  29947. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  29948. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  29949. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  29950. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  29951. #else
  29952. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29953. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29954. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  29955. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  29956. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  29957. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  29958. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  29959. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  29960. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  29961. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  29962. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  29963. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  29964. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  29965. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  29966. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  29967. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  29968. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  29969. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  29970. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  29971. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  29972. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  29973. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  29974. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  29975. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  29976. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  29977. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  29978. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  29979. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  29980. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  29981. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  29982. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  29983. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  29984. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  29985. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  29986. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  29987. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  29988. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  29989. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  29990. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  29991. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  29992. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  29993. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  29994. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  29995. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  29996. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  29997. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  29998. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  29999. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  30000. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  30001. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  30002. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  30003. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  30004. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  30005. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  30006. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  30007. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  30008. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  30009. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  30010. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  30011. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  30012. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  30013. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  30014. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  30015. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  30016. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  30017. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  30018. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  30019. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  30020. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  30021. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  30022. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  30023. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  30024. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  30025. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  30026. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  30027. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  30028. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  30029. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  30030. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  30031. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  30032. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  30033. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  30034. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  30035. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  30036. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  30037. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  30038. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  30039. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  30040. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  30041. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  30042. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  30043. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  30044. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  30045. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  30046. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  30047. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  30048. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  30049. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  30050. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  30051. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  30052. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  30053. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  30054. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  30055. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  30056. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  30057. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  30058. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  30059. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  30060. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  30061. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  30062. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  30063. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  30064. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  30065. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  30066. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  30067. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  30068. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  30069. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  30070. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  30071. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  30072. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  30073. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  30074. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  30075. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  30076. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  30077. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  30078. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  30079. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  30080. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  30081. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  30082. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  30083. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  30084. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  30085. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  30086. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  30087. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  30088. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  30089. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  30090. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  30091. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  30092. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  30093. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  30094. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  30095. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  30096. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  30097. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  30098. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  30099. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  30100. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  30101. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  30102. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  30103. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  30104. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  30105. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  30106. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  30107. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  30108. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  30109. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  30110. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  30111. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  30112. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  30113. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  30114. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  30115. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  30116. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  30117. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  30118. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  30119. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  30120. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  30121. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  30122. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  30123. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  30124. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  30125. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  30126. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  30127. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  30128. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  30129. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  30130. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  30131. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  30132. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  30133. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  30134. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  30135. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  30136. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  30137. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  30138. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  30139. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  30140. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  30141. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  30142. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  30143. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  30144. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  30145. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  30146. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  30147. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  30148. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  30149. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  30150. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  30151. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  30152. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  30153. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  30154. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  30155. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  30156. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  30157. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  30158. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  30159. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  30160. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  30161. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  30162. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  30163. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  30164. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  30165. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  30166. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  30167. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  30168. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  30169. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  30170. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  30171. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  30172. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  30173. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  30174. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  30175. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  30176. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  30177. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  30178. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  30179. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  30180. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  30181. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  30182. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  30183. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  30184. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  30185. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  30186. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  30187. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  30188. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  30189. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  30190. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  30191. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  30192. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  30193. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  30194. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  30195. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  30196. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  30197. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  30198. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  30199. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  30200. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  30201. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  30202. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  30203. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  30204. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  30205. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  30206. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  30207. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  30208. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  30209. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  30210. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  30211. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  30212. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  30213. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  30214. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  30215. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  30216. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  30217. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  30218. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  30219. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  30220. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  30221. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  30222. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  30223. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  30224. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  30225. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  30226. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  30227. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  30228. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  30229. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  30230. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  30231. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  30232. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  30233. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  30234. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  30235. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  30236. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  30237. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  30238. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  30239. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  30240. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  30241. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  30242. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  30243. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  30244. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  30245. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  30246. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  30247. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  30248. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  30249. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  30250. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  30251. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  30252. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  30253. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  30254. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  30255. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  30256. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  30257. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  30258. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  30259. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  30260. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  30261. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  30262. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  30263. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  30264. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  30265. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  30266. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  30267. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  30268. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  30269. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  30270. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  30271. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  30272. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  30273. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  30274. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  30275. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  30276. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  30277. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  30278. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  30279. #endif
  30280. };
  30281. #endif
  30282. static int test_wc_dilithium_public_der_decode(void)
  30283. {
  30284. EXPECT_DECLS;
  30285. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30286. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  30287. dilithium_key* key;
  30288. word32 idx = 0;
  30289. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30290. ExpectNotNull(key);
  30291. if (key != NULL) {
  30292. XMEMSET(key, 0, sizeof(*key));
  30293. }
  30294. ExpectIntEQ(wc_dilithium_init(key), 0);
  30295. #ifndef WOLFSSL_NO_ML_DSA_44
  30296. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30297. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30298. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30299. #else
  30300. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30301. #endif
  30302. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  30303. (word32)sizeof(dilithium_public_der)), 0);
  30304. wc_dilithium_free(key);
  30305. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30306. #endif
  30307. return EXPECT_RESULT();
  30308. }
  30309. static int test_wc_dilithium_der(void)
  30310. {
  30311. EXPECT_DECLS;
  30312. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30313. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  30314. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30315. #define DILITHIUM_MAX_DER_SIZE 8192
  30316. dilithium_key* key;
  30317. WC_RNG rng;
  30318. byte* der = NULL;
  30319. int len;
  30320. int pubLen;
  30321. int pubDerLen;
  30322. int privDerLen;
  30323. int keyDerLen;
  30324. word32 idx;
  30325. #ifndef WOLFSSL_NO_ML_DSA_44
  30326. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  30327. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 24;
  30328. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 30;
  30329. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 34;
  30330. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30331. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  30332. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 24;
  30333. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 30;
  30334. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 34;
  30335. #else
  30336. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  30337. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 24;
  30338. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 30;
  30339. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 34;
  30340. #endif
  30341. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30342. ExpectNotNull(key);
  30343. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30344. ExpectNotNull(der);
  30345. if (key != NULL) {
  30346. XMEMSET(key, 0, sizeof(*key));
  30347. }
  30348. XMEMSET(&rng, 0, sizeof(WC_RNG));
  30349. ExpectIntEQ(wc_InitRng(&rng), 0);
  30350. ExpectIntEQ(wc_dilithium_init(key), 0);
  30351. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30352. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30353. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30354. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30355. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30356. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30357. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  30358. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30359. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  30360. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30361. #ifndef WOLFSSL_NO_ML_DSA_44
  30362. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30363. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30364. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30365. #else
  30366. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30367. #endif
  30368. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30369. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30370. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30371. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30372. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30373. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30374. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  30375. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  30376. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30377. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  30378. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30379. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  30380. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30381. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  30382. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30383. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  30384. 0), WC_NO_ERR_TRACE(BUFFER_E));
  30385. /* Get length only. */
  30386. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30387. 0), pubLen);
  30388. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30389. 0), pubLen);
  30390. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30391. 1), pubDerLen);
  30392. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30393. 1), pubDerLen);
  30394. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30395. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30396. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30397. 0 ), 0);
  30398. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30399. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30400. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30401. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30402. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30403. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30404. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  30405. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  30406. /* Get length only. */
  30407. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30408. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30409. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  30410. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30411. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  30412. 0 );
  30413. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  30414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30415. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  30416. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30417. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  30418. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30419. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  30420. WC_NO_ERR_TRACE(BUFFER_E));
  30421. /* Get length only. */
  30422. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  30423. keyDerLen);
  30424. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  30425. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30426. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  30427. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30428. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  30429. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30430. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  30431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30432. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  30433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30434. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  30435. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30436. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  30437. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30438. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  30439. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30440. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  30441. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30442. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  30443. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30444. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  30445. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30446. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  30447. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30448. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  30449. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30450. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  30451. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30452. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  30453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30454. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  30455. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30456. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  30457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30458. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  30459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30460. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30461. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  30462. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  30463. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30464. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  30465. idx = 0;
  30466. {
  30467. fprintf(stderr, "\n");
  30468. for (int ii = 0; ii < pubDerLen; ii++) {
  30469. if ((ii % 8) == 0) fprintf(stderr, " ");
  30470. fprintf(stderr, "0x%02x,", der[ii]);
  30471. if ((ii % 8) == 7) fprintf(stderr, "\n");
  30472. else fprintf(stderr, " ");
  30473. }
  30474. }
  30475. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  30476. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  30477. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30478. idx = 0;
  30479. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30480. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30481. keyDerLen);
  30482. idx = 0;
  30483. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30484. wc_dilithium_free(key);
  30485. wc_FreeRng(&rng);
  30486. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30487. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30488. #endif
  30489. return EXPECT_RESULT();
  30490. }
  30491. static int test_wc_dilithium_make_key_from_seed(void)
  30492. {
  30493. EXPECT_DECLS;
  30494. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30495. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30496. dilithium_key* key;
  30497. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30498. #ifndef WOLFSSL_NO_ML_DSA_44
  30499. static const byte seed_44[] = {
  30500. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  30501. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  30502. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  30503. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  30504. };
  30505. static const byte pk_44[] = {
  30506. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30507. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30508. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30509. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30510. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  30511. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  30512. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  30513. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  30514. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  30515. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  30516. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  30517. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  30518. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  30519. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  30520. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  30521. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  30522. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  30523. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  30524. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  30525. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  30526. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  30527. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  30528. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  30529. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  30530. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  30531. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  30532. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  30533. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  30534. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  30535. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  30536. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  30537. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  30538. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  30539. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  30540. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  30541. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  30542. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  30543. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  30544. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  30545. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  30546. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  30547. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  30548. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  30549. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  30550. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  30551. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  30552. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  30553. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  30554. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  30555. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  30556. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  30557. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  30558. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  30559. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  30560. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  30561. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  30562. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  30563. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  30564. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  30565. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  30566. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  30567. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  30568. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  30569. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  30570. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  30571. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  30572. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  30573. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  30574. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  30575. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  30576. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  30577. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  30578. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  30579. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  30580. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  30581. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  30582. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  30583. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  30584. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  30585. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  30586. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  30587. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  30588. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  30589. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  30590. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  30591. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  30592. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  30593. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  30594. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  30595. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  30596. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  30597. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  30598. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  30599. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  30600. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  30601. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  30602. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  30603. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  30604. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  30605. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  30606. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  30607. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  30608. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  30609. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  30610. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  30611. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  30612. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  30613. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  30614. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  30615. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  30616. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  30617. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  30618. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  30619. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  30620. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  30621. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  30622. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  30623. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  30624. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  30625. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  30626. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  30627. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  30628. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  30629. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  30630. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  30631. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  30632. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  30633. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  30634. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  30635. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  30636. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  30637. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  30638. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  30639. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  30640. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  30641. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  30642. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  30643. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  30644. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  30645. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  30646. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  30647. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  30648. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  30649. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  30650. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  30651. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  30652. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  30653. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  30654. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  30655. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  30656. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  30657. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  30658. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  30659. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  30660. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  30661. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  30662. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  30663. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  30664. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  30665. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  30666. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  30667. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  30668. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  30669. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  30670. };
  30671. static const byte sk_44[] = {
  30672. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30673. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30674. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30675. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30676. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  30677. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  30678. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  30679. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  30680. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  30681. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  30682. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  30683. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  30684. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  30685. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  30686. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  30687. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  30688. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  30689. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  30690. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  30691. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  30692. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  30693. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  30694. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  30695. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  30696. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  30697. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  30698. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  30699. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  30700. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  30701. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  30702. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  30703. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  30704. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  30705. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  30706. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  30707. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  30708. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  30709. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  30710. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  30711. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  30712. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  30713. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  30714. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  30715. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  30716. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  30717. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  30718. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  30719. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  30720. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  30721. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  30722. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  30723. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  30724. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  30725. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  30726. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  30727. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  30728. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  30729. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  30730. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  30731. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  30732. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  30733. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  30734. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  30735. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  30736. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  30737. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  30738. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  30739. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  30740. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  30741. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  30742. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  30743. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  30744. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  30745. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  30746. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  30747. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  30748. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  30749. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  30750. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  30751. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  30752. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  30753. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  30754. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  30755. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  30756. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  30757. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  30758. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  30759. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  30760. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  30761. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  30762. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  30763. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  30764. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  30765. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  30766. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  30767. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  30768. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  30769. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  30770. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  30771. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  30772. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  30773. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  30774. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  30775. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  30776. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  30777. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  30778. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  30779. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  30780. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  30781. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  30782. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  30783. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  30784. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  30785. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  30786. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  30787. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  30788. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  30789. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  30790. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  30791. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  30792. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  30793. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  30794. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  30795. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  30796. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  30797. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  30798. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  30799. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  30800. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  30801. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  30802. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  30803. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  30804. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  30805. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  30806. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  30807. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  30808. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  30809. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  30810. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  30811. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  30812. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  30813. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  30814. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  30815. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  30816. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  30817. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  30818. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  30819. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  30820. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  30821. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  30822. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  30823. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  30824. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  30825. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  30826. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  30827. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  30828. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  30829. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  30830. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  30831. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  30832. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  30833. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  30834. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  30835. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  30836. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  30837. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  30838. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  30839. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  30840. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  30841. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  30842. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  30843. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  30844. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  30845. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  30846. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  30847. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  30848. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  30849. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  30850. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  30851. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  30852. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  30853. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  30854. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  30855. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  30856. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  30857. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  30858. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  30859. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  30860. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  30861. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  30862. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  30863. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  30864. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  30865. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  30866. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  30867. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  30868. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  30869. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  30870. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  30871. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  30872. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  30873. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  30874. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  30875. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  30876. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  30877. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  30878. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  30879. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  30880. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  30881. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  30882. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  30883. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  30884. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  30885. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  30886. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  30887. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  30888. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  30889. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  30890. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  30891. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  30892. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  30893. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  30894. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  30895. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  30896. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  30897. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  30898. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  30899. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  30900. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  30901. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  30902. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  30903. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  30904. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  30905. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  30906. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  30907. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  30908. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  30909. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  30910. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  30911. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  30912. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  30913. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  30914. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  30915. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  30916. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  30917. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  30918. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  30919. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  30920. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  30921. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  30922. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  30923. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  30924. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  30925. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  30926. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  30927. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  30928. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  30929. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  30930. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  30931. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  30932. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  30933. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  30934. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  30935. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  30936. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  30937. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  30938. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  30939. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  30940. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  30941. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  30942. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  30943. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  30944. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  30945. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  30946. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  30947. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  30948. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  30949. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  30950. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  30951. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  30952. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  30953. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  30954. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  30955. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  30956. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  30957. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  30958. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  30959. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  30960. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  30961. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  30962. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  30963. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  30964. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  30965. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  30966. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  30967. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  30968. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  30969. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  30970. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  30971. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  30972. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  30973. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  30974. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  30975. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  30976. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  30977. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  30978. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  30979. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  30980. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  30981. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  30982. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  30983. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  30984. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  30985. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  30986. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  30987. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  30988. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  30989. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  30990. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  30991. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  30992. };
  30993. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  30994. #ifndef WOLFSSL_NO_ML_DSA_65
  30995. static const byte seed_65[] = {
  30996. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  30997. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  30998. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  30999. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  31000. };
  31001. static const byte pk_65[] = {
  31002. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31003. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31004. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31005. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31006. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  31007. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  31008. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  31009. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  31010. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  31011. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  31012. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  31013. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  31014. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  31015. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  31016. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  31017. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  31018. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  31019. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  31020. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  31021. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  31022. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  31023. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  31024. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  31025. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  31026. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  31027. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  31028. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  31029. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  31030. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  31031. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  31032. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  31033. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  31034. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  31035. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  31036. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  31037. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  31038. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  31039. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  31040. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  31041. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  31042. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  31043. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  31044. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  31045. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  31046. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  31047. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  31048. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  31049. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  31050. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  31051. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  31052. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  31053. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  31054. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  31055. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  31056. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  31057. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  31058. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  31059. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  31060. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  31061. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  31062. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  31063. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  31064. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  31065. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  31066. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  31067. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  31068. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  31069. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  31070. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  31071. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  31072. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  31073. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  31074. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  31075. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  31076. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  31077. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  31078. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  31079. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  31080. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  31081. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  31082. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  31083. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  31084. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  31085. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  31086. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  31087. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  31088. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  31089. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  31090. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  31091. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  31092. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  31093. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  31094. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  31095. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  31096. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  31097. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  31098. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  31099. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  31100. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  31101. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  31102. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  31103. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  31104. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  31105. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  31106. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  31107. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  31108. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  31109. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  31110. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  31111. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  31112. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  31113. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  31114. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  31115. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  31116. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  31117. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  31118. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  31119. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  31120. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  31121. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  31122. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  31123. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  31124. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  31125. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  31126. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  31127. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  31128. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  31129. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  31130. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  31131. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  31132. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  31133. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  31134. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  31135. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  31136. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  31137. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  31138. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  31139. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  31140. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  31141. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  31142. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  31143. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  31144. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  31145. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  31146. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  31147. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  31148. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  31149. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  31150. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  31151. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  31152. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  31153. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  31154. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  31155. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  31156. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  31157. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  31158. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  31159. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  31160. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  31161. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  31162. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  31163. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  31164. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  31165. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  31166. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  31167. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  31168. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  31169. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  31170. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  31171. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  31172. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  31173. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  31174. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  31175. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  31176. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  31177. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  31178. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  31179. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  31180. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  31181. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  31182. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  31183. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  31184. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  31185. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  31186. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  31187. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  31188. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  31189. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  31190. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  31191. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  31192. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  31193. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  31194. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  31195. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  31196. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  31197. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  31198. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  31199. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  31200. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  31201. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  31202. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  31203. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  31204. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  31205. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  31206. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  31207. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  31208. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  31209. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  31210. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  31211. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  31212. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  31213. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  31214. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  31215. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  31216. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  31217. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  31218. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  31219. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  31220. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  31221. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  31222. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  31223. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  31224. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  31225. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  31226. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  31227. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  31228. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  31229. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  31230. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  31231. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  31232. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  31233. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  31234. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  31235. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  31236. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  31237. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  31238. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  31239. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  31240. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  31241. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  31242. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  31243. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  31244. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  31245. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  31246. };
  31247. static const byte sk_65[] = {
  31248. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31249. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31250. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31251. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31252. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  31253. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  31254. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  31255. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  31256. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  31257. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  31258. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  31259. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  31260. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  31261. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  31262. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  31263. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  31264. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  31265. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  31266. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  31267. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  31268. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  31269. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  31270. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  31271. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  31272. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  31273. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  31274. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  31275. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  31276. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  31277. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  31278. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  31279. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  31280. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  31281. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  31282. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  31283. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  31284. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  31285. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  31286. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  31287. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  31288. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  31289. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  31290. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  31291. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  31292. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  31293. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  31294. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  31295. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  31296. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  31297. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  31298. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  31299. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  31300. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  31301. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  31302. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  31303. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  31304. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  31305. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  31306. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  31307. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  31308. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  31309. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  31310. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  31311. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  31312. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  31313. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  31314. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  31315. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  31316. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  31317. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  31318. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  31319. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  31320. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  31321. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  31322. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  31323. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  31324. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  31325. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  31326. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  31327. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  31328. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  31329. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  31330. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  31331. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  31332. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  31333. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  31334. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  31335. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  31336. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  31337. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  31338. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  31339. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  31340. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  31341. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  31342. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  31343. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  31344. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  31345. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  31346. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  31347. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  31348. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  31349. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  31350. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  31351. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  31352. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  31353. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  31354. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  31355. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  31356. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  31357. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  31358. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  31359. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  31360. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  31361. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  31362. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  31363. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  31364. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  31365. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  31366. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  31367. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  31368. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  31369. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  31370. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  31371. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  31372. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  31373. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  31374. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  31375. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  31376. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  31377. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  31378. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  31379. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  31380. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  31381. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  31382. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  31383. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  31384. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  31385. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  31386. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  31387. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  31388. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  31389. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  31390. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  31391. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  31392. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  31393. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  31394. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  31395. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  31396. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  31397. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  31398. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  31399. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  31400. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  31401. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  31402. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  31403. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  31404. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  31405. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  31406. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  31407. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  31408. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  31409. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  31410. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  31411. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  31412. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  31413. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  31414. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  31415. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  31416. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  31417. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  31418. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  31419. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  31420. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  31421. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  31422. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  31423. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  31424. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  31425. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  31426. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  31427. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  31428. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  31429. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  31430. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  31431. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  31432. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  31433. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  31434. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  31435. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  31436. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  31437. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  31438. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  31439. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  31440. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  31441. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  31442. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  31443. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  31444. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  31445. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  31446. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  31447. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  31448. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  31449. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  31450. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  31451. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  31452. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  31453. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  31454. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  31455. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  31456. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  31457. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  31458. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  31459. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  31460. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  31461. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  31462. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  31463. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  31464. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  31465. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  31466. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  31467. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  31468. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  31469. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  31470. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  31471. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  31472. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  31473. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  31474. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  31475. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  31476. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  31477. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  31478. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  31479. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  31480. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  31481. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  31482. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  31483. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  31484. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  31485. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  31486. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  31487. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  31488. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  31489. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  31490. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  31491. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  31492. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  31493. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  31494. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  31495. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  31496. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  31497. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  31498. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  31499. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  31500. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  31501. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  31502. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  31503. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  31504. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  31505. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  31506. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  31507. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  31508. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  31509. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  31510. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  31511. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  31512. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  31513. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  31514. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  31515. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  31516. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  31517. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  31518. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  31519. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  31520. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  31521. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  31522. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  31523. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  31524. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  31525. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  31526. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  31527. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  31528. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  31529. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  31530. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  31531. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  31532. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  31533. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  31534. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  31535. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  31536. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  31537. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  31538. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  31539. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  31540. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  31541. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  31542. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  31543. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  31544. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  31545. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  31546. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  31547. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  31548. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  31549. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  31550. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  31551. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  31552. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  31553. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  31554. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  31555. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  31556. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  31557. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  31558. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  31559. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  31560. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  31561. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  31562. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  31563. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  31564. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  31565. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  31566. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  31567. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  31568. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  31569. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  31570. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  31571. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  31572. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  31573. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  31574. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  31575. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  31576. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  31577. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  31578. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  31579. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  31580. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  31581. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  31582. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  31583. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  31584. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  31585. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  31586. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  31587. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  31588. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  31589. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  31590. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  31591. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  31592. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  31593. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  31594. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  31595. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  31596. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  31597. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  31598. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  31599. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  31600. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  31601. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  31602. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  31603. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  31604. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  31605. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  31606. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  31607. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  31608. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  31609. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  31610. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  31611. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  31612. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  31613. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  31614. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  31615. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  31616. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  31617. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  31618. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  31619. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  31620. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  31621. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  31622. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  31623. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  31624. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  31625. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  31626. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  31627. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  31628. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  31629. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  31630. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  31631. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  31632. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  31633. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  31634. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  31635. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  31636. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  31637. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  31638. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  31639. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  31640. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  31641. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  31642. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  31643. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  31644. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  31645. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  31646. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  31647. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  31648. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  31649. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  31650. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  31651. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  31652. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  31653. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  31654. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  31655. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  31656. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  31657. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  31658. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  31659. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  31660. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  31661. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  31662. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  31663. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  31664. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  31665. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  31666. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  31667. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  31668. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  31669. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  31670. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  31671. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  31672. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  31673. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  31674. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  31675. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  31676. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  31677. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  31678. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  31679. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  31680. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  31681. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  31682. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  31683. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  31684. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  31685. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  31686. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  31687. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  31688. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  31689. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  31690. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  31691. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  31692. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  31693. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  31694. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  31695. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  31696. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  31697. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  31698. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  31699. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  31700. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  31701. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  31702. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  31703. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  31704. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  31705. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  31706. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  31707. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  31708. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  31709. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  31710. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  31711. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  31712. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  31713. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  31714. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  31715. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  31716. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  31717. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  31718. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  31719. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  31720. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  31721. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  31722. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  31723. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  31724. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  31725. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  31726. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  31727. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  31728. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  31729. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  31730. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  31731. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  31732. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  31733. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  31734. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  31735. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  31736. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  31737. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  31738. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  31739. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  31740. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  31741. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  31742. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  31743. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  31744. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  31745. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  31746. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  31747. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  31748. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  31749. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  31750. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  31751. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  31752. };
  31753. #endif /* WOLFSSL_NO_ML_DSA_65 */
  31754. #ifndef WOLFSSL_NO_ML_DSA_87
  31755. static const byte seed_87[] = {
  31756. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  31757. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  31758. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  31759. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  31760. };
  31761. static const byte pk_87[] = {
  31762. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31763. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31764. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31765. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31766. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  31767. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  31768. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  31769. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  31770. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  31771. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  31772. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  31773. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  31774. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  31775. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  31776. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  31777. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  31778. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  31779. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  31780. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  31781. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  31782. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  31783. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  31784. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  31785. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  31786. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  31787. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  31788. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  31789. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  31790. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  31791. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  31792. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  31793. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  31794. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  31795. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  31796. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  31797. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  31798. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  31799. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  31800. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  31801. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  31802. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  31803. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  31804. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  31805. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  31806. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  31807. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  31808. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  31809. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  31810. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  31811. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  31812. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  31813. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  31814. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  31815. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  31816. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  31817. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  31818. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  31819. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  31820. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  31821. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  31822. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  31823. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  31824. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  31825. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  31826. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  31827. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  31828. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  31829. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  31830. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  31831. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  31832. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  31833. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  31834. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  31835. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  31836. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  31837. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  31838. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  31839. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  31840. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  31841. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  31842. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  31843. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  31844. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  31845. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  31846. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  31847. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  31848. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  31849. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  31850. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  31851. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  31852. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  31853. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  31854. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  31855. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  31856. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  31857. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  31858. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  31859. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  31860. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  31861. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  31862. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  31863. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  31864. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  31865. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  31866. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  31867. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  31868. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  31869. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  31870. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  31871. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  31872. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  31873. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  31874. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  31875. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  31876. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  31877. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  31878. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  31879. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  31880. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  31881. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  31882. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  31883. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  31884. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  31885. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  31886. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  31887. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  31888. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  31889. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  31890. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  31891. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  31892. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  31893. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  31894. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  31895. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  31896. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  31897. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  31898. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  31899. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  31900. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  31901. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  31902. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  31903. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  31904. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  31905. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  31906. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  31907. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  31908. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  31909. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  31910. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  31911. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  31912. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  31913. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  31914. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  31915. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  31916. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  31917. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  31918. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  31919. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  31920. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  31921. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  31922. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  31923. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  31924. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  31925. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  31926. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  31927. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  31928. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  31929. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  31930. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  31931. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  31932. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  31933. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  31934. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  31935. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  31936. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  31937. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  31938. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  31939. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  31940. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  31941. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  31942. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  31943. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  31944. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  31945. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  31946. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  31947. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  31948. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  31949. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  31950. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  31951. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  31952. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  31953. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  31954. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  31955. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  31956. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  31957. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  31958. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  31959. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  31960. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  31961. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  31962. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  31963. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  31964. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  31965. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  31966. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  31967. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  31968. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  31969. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  31970. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  31971. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  31972. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  31973. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  31974. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  31975. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  31976. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  31977. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  31978. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  31979. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  31980. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  31981. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  31982. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  31983. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  31984. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  31985. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  31986. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  31987. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  31988. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  31989. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  31990. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  31991. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  31992. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  31993. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  31994. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  31995. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  31996. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  31997. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  31998. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  31999. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  32000. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  32001. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  32002. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  32003. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  32004. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  32005. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  32006. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  32007. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  32008. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  32009. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  32010. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  32011. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  32012. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  32013. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  32014. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  32015. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  32016. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  32017. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  32018. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  32019. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  32020. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  32021. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  32022. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  32023. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  32024. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  32025. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  32026. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  32027. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  32028. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  32029. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  32030. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  32031. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  32032. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  32033. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  32034. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  32035. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  32036. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  32037. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  32038. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  32039. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  32040. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  32041. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  32042. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  32043. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  32044. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  32045. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  32046. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  32047. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  32048. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  32049. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  32050. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  32051. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  32052. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  32053. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  32054. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  32055. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  32056. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  32057. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  32058. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  32059. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  32060. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  32061. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  32062. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  32063. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  32064. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  32065. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  32066. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  32067. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  32068. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  32069. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  32070. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  32071. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  32072. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  32073. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  32074. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  32075. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  32076. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  32077. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  32078. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  32079. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  32080. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  32081. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  32082. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  32083. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  32084. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  32085. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  32086. };
  32087. static const byte sk_87[] = {
  32088. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32089. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32090. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32091. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32092. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  32093. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  32094. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  32095. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  32096. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  32097. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  32098. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  32099. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  32100. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  32101. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  32102. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  32103. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  32104. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  32105. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  32106. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  32107. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  32108. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  32109. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  32110. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  32111. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  32112. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  32113. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  32114. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  32115. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  32116. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  32117. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  32118. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  32119. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  32120. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  32121. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  32122. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  32123. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  32124. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  32125. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  32126. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  32127. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  32128. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  32129. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  32130. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  32131. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  32132. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  32133. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  32134. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  32135. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  32136. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  32137. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  32138. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  32139. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  32140. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  32141. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  32142. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  32143. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  32144. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  32145. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  32146. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  32147. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  32148. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  32149. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  32150. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  32151. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  32152. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  32153. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  32154. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  32155. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  32156. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  32157. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  32158. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  32159. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  32160. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  32161. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  32162. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  32163. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  32164. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  32165. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  32166. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  32167. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  32168. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  32169. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  32170. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  32171. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  32172. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  32173. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  32174. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  32175. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  32176. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  32177. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  32178. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  32179. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  32180. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  32181. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  32182. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  32183. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  32184. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  32185. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  32186. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  32187. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  32188. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  32189. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  32190. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  32191. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  32192. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  32193. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  32194. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  32195. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  32196. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  32197. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  32198. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  32199. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  32200. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  32201. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  32202. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  32203. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  32204. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  32205. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  32206. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  32207. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  32208. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  32209. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  32210. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  32211. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  32212. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  32213. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  32214. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  32215. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  32216. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  32217. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  32218. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  32219. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  32220. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  32221. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  32222. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  32223. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  32224. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  32225. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  32226. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  32227. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  32228. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  32229. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  32230. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  32231. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  32232. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  32233. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  32234. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  32235. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  32236. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  32237. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  32238. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  32239. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  32240. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  32241. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  32242. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  32243. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  32244. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  32245. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  32246. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  32247. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  32248. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  32249. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  32250. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  32251. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  32252. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  32253. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  32254. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  32255. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  32256. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  32257. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  32258. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  32259. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  32260. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  32261. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  32262. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  32263. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  32264. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  32265. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  32266. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  32267. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  32268. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  32269. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  32270. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  32271. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  32272. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  32273. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  32274. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  32275. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  32276. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  32277. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  32278. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  32279. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  32280. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  32281. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  32282. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  32283. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  32284. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  32285. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  32286. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  32287. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  32288. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  32289. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  32290. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  32291. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  32292. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  32293. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  32294. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  32295. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  32296. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  32297. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  32298. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  32299. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  32300. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  32301. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  32302. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  32303. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  32304. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  32305. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  32306. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  32307. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  32308. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  32309. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  32310. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  32311. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  32312. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  32313. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  32314. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  32315. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  32316. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  32317. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  32318. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  32319. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  32320. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  32321. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  32322. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  32323. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  32324. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  32325. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  32326. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  32327. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  32328. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  32329. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  32330. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  32331. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  32332. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  32333. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  32334. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  32335. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  32336. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  32337. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  32338. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  32339. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  32340. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  32341. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  32342. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  32343. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  32344. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  32345. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  32346. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  32347. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  32348. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  32349. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  32350. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  32351. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  32352. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  32353. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  32354. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  32355. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  32356. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  32357. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  32358. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  32359. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  32360. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  32361. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  32362. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  32363. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  32364. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  32365. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  32366. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  32367. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  32368. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  32369. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  32370. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  32371. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  32372. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  32373. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  32374. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  32375. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  32376. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  32377. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  32378. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  32379. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  32380. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  32381. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  32382. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  32383. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  32384. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  32385. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  32386. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  32387. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  32388. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  32389. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  32390. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  32391. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  32392. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  32393. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  32394. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  32395. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  32396. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  32397. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  32398. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  32399. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  32400. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  32401. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  32402. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  32403. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  32404. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  32405. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  32406. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  32407. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  32408. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  32409. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  32410. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  32411. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  32412. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  32413. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  32414. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  32415. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  32416. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  32417. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  32418. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  32419. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  32420. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  32421. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  32422. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  32423. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  32424. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  32425. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  32426. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  32427. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  32428. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  32429. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  32430. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  32431. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  32432. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  32433. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  32434. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  32435. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  32436. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  32437. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  32438. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  32439. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  32440. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  32441. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  32442. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  32443. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  32444. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  32445. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  32446. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  32447. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  32448. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  32449. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  32450. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  32451. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  32452. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  32453. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  32454. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  32455. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  32456. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  32457. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  32458. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  32459. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  32460. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  32461. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  32462. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  32463. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  32464. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  32465. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  32466. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  32467. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  32468. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  32469. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  32470. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  32471. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  32472. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  32473. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  32474. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  32475. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  32476. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  32477. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  32478. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  32479. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  32480. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  32481. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  32482. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  32483. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  32484. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  32485. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  32486. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  32487. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  32488. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  32489. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  32490. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  32491. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  32492. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  32493. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  32494. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  32495. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  32496. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  32497. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  32498. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  32499. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  32500. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  32501. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  32502. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  32503. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  32504. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  32505. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  32506. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  32507. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  32508. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  32509. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  32510. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  32511. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  32512. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  32513. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  32514. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  32515. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  32516. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  32517. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  32518. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  32519. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  32520. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  32521. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  32522. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  32523. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  32524. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  32525. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  32526. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  32527. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  32528. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  32529. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  32530. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  32531. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  32532. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  32533. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  32534. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  32535. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  32536. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  32537. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  32538. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  32539. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  32540. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  32541. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  32542. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  32543. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  32544. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  32545. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  32546. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  32547. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  32548. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  32549. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  32550. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  32551. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  32552. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  32553. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  32554. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  32555. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  32556. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  32557. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  32558. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  32559. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  32560. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  32561. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  32562. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  32563. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  32564. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  32565. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  32566. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  32567. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  32568. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  32569. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  32570. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  32571. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  32572. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  32573. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  32574. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  32575. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  32576. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  32577. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  32578. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  32579. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  32580. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  32581. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  32582. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  32583. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  32584. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  32585. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  32586. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  32587. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  32588. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  32589. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  32590. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  32591. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  32592. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  32593. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  32594. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  32595. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  32596. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  32597. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  32598. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  32599. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  32600. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  32601. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  32602. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  32603. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  32604. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  32605. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  32606. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  32607. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  32608. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  32609. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  32610. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  32611. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  32612. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  32613. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  32614. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  32615. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  32616. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  32617. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  32618. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  32619. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  32620. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  32621. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  32622. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  32623. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  32624. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  32625. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  32626. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  32627. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  32628. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  32629. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  32630. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  32631. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  32632. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  32633. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  32634. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  32635. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  32636. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  32637. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  32638. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  32639. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  32640. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  32641. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  32642. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  32643. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  32644. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  32645. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  32646. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  32647. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  32648. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  32649. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  32650. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  32651. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  32652. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  32653. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  32654. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  32655. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  32656. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  32657. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  32658. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  32659. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  32660. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  32661. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  32662. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  32663. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  32664. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  32665. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  32666. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  32667. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  32668. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  32669. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  32670. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  32671. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  32672. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  32673. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  32674. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  32675. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  32676. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  32677. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  32678. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  32679. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  32680. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  32681. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  32682. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  32683. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  32684. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  32685. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  32686. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  32687. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  32688. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  32689. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  32690. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  32691. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  32692. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  32693. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  32694. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  32695. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  32696. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  32697. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  32698. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  32699. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  32700. };
  32701. #endif /* WOLFSSL_NO_ML_DSA_87 */
  32702. #else
  32703. #ifndef WOLFSSL_NO_ML_DSA_44
  32704. static const byte seed_44[] = {
  32705. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  32706. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  32707. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  32708. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  32709. };
  32710. static const byte pk_44[] = {
  32711. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32712. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32713. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32714. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32715. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  32716. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  32717. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  32718. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  32719. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  32720. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  32721. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  32722. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  32723. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  32724. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  32725. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  32726. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  32727. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  32728. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  32729. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  32730. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  32731. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  32732. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  32733. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  32734. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  32735. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  32736. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  32737. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  32738. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  32739. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  32740. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  32741. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  32742. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  32743. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  32744. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  32745. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  32746. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  32747. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  32748. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  32749. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  32750. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  32751. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  32752. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  32753. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  32754. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  32755. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  32756. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  32757. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  32758. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  32759. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  32760. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  32761. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  32762. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  32763. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  32764. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  32765. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  32766. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  32767. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  32768. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  32769. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  32770. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  32771. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  32772. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  32773. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  32774. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  32775. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  32776. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  32777. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  32778. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  32779. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  32780. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  32781. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  32782. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  32783. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  32784. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  32785. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  32786. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  32787. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  32788. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  32789. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  32790. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  32791. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  32792. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  32793. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  32794. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  32795. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  32796. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  32797. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  32798. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  32799. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  32800. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  32801. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  32802. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  32803. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  32804. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  32805. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  32806. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  32807. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  32808. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  32809. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  32810. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  32811. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  32812. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  32813. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  32814. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  32815. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  32816. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  32817. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  32818. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  32819. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  32820. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  32821. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  32822. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  32823. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  32824. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  32825. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  32826. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  32827. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  32828. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  32829. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  32830. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  32831. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  32832. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  32833. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  32834. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  32835. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  32836. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  32837. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  32838. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  32839. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  32840. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  32841. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  32842. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  32843. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  32844. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  32845. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  32846. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  32847. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  32848. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  32849. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  32850. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  32851. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  32852. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  32853. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  32854. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  32855. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  32856. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  32857. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  32858. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  32859. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  32860. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  32861. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  32862. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  32863. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  32864. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  32865. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  32866. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  32867. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  32868. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  32869. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  32870. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  32871. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  32872. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  32873. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  32874. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  32875. };
  32876. static const byte sk_44[] = {
  32877. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32878. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32879. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32880. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32881. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  32882. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  32883. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  32884. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  32885. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  32886. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  32887. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  32888. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  32889. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  32890. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  32891. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  32892. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  32893. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  32894. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  32895. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  32896. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  32897. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  32898. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  32899. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  32900. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  32901. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  32902. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  32903. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  32904. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  32905. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  32906. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  32907. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  32908. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  32909. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  32910. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  32911. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  32912. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  32913. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  32914. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  32915. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  32916. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  32917. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  32918. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  32919. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  32920. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  32921. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  32922. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  32923. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  32924. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  32925. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  32926. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  32927. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  32928. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  32929. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  32930. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  32931. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  32932. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  32933. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  32934. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  32935. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  32936. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  32937. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  32938. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  32939. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  32940. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  32941. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  32942. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  32943. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  32944. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  32945. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  32946. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  32947. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  32948. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  32949. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  32950. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  32951. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  32952. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  32953. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  32954. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  32955. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  32956. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  32957. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  32958. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  32959. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  32960. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  32961. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  32962. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  32963. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  32964. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  32965. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  32966. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  32967. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  32968. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  32969. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  32970. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  32971. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  32972. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  32973. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  32974. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  32975. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  32976. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  32977. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  32978. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  32979. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  32980. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  32981. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  32982. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  32983. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  32984. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  32985. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  32986. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  32987. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  32988. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  32989. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  32990. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  32991. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  32992. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  32993. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  32994. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  32995. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  32996. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  32997. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  32998. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  32999. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  33000. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  33001. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  33002. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  33003. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  33004. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  33005. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  33006. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  33007. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  33008. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  33009. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  33010. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  33011. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  33012. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  33013. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  33014. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  33015. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  33016. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  33017. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  33018. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  33019. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  33020. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  33021. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  33022. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  33023. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  33024. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  33025. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  33026. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  33027. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  33028. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  33029. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  33030. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  33031. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  33032. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  33033. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  33034. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  33035. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  33036. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  33037. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  33038. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  33039. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  33040. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  33041. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  33042. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  33043. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  33044. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  33045. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  33046. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  33047. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  33048. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  33049. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  33050. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  33051. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  33052. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  33053. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  33054. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  33055. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  33056. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  33057. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  33058. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  33059. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  33060. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  33061. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  33062. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  33063. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  33064. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  33065. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  33066. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  33067. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  33068. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  33069. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  33070. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  33071. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  33072. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  33073. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  33074. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  33075. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  33076. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  33077. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  33078. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  33079. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  33080. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  33081. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  33082. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  33083. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  33084. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  33085. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  33086. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  33087. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  33088. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  33089. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  33090. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  33091. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  33092. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  33093. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  33094. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  33095. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  33096. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  33097. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  33098. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  33099. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  33100. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  33101. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  33102. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  33103. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  33104. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  33105. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  33106. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  33107. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  33108. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  33109. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  33110. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  33111. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  33112. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  33113. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  33114. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  33115. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  33116. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  33117. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  33118. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  33119. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  33120. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  33121. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  33122. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  33123. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  33124. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  33125. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  33126. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  33127. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  33128. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  33129. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  33130. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  33131. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  33132. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  33133. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  33134. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  33135. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  33136. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  33137. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  33138. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  33139. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  33140. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  33141. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  33142. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  33143. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  33144. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  33145. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  33146. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  33147. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  33148. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  33149. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  33150. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  33151. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  33152. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  33153. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  33154. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  33155. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  33156. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  33157. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  33158. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  33159. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  33160. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  33161. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  33162. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  33163. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  33164. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  33165. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  33166. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  33167. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  33168. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  33169. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  33170. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  33171. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  33172. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  33173. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  33174. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  33175. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  33176. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  33177. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  33178. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  33179. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  33180. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  33181. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  33182. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  33183. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  33184. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  33185. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  33186. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  33187. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  33188. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  33189. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  33190. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  33191. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  33192. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  33193. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  33194. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  33195. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  33196. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  33197. };
  33198. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  33199. #ifndef WOLFSSL_NO_ML_DSA_65
  33200. static const byte seed_65[] = {
  33201. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  33202. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  33203. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  33204. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  33205. };
  33206. static const byte pk_65[] = {
  33207. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33208. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33209. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33210. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33211. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  33212. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  33213. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  33214. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  33215. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  33216. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  33217. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  33218. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  33219. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  33220. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  33221. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  33222. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  33223. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  33224. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  33225. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  33226. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  33227. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  33228. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  33229. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  33230. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  33231. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  33232. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  33233. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  33234. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  33235. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  33236. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  33237. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  33238. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  33239. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  33240. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  33241. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  33242. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  33243. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  33244. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  33245. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  33246. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  33247. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  33248. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  33249. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  33250. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  33251. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  33252. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  33253. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  33254. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  33255. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  33256. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  33257. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  33258. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  33259. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  33260. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  33261. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  33262. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  33263. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  33264. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  33265. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  33266. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  33267. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  33268. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  33269. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  33270. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  33271. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  33272. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  33273. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  33274. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  33275. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  33276. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  33277. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  33278. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  33279. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  33280. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  33281. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  33282. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  33283. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  33284. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  33285. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  33286. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  33287. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  33288. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  33289. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  33290. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  33291. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  33292. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  33293. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  33294. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  33295. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  33296. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  33297. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  33298. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  33299. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  33300. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  33301. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  33302. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  33303. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  33304. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  33305. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  33306. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  33307. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  33308. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  33309. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  33310. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  33311. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  33312. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  33313. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  33314. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  33315. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  33316. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  33317. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  33318. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  33319. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  33320. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  33321. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  33322. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  33323. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  33324. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  33325. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  33326. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  33327. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  33328. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  33329. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  33330. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  33331. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  33332. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  33333. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  33334. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  33335. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  33336. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  33337. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  33338. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  33339. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  33340. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  33341. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  33342. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  33343. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  33344. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  33345. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  33346. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  33347. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  33348. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  33349. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  33350. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  33351. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  33352. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  33353. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  33354. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  33355. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  33356. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  33357. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  33358. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  33359. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  33360. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  33361. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  33362. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  33363. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  33364. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  33365. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  33366. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  33367. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  33368. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  33369. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  33370. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  33371. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  33372. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  33373. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  33374. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  33375. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  33376. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  33377. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  33378. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  33379. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  33380. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  33381. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  33382. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  33383. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  33384. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  33385. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  33386. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  33387. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  33388. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  33389. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  33390. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  33391. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  33392. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  33393. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  33394. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  33395. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  33396. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  33397. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  33398. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  33399. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  33400. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  33401. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  33402. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  33403. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  33404. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  33405. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  33406. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  33407. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  33408. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  33409. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  33410. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  33411. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  33412. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  33413. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  33414. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  33415. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  33416. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  33417. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  33418. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  33419. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  33420. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  33421. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  33422. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  33423. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  33424. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  33425. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  33426. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  33427. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  33428. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  33429. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  33430. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  33431. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  33432. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  33433. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  33434. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  33435. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  33436. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  33437. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  33438. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  33439. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  33440. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  33441. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  33442. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  33443. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  33444. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  33445. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  33446. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  33447. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  33448. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  33449. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  33450. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  33451. };
  33452. static const byte sk_65[] = {
  33453. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33454. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33455. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33456. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33457. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  33458. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  33459. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  33460. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  33461. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  33462. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  33463. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  33464. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  33465. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  33466. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  33467. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  33468. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  33469. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  33470. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  33471. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  33472. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  33473. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  33474. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  33475. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  33476. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  33477. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  33478. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  33479. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  33480. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  33481. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  33482. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  33483. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  33484. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  33485. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  33486. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  33487. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  33488. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  33489. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  33490. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  33491. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  33492. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  33493. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  33494. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  33495. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  33496. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  33497. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  33498. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  33499. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  33500. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  33501. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  33502. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  33503. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  33504. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  33505. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  33506. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  33507. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  33508. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  33509. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  33510. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  33511. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  33512. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  33513. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  33514. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  33515. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  33516. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  33517. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  33518. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  33519. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  33520. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  33521. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  33522. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  33523. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  33524. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  33525. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  33526. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  33527. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  33528. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  33529. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  33530. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  33531. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  33532. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  33533. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  33534. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  33535. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  33536. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  33537. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  33538. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  33539. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  33540. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  33541. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  33542. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  33543. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  33544. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  33545. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  33546. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  33547. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  33548. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  33549. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  33550. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  33551. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  33552. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  33553. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  33554. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  33555. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  33556. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  33557. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  33558. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  33559. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  33560. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  33561. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  33562. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  33563. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  33564. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  33565. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  33566. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  33567. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  33568. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  33569. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  33570. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  33571. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  33572. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  33573. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  33574. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  33575. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  33576. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  33577. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  33578. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  33579. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  33580. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  33581. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  33582. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  33583. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  33584. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  33585. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  33586. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  33587. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  33588. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  33589. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  33590. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  33591. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  33592. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  33593. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  33594. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  33595. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  33596. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  33597. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  33598. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  33599. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  33600. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  33601. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  33602. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  33603. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  33604. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  33605. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  33606. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  33607. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  33608. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  33609. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  33610. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  33611. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  33612. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  33613. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  33614. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  33615. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  33616. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  33617. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  33618. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  33619. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  33620. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  33621. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  33622. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  33623. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  33624. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  33625. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  33626. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  33627. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  33628. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  33629. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  33630. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  33631. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  33632. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  33633. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  33634. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  33635. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  33636. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  33637. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  33638. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  33639. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  33640. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  33641. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  33642. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  33643. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  33644. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  33645. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  33646. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  33647. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  33648. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  33649. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  33650. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  33651. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  33652. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  33653. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  33654. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  33655. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  33656. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  33657. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  33658. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  33659. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  33660. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  33661. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  33662. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  33663. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  33664. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  33665. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  33666. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  33667. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  33668. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  33669. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  33670. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  33671. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  33672. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  33673. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  33674. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  33675. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  33676. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  33677. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  33678. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  33679. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  33680. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  33681. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  33682. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  33683. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  33684. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  33685. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  33686. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  33687. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  33688. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  33689. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  33690. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  33691. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  33692. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  33693. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  33694. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  33695. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  33696. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  33697. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  33698. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  33699. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  33700. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  33701. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  33702. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  33703. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  33704. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  33705. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  33706. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  33707. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  33708. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  33709. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  33710. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  33711. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  33712. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  33713. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  33714. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  33715. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  33716. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  33717. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  33718. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  33719. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  33720. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  33721. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  33722. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  33723. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  33724. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  33725. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  33726. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  33727. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  33728. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  33729. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  33730. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  33731. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  33732. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  33733. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  33734. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  33735. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  33736. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  33737. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  33738. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  33739. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  33740. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  33741. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  33742. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  33743. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  33744. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  33745. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  33746. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  33747. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  33748. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  33749. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  33750. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  33751. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  33752. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  33753. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  33754. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  33755. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  33756. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  33757. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  33758. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  33759. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  33760. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  33761. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  33762. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  33763. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  33764. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  33765. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  33766. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  33767. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  33768. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  33769. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  33770. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  33771. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  33772. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  33773. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  33774. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  33775. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  33776. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  33777. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  33778. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  33779. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  33780. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  33781. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  33782. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  33783. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  33784. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  33785. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  33786. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  33787. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  33788. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  33789. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  33790. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  33791. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  33792. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  33793. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  33794. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  33795. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  33796. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  33797. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  33798. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  33799. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  33800. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  33801. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  33802. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  33803. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  33804. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  33805. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  33806. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  33807. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  33808. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  33809. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  33810. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  33811. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  33812. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  33813. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  33814. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  33815. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  33816. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  33817. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  33818. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  33819. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  33820. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  33821. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  33822. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  33823. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  33824. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  33825. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  33826. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  33827. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  33828. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  33829. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  33830. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  33831. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  33832. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  33833. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  33834. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  33835. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  33836. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  33837. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  33838. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  33839. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  33840. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  33841. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  33842. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  33843. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  33844. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  33845. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  33846. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  33847. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  33848. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  33849. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  33850. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  33851. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  33852. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  33853. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  33854. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  33855. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  33856. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  33857. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  33858. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  33859. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  33860. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  33861. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  33862. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  33863. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  33864. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  33865. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  33866. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  33867. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  33868. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  33869. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  33870. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  33871. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  33872. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  33873. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  33874. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  33875. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  33876. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  33877. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  33878. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  33879. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  33880. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  33881. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  33882. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  33883. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  33884. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  33885. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  33886. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  33887. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  33888. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  33889. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  33890. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  33891. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  33892. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  33893. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  33894. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  33895. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  33896. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  33897. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  33898. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  33899. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  33900. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  33901. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  33902. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  33903. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  33904. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  33905. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  33906. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  33907. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  33908. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  33909. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  33910. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  33911. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  33912. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  33913. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  33914. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  33915. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  33916. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  33917. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  33918. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  33919. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  33920. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  33921. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  33922. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  33923. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  33924. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  33925. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  33926. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  33927. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  33928. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  33929. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  33930. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  33931. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  33932. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  33933. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  33934. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  33935. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  33936. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  33937. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  33938. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  33939. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  33940. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  33941. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  33942. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  33943. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  33944. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  33945. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  33946. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  33947. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  33948. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  33949. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  33950. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  33951. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  33952. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  33953. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  33954. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  33955. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  33956. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  33957. };
  33958. #endif /* WOLFSSL_NO_ML_DSA_65 */
  33959. #ifndef WOLFSSL_NO_ML_DSA_87
  33960. static const byte seed_87[] = {
  33961. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  33962. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  33963. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  33964. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  33965. };
  33966. static const byte pk_87[] = {
  33967. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  33968. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  33969. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  33970. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  33971. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  33972. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  33973. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  33974. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  33975. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  33976. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  33977. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  33978. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  33979. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  33980. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  33981. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  33982. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  33983. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  33984. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  33985. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  33986. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  33987. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  33988. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  33989. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  33990. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  33991. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  33992. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  33993. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  33994. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  33995. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  33996. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  33997. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  33998. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  33999. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  34000. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  34001. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  34002. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  34003. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  34004. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  34005. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  34006. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  34007. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  34008. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  34009. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  34010. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  34011. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  34012. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  34013. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  34014. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  34015. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  34016. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  34017. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  34018. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  34019. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  34020. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  34021. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  34022. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  34023. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  34024. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  34025. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  34026. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  34027. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  34028. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  34029. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  34030. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  34031. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  34032. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  34033. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  34034. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  34035. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  34036. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  34037. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  34038. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  34039. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  34040. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  34041. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  34042. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  34043. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  34044. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  34045. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  34046. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  34047. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  34048. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  34049. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  34050. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  34051. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  34052. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  34053. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  34054. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  34055. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  34056. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  34057. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  34058. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  34059. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  34060. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  34061. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  34062. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  34063. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  34064. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  34065. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  34066. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  34067. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  34068. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  34069. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  34070. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  34071. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  34072. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  34073. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  34074. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  34075. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  34076. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  34077. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  34078. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  34079. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  34080. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  34081. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  34082. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  34083. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  34084. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  34085. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  34086. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  34087. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  34088. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  34089. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  34090. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  34091. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  34092. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  34093. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  34094. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  34095. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  34096. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  34097. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  34098. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  34099. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  34100. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  34101. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  34102. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  34103. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  34104. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  34105. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  34106. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  34107. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  34108. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  34109. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  34110. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  34111. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  34112. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  34113. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  34114. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  34115. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  34116. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  34117. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  34118. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  34119. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  34120. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  34121. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  34122. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  34123. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  34124. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  34125. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  34126. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  34127. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  34128. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  34129. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  34130. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  34131. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  34132. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  34133. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  34134. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  34135. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  34136. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  34137. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  34138. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  34139. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  34140. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  34141. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  34142. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  34143. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  34144. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  34145. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  34146. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  34147. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  34148. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  34149. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  34150. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  34151. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  34152. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  34153. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  34154. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  34155. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  34156. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  34157. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  34158. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  34159. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  34160. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  34161. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  34162. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  34163. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  34164. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  34165. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  34166. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  34167. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  34168. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  34169. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  34170. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  34171. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  34172. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  34173. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  34174. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  34175. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  34176. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  34177. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  34178. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  34179. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  34180. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  34181. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  34182. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  34183. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  34184. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  34185. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  34186. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  34187. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  34188. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  34189. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  34190. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  34191. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  34192. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  34193. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  34194. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  34195. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  34196. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  34197. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  34198. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  34199. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  34200. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  34201. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  34202. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  34203. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  34204. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  34205. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  34206. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  34207. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  34208. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  34209. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  34210. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  34211. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  34212. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  34213. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  34214. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  34215. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  34216. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  34217. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  34218. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  34219. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  34220. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  34221. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  34222. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  34223. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  34224. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  34225. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  34226. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  34227. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  34228. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  34229. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  34230. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  34231. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  34232. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  34233. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  34234. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  34235. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  34236. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  34237. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  34238. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  34239. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  34240. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  34241. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  34242. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  34243. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  34244. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  34245. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  34246. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  34247. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  34248. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  34249. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  34250. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  34251. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  34252. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  34253. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  34254. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  34255. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  34256. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  34257. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  34258. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  34259. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  34260. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  34261. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  34262. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  34263. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  34264. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  34265. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  34266. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  34267. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  34268. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  34269. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  34270. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  34271. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  34272. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  34273. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  34274. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  34275. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  34276. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  34277. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  34278. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  34279. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  34280. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  34281. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  34282. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  34283. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  34284. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  34285. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  34286. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  34287. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  34288. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  34289. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  34290. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  34291. };
  34292. static const byte sk_87[] = {
  34293. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  34294. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  34295. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  34296. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  34297. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  34298. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  34299. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  34300. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  34301. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  34302. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  34303. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  34304. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  34305. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  34306. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  34307. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  34308. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  34309. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  34310. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  34311. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  34312. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  34313. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  34314. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  34315. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  34316. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  34317. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  34318. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  34319. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  34320. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  34321. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  34322. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  34323. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  34324. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  34325. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  34326. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  34327. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  34328. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  34329. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  34330. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  34331. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  34332. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  34333. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  34334. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  34335. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  34336. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  34337. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  34338. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  34339. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  34340. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  34341. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  34342. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  34343. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  34344. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  34345. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  34346. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  34347. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  34348. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  34349. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  34350. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  34351. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  34352. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  34353. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  34354. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  34355. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  34356. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  34357. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  34358. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  34359. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  34360. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  34361. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  34362. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  34363. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  34364. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  34365. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  34366. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  34367. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  34368. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  34369. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  34370. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  34371. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  34372. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  34373. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  34374. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  34375. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  34376. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  34377. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  34378. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  34379. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  34380. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  34381. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  34382. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  34383. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  34384. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  34385. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  34386. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  34387. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  34388. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  34389. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  34390. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  34391. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  34392. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  34393. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  34394. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  34395. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  34396. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  34397. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  34398. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  34399. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  34400. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  34401. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  34402. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  34403. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  34404. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  34405. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  34406. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  34407. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  34408. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  34409. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  34410. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  34411. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  34412. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  34413. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  34414. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  34415. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  34416. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  34417. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  34418. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  34419. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  34420. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  34421. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  34422. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  34423. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  34424. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  34425. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  34426. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  34427. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  34428. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  34429. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  34430. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  34431. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  34432. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  34433. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  34434. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  34435. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  34436. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  34437. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  34438. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  34439. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  34440. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  34441. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  34442. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  34443. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  34444. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  34445. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  34446. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  34447. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  34448. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  34449. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  34450. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  34451. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  34452. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  34453. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  34454. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  34455. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  34456. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  34457. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  34458. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  34459. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  34460. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  34461. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  34462. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  34463. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  34464. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  34465. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  34466. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  34467. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  34468. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  34469. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  34470. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  34471. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  34472. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  34473. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  34474. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  34475. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  34476. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  34477. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  34478. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  34479. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  34480. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  34481. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  34482. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  34483. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  34484. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  34485. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  34486. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  34487. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  34488. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  34489. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  34490. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  34491. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  34492. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  34493. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  34494. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  34495. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  34496. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  34497. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  34498. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  34499. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  34500. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  34501. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  34502. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  34503. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  34504. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  34505. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  34506. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  34507. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  34508. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  34509. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  34510. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  34511. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  34512. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  34513. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  34514. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  34515. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  34516. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  34517. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  34518. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  34519. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  34520. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  34521. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  34522. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  34523. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  34524. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  34525. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  34526. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  34527. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  34528. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  34529. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  34530. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  34531. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  34532. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  34533. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  34534. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  34535. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  34536. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  34537. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  34538. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  34539. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  34540. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  34541. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  34542. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  34543. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  34544. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  34545. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  34546. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  34547. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  34548. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  34549. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  34550. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  34551. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  34552. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  34553. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  34554. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  34555. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  34556. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  34557. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  34558. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  34559. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  34560. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  34561. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  34562. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  34563. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  34564. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  34565. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  34566. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  34567. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  34568. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  34569. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  34570. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  34571. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  34572. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  34573. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  34574. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  34575. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  34576. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  34577. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  34578. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  34579. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  34580. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  34581. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  34582. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  34583. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  34584. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  34585. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  34586. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  34587. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  34588. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  34589. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  34590. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  34591. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  34592. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  34593. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  34594. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  34595. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  34596. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  34597. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  34598. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  34599. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  34600. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  34601. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  34602. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  34603. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  34604. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  34605. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  34606. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  34607. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  34608. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  34609. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  34610. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  34611. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  34612. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  34613. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  34614. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  34615. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  34616. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  34617. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  34618. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  34619. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  34620. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  34621. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  34622. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  34623. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  34624. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  34625. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  34626. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  34627. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  34628. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  34629. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  34630. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  34631. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  34632. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  34633. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  34634. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  34635. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  34636. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  34637. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  34638. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  34639. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  34640. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  34641. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  34642. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  34643. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  34644. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  34645. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  34646. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  34647. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  34648. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  34649. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  34650. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  34651. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  34652. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  34653. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  34654. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  34655. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  34656. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  34657. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  34658. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  34659. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  34660. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  34661. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  34662. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  34663. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  34664. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  34665. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  34666. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  34667. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  34668. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  34669. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  34670. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  34671. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  34672. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  34673. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  34674. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  34675. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  34676. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  34677. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  34678. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  34679. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  34680. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  34681. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  34682. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  34683. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  34684. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  34685. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  34686. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  34687. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  34688. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  34689. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  34690. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  34691. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  34692. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  34693. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  34694. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  34695. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  34696. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  34697. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  34698. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  34699. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  34700. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  34701. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  34702. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  34703. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  34704. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  34705. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  34706. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  34707. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  34708. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  34709. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  34710. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  34711. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  34712. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  34713. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  34714. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  34715. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  34716. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  34717. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  34718. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  34719. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  34720. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  34721. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  34722. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  34723. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  34724. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  34725. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  34726. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  34727. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  34728. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  34729. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  34730. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  34731. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  34732. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  34733. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  34734. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  34735. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  34736. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  34737. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  34738. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  34739. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  34740. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  34741. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  34742. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  34743. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  34744. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  34745. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  34746. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  34747. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  34748. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  34749. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  34750. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  34751. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  34752. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  34753. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  34754. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  34755. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  34756. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  34757. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  34758. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  34759. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  34760. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  34761. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  34762. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  34763. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  34764. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  34765. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  34766. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  34767. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  34768. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  34769. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  34770. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  34771. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  34772. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  34773. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  34774. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  34775. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  34776. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  34777. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  34778. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  34779. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  34780. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  34781. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  34782. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  34783. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  34784. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  34785. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  34786. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  34787. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  34788. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  34789. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  34790. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  34791. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  34792. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  34793. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  34794. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  34795. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  34796. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  34797. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  34798. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  34799. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  34800. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  34801. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  34802. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  34803. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  34804. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  34805. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  34806. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  34807. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  34808. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  34809. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  34810. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  34811. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  34812. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  34813. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  34814. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  34815. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  34816. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  34817. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  34818. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  34819. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  34820. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  34821. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  34822. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  34823. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  34824. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  34825. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  34826. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  34827. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  34828. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  34829. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  34830. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  34831. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  34832. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  34833. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  34834. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  34835. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  34836. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  34837. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  34838. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  34839. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  34840. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  34841. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  34842. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  34843. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  34844. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  34845. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  34846. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  34847. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  34848. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  34849. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  34850. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  34851. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  34852. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  34853. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  34854. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  34855. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  34856. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  34857. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  34858. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  34859. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  34860. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  34861. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  34862. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  34863. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  34864. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  34865. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  34866. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  34867. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  34868. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  34869. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  34870. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  34871. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  34872. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  34873. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  34874. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  34875. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  34876. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  34877. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  34878. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  34879. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  34880. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  34881. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  34882. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  34883. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  34884. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  34885. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  34886. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  34887. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  34888. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  34889. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  34890. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  34891. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  34892. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  34893. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  34894. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  34895. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  34896. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  34897. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  34898. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  34899. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  34900. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  34901. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  34902. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  34903. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  34904. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  34905. };
  34906. #endif /* WOLFSSL_NO_ML_DSA_87 */
  34907. #endif
  34908. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34909. ExpectNotNull(key);
  34910. if (key != NULL) {
  34911. XMEMSET(key, 0, sizeof(*key));
  34912. }
  34913. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  34914. #ifndef WOLFSSL_NO_ML_DSA_44
  34915. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  34916. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  34917. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  34918. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  34919. #endif
  34920. #ifndef WOLFSSL_NO_ML_DSA_65
  34921. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  34922. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  34923. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  34924. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  34925. #endif
  34926. #ifndef WOLFSSL_NO_ML_DSA_87
  34927. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  34928. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  34929. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  34930. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  34931. #endif
  34932. wc_dilithium_free(key);
  34933. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34934. #endif
  34935. return EXPECT_RESULT();
  34936. }
  34937. static int test_wc_dilithium_sig_kats(void)
  34938. {
  34939. EXPECT_DECLS;
  34940. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  34941. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
  34942. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT)
  34943. dilithium_key* key;
  34944. #ifndef WOLFSSL_NO_ML_DSA_44
  34945. static const byte sk_44[] = {
  34946. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  34947. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  34948. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  34949. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  34950. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  34951. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  34952. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  34953. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  34954. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  34955. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  34956. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  34957. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  34958. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  34959. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  34960. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  34961. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  34962. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  34963. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  34964. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  34965. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  34966. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  34967. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  34968. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  34969. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  34970. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  34971. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  34972. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  34973. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  34974. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  34975. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  34976. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  34977. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  34978. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  34979. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  34980. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  34981. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  34982. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  34983. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  34984. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  34985. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  34986. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  34987. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  34988. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  34989. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  34990. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  34991. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  34992. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  34993. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  34994. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  34995. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  34996. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  34997. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  34998. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  34999. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  35000. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  35001. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  35002. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  35003. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  35004. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  35005. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  35006. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  35007. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  35008. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  35009. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  35010. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  35011. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  35012. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  35013. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  35014. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  35015. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  35016. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  35017. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  35018. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  35019. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  35020. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  35021. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  35022. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  35023. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  35024. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  35025. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  35026. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  35027. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  35028. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  35029. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  35030. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  35031. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  35032. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  35033. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  35034. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  35035. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  35036. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  35037. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  35038. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  35039. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  35040. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  35041. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  35042. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  35043. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  35044. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  35045. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  35046. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  35047. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  35048. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  35049. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  35050. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  35051. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  35052. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  35053. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  35054. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  35055. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  35056. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  35057. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  35058. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  35059. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  35060. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  35061. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  35062. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  35063. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  35064. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  35065. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  35066. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  35067. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  35068. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  35069. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  35070. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  35071. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  35072. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  35073. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  35074. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  35075. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  35076. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  35077. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  35078. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  35079. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  35080. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  35081. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  35082. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  35083. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  35084. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  35085. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  35086. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  35087. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  35088. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  35089. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  35090. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  35091. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  35092. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  35093. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  35094. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  35095. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  35096. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  35097. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  35098. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  35099. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  35100. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  35101. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  35102. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  35103. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  35104. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  35105. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  35106. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  35107. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  35108. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  35109. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  35110. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  35111. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  35112. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  35113. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  35114. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  35115. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  35116. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  35117. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  35118. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  35119. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  35120. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  35121. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  35122. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  35123. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  35124. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  35125. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  35126. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  35127. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  35128. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  35129. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  35130. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  35131. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  35132. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  35133. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  35134. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  35135. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  35136. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  35137. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  35138. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  35139. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  35140. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  35141. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  35142. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  35143. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  35144. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  35145. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  35146. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  35147. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  35148. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  35149. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  35150. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  35151. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  35152. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  35153. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  35154. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  35155. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  35156. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  35157. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  35158. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  35159. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  35160. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  35161. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  35162. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  35163. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  35164. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  35165. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  35166. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  35167. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  35168. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  35169. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  35170. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  35171. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  35172. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  35173. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  35174. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  35175. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  35176. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  35177. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  35178. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  35179. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  35180. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  35181. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  35182. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  35183. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  35184. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  35185. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  35186. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  35187. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  35188. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  35189. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  35190. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  35191. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  35192. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  35193. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  35194. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  35195. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  35196. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  35197. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  35198. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  35199. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  35200. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  35201. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  35202. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  35203. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  35204. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  35205. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  35206. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  35207. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  35208. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  35209. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  35210. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  35211. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  35212. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  35213. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  35214. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  35215. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  35216. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  35217. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  35218. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  35219. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  35220. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  35221. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  35222. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  35223. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  35224. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  35225. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  35226. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  35227. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  35228. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  35229. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  35230. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  35231. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  35232. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  35233. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  35234. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  35235. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  35236. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  35237. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  35238. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  35239. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  35240. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  35241. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  35242. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  35243. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  35244. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  35245. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  35246. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  35247. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  35248. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  35249. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  35250. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  35251. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  35252. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  35253. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  35254. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  35255. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  35256. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  35257. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  35258. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  35259. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  35260. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  35261. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  35262. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  35263. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  35264. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  35265. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  35266. };
  35267. static const byte msg_44[] = {
  35268. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  35269. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  35270. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  35271. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  35272. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  35273. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  35274. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  35275. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  35276. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  35277. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  35278. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  35279. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  35280. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  35281. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  35282. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  35283. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  35284. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  35285. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  35286. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  35287. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  35288. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  35289. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  35290. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  35291. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  35292. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  35293. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  35294. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  35295. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  35296. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  35297. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  35298. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  35299. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  35300. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  35301. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  35302. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  35303. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  35304. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  35305. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  35306. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  35307. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  35308. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  35309. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  35310. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  35311. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  35312. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  35313. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  35314. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  35315. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  35316. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  35317. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  35318. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  35319. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  35320. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  35321. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  35322. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  35323. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  35324. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  35325. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  35326. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  35327. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  35328. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  35329. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  35330. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  35331. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  35332. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  35333. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  35334. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  35335. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  35336. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  35337. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  35338. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  35339. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  35340. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  35341. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  35342. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  35343. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  35344. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  35345. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  35346. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  35347. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  35348. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  35349. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  35350. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  35351. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  35352. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  35353. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  35354. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  35355. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  35356. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  35357. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  35358. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  35359. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  35360. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  35361. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  35362. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  35363. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  35364. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  35365. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  35366. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  35367. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  35368. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  35369. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  35370. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  35371. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  35372. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  35373. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  35374. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  35375. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  35376. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  35377. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  35378. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  35379. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  35380. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  35381. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  35382. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  35383. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  35384. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  35385. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  35386. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  35387. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  35388. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  35389. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  35390. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  35391. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  35392. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  35393. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  35394. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  35395. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  35396. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  35397. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  35398. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  35399. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  35400. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  35401. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  35402. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  35403. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  35404. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  35405. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  35406. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  35407. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  35408. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  35409. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  35410. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  35411. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  35412. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  35413. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  35414. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  35415. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  35416. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  35417. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  35418. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  35419. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  35420. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  35421. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  35422. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  35423. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  35424. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  35425. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  35426. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  35427. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  35428. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  35429. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  35430. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  35431. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  35432. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  35433. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  35434. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  35435. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  35436. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  35437. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  35438. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  35439. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  35440. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  35441. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  35442. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  35443. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  35444. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  35445. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  35446. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  35447. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  35448. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  35449. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  35450. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  35451. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  35452. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  35453. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  35454. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  35455. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  35456. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  35457. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  35458. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  35459. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  35460. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  35461. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  35462. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  35463. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  35464. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  35465. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  35466. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  35467. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  35468. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  35469. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  35470. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  35471. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  35472. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  35473. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  35474. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  35475. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  35476. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  35477. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  35478. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  35479. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  35480. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  35481. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  35482. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  35483. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  35484. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  35485. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  35486. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  35487. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  35488. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  35489. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  35490. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  35491. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  35492. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  35493. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  35494. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  35495. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  35496. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  35497. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  35498. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  35499. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  35500. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  35501. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  35502. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  35503. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  35504. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  35505. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  35506. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  35507. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  35508. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  35509. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  35510. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  35511. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  35512. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  35513. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  35514. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  35515. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  35516. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  35517. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  35518. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  35519. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  35520. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  35521. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  35522. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  35523. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  35524. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  35525. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  35526. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  35527. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  35528. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  35529. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  35530. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  35531. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  35532. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  35533. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  35534. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  35535. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  35536. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  35537. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  35538. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  35539. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  35540. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  35541. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  35542. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  35543. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  35544. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  35545. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  35546. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  35547. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  35548. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  35549. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  35550. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  35551. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  35552. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  35553. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  35554. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  35555. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  35556. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  35557. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  35558. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  35559. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  35560. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  35561. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  35562. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  35563. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  35564. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  35565. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  35566. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  35567. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  35568. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  35569. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  35570. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  35571. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  35572. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  35573. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  35574. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  35575. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  35576. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  35577. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  35578. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  35579. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  35580. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  35581. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  35582. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  35583. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  35584. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  35585. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  35586. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  35587. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  35588. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  35589. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  35590. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  35591. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  35592. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  35593. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  35594. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  35595. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  35596. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  35597. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  35598. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  35599. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  35600. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  35601. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  35602. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  35603. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  35604. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  35605. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  35606. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  35607. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  35608. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  35609. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  35610. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  35611. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  35612. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  35613. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  35614. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  35615. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  35616. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  35617. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  35618. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  35619. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  35620. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  35621. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  35622. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  35623. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  35624. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  35625. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  35626. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  35627. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  35628. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  35629. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  35630. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  35631. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  35632. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  35633. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  35634. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  35635. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  35636. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  35637. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  35638. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  35639. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  35640. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  35641. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  35642. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  35643. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  35644. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  35645. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  35646. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  35647. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  35648. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  35649. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  35650. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  35651. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  35652. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  35653. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  35654. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  35655. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  35656. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  35657. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  35658. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  35659. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  35660. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  35661. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  35662. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  35663. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  35664. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  35665. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  35666. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  35667. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  35668. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  35669. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  35670. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  35671. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  35672. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  35673. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  35674. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  35675. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  35676. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  35677. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  35678. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  35679. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  35680. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  35681. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  35682. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  35683. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  35684. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  35685. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  35686. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  35687. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  35688. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  35689. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  35690. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  35691. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  35692. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  35693. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  35694. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  35695. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  35696. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  35697. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  35698. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  35699. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  35700. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  35701. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  35702. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  35703. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  35704. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  35705. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  35706. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  35707. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  35708. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  35709. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  35710. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  35711. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  35712. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  35713. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  35714. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  35715. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  35716. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  35717. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  35718. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  35719. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  35720. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  35721. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  35722. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  35723. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  35724. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  35725. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  35726. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  35727. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  35728. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  35729. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  35730. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  35731. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  35732. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  35733. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  35734. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  35735. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  35736. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  35737. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  35738. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  35739. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  35740. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  35741. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  35742. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  35743. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  35744. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  35745. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  35746. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  35747. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  35748. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  35749. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  35750. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  35751. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  35752. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  35753. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  35754. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  35755. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  35756. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  35757. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  35758. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  35759. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  35760. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  35761. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  35762. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  35763. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  35764. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  35765. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  35766. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  35767. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  35768. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  35769. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  35770. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  35771. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  35772. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  35773. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  35774. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  35775. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  35776. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  35777. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  35778. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  35779. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  35780. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  35781. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  35782. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  35783. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  35784. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  35785. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  35786. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  35787. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  35788. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  35789. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  35790. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  35791. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  35792. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  35793. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  35794. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  35795. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  35796. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  35797. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  35798. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  35799. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  35800. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  35801. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  35802. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  35803. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  35804. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  35805. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  35806. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  35807. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  35808. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  35809. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  35810. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  35811. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  35812. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  35813. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  35814. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  35815. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  35816. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  35817. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  35818. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  35819. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  35820. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  35821. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  35822. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  35823. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  35824. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  35825. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  35826. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  35827. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  35828. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  35829. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  35830. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  35831. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  35832. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  35833. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  35834. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  35835. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  35836. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  35837. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  35838. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  35839. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  35840. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  35841. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  35842. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  35843. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  35844. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  35845. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  35846. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  35847. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  35848. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  35849. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  35850. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  35851. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  35852. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  35853. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  35854. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  35855. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  35856. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  35857. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  35858. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  35859. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  35860. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  35861. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  35862. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  35863. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  35864. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  35865. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  35866. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  35867. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  35868. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  35869. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  35870. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  35871. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  35872. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  35873. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  35874. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  35875. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  35876. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  35877. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  35878. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  35879. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  35880. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  35881. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  35882. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  35883. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  35884. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  35885. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  35886. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  35887. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  35888. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  35889. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  35890. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  35891. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  35892. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  35893. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  35894. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  35895. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  35896. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  35897. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  35898. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  35899. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  35900. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  35901. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  35902. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  35903. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  35904. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  35905. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  35906. 0x96
  35907. };
  35908. static const byte rnd_44[] = {
  35909. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  35910. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  35911. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  35912. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  35913. };
  35914. static const byte sig_44[] = {
  35915. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  35916. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  35917. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  35918. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  35919. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  35920. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  35921. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  35922. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  35923. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  35924. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  35925. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  35926. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  35927. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  35928. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  35929. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  35930. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  35931. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  35932. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  35933. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  35934. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  35935. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  35936. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  35937. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  35938. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  35939. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  35940. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  35941. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  35942. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  35943. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  35944. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  35945. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  35946. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  35947. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  35948. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  35949. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  35950. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  35951. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  35952. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  35953. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  35954. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  35955. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  35956. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  35957. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  35958. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  35959. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  35960. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  35961. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  35962. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  35963. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  35964. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  35965. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  35966. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  35967. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  35968. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  35969. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  35970. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  35971. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  35972. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  35973. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  35974. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  35975. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  35976. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  35977. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  35978. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  35979. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  35980. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  35981. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  35982. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  35983. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  35984. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  35985. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  35986. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  35987. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  35988. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  35989. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  35990. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  35991. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  35992. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  35993. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  35994. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  35995. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  35996. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  35997. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  35998. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  35999. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  36000. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  36001. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  36002. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  36003. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  36004. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  36005. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  36006. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  36007. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  36008. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  36009. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  36010. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  36011. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  36012. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  36013. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  36014. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  36015. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  36016. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  36017. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  36018. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  36019. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  36020. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  36021. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  36022. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  36023. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  36024. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  36025. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  36026. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  36027. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  36028. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  36029. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  36030. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  36031. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  36032. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  36033. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  36034. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  36035. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  36036. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  36037. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  36038. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  36039. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  36040. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  36041. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  36042. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  36043. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  36044. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  36045. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  36046. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  36047. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  36048. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  36049. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  36050. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  36051. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  36052. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  36053. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  36054. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  36055. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  36056. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  36057. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  36058. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  36059. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  36060. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  36061. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  36062. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  36063. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  36064. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  36065. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  36066. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  36067. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  36068. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  36069. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  36070. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  36071. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  36072. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  36073. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  36074. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  36075. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  36076. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  36077. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  36078. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  36079. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  36080. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  36081. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  36082. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  36083. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  36084. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  36085. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  36086. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  36087. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  36088. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  36089. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  36090. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  36091. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  36092. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  36093. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  36094. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  36095. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  36096. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  36097. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  36098. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  36099. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  36100. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  36101. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  36102. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  36103. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  36104. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  36105. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  36106. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  36107. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  36108. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  36109. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  36110. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  36111. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  36112. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  36113. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  36114. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  36115. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  36116. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  36117. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  36118. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  36119. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  36120. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  36121. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  36122. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  36123. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  36124. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  36125. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  36126. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  36127. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  36128. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  36129. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  36130. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  36131. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  36132. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  36133. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  36134. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  36135. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  36136. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  36137. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  36138. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  36139. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  36140. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  36141. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  36142. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  36143. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  36144. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  36145. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  36146. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  36147. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  36148. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  36149. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  36150. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  36151. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  36152. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  36153. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  36154. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  36155. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  36156. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  36157. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  36158. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  36159. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  36160. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  36161. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  36162. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  36163. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  36164. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  36165. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  36166. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  36167. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  36168. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  36169. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  36170. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  36171. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  36172. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  36173. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  36174. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  36175. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  36176. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  36177. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  36178. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  36179. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  36180. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  36181. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  36182. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  36183. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  36184. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  36185. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  36186. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  36187. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  36188. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  36189. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  36190. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  36191. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  36192. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  36193. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  36194. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  36195. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  36196. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  36197. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  36198. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  36199. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  36200. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  36201. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  36202. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  36203. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  36204. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  36205. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  36206. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  36207. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  36208. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  36209. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  36210. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  36211. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  36212. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  36213. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36214. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36215. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36216. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36217. 0x06, 0x17, 0x23, 0x2E
  36218. };
  36219. #endif
  36220. #ifndef WOLFSSL_NO_ML_DSA_65
  36221. static const byte sk_65[] = {
  36222. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  36223. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  36224. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  36225. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  36226. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  36227. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  36228. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  36229. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  36230. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  36231. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  36232. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  36233. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  36234. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  36235. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  36236. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  36237. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  36238. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  36239. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  36240. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  36241. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  36242. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  36243. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  36244. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  36245. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  36246. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  36247. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  36248. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  36249. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  36250. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  36251. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  36252. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  36253. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  36254. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  36255. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  36256. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  36257. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  36258. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  36259. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  36260. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  36261. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  36262. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  36263. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  36264. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  36265. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  36266. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  36267. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  36268. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  36269. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  36270. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  36271. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  36272. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  36273. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  36274. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  36275. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  36276. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  36277. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  36278. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  36279. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  36280. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  36281. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  36282. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  36283. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  36284. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  36285. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  36286. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  36287. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  36288. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  36289. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  36290. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  36291. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  36292. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  36293. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  36294. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  36295. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  36296. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  36297. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  36298. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  36299. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  36300. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  36301. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  36302. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  36303. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  36304. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  36305. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  36306. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  36307. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  36308. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  36309. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  36310. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  36311. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  36312. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  36313. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  36314. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  36315. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  36316. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  36317. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  36318. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  36319. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  36320. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  36321. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  36322. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  36323. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  36324. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  36325. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  36326. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  36327. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  36328. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  36329. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  36330. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  36331. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  36332. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  36333. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  36334. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  36335. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  36336. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  36337. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  36338. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  36339. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  36340. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  36341. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  36342. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  36343. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  36344. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  36345. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  36346. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  36347. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  36348. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  36349. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  36350. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  36351. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  36352. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  36353. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  36354. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  36355. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  36356. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  36357. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  36358. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  36359. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  36360. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  36361. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  36362. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  36363. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  36364. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  36365. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  36366. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  36367. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  36368. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  36369. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  36370. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  36371. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  36372. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  36373. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  36374. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  36375. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  36376. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  36377. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  36378. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  36379. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  36380. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  36381. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  36382. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  36383. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  36384. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  36385. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  36386. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  36387. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  36388. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  36389. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  36390. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  36391. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  36392. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  36393. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  36394. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  36395. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  36396. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  36397. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  36398. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  36399. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  36400. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  36401. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  36402. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  36403. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  36404. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  36405. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  36406. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  36407. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  36408. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  36409. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  36410. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  36411. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  36412. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  36413. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  36414. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  36415. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  36416. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  36417. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  36418. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  36419. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  36420. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  36421. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  36422. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  36423. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  36424. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  36425. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  36426. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  36427. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  36428. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  36429. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  36430. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  36431. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  36432. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  36433. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  36434. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  36435. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  36436. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  36437. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  36438. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  36439. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  36440. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  36441. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  36442. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  36443. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  36444. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  36445. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  36446. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  36447. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  36448. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  36449. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  36450. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  36451. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  36452. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  36453. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  36454. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  36455. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  36456. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  36457. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  36458. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  36459. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  36460. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  36461. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  36462. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  36463. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  36464. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  36465. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  36466. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  36467. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  36468. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  36469. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  36470. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  36471. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  36472. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  36473. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  36474. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  36475. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  36476. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  36477. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  36478. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  36479. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  36480. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  36481. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  36482. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  36483. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  36484. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  36485. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  36486. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  36487. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  36488. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  36489. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  36490. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  36491. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  36492. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  36493. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  36494. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  36495. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  36496. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  36497. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  36498. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  36499. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  36500. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  36501. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  36502. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  36503. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  36504. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  36505. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  36506. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  36507. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  36508. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  36509. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  36510. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  36511. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  36512. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  36513. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  36514. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  36515. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  36516. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  36517. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  36518. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  36519. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  36520. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  36521. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  36522. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  36523. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  36524. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  36525. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  36526. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  36527. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  36528. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  36529. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  36530. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  36531. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  36532. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  36533. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  36534. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  36535. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  36536. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  36537. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  36538. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  36539. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  36540. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  36541. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  36542. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  36543. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  36544. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  36545. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  36546. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  36547. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  36548. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  36549. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  36550. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  36551. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  36552. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  36553. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  36554. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  36555. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  36556. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  36557. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  36558. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  36559. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  36560. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  36561. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  36562. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  36563. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  36564. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  36565. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  36566. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  36567. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  36568. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  36569. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  36570. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  36571. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  36572. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  36573. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  36574. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  36575. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  36576. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  36577. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  36578. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  36579. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  36580. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  36581. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  36582. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  36583. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  36584. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  36585. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  36586. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  36587. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  36588. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  36589. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  36590. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  36591. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  36592. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  36593. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  36594. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  36595. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  36596. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  36597. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  36598. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  36599. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  36600. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  36601. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  36602. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  36603. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  36604. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  36605. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  36606. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  36607. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  36608. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  36609. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  36610. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  36611. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  36612. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  36613. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  36614. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  36615. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  36616. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  36617. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  36618. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  36619. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  36620. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  36621. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  36622. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  36623. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  36624. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  36625. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  36626. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  36627. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  36628. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  36629. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  36630. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  36631. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  36632. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  36633. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  36634. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  36635. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  36636. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  36637. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  36638. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  36639. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  36640. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  36641. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  36642. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  36643. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  36644. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  36645. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  36646. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  36647. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  36648. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  36649. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  36650. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  36651. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  36652. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  36653. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  36654. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  36655. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  36656. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  36657. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  36658. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  36659. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  36660. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  36661. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  36662. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  36663. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  36664. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  36665. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  36666. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  36667. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  36668. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  36669. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  36670. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  36671. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  36672. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  36673. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  36674. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  36675. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  36676. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  36677. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  36678. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  36679. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  36680. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  36681. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  36682. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  36683. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  36684. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  36685. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  36686. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  36687. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  36688. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  36689. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  36690. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  36691. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  36692. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  36693. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  36694. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  36695. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  36696. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  36697. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  36698. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  36699. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  36700. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  36701. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  36702. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  36703. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  36704. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  36705. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  36706. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  36707. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  36708. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  36709. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  36710. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  36711. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  36712. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  36713. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  36714. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  36715. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  36716. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  36717. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  36718. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  36719. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  36720. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  36721. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  36722. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  36723. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  36724. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  36725. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  36726. };
  36727. static const byte msg_65[] = {
  36728. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  36729. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  36730. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  36731. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  36732. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  36733. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  36734. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  36735. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  36736. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  36737. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  36738. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  36739. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  36740. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  36741. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  36742. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  36743. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  36744. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  36745. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  36746. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  36747. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  36748. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  36749. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  36750. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  36751. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  36752. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  36753. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  36754. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  36755. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  36756. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  36757. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  36758. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  36759. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  36760. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  36761. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  36762. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  36763. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  36764. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  36765. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  36766. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  36767. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  36768. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  36769. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  36770. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  36771. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  36772. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  36773. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  36774. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  36775. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  36776. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  36777. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  36778. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  36779. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  36780. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  36781. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  36782. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  36783. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  36784. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  36785. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  36786. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  36787. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  36788. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  36789. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  36790. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  36791. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  36792. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  36793. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  36794. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  36795. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  36796. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  36797. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  36798. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  36799. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  36800. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  36801. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  36802. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  36803. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  36804. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  36805. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  36806. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  36807. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  36808. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  36809. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  36810. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  36811. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  36812. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  36813. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  36814. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  36815. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  36816. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  36817. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  36818. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  36819. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  36820. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  36821. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  36822. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  36823. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  36824. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  36825. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  36826. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  36827. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  36828. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  36829. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  36830. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  36831. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  36832. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  36833. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  36834. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  36835. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  36836. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  36837. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  36838. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  36839. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  36840. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  36841. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  36842. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  36843. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  36844. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  36845. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  36846. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  36847. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  36848. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  36849. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  36850. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  36851. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  36852. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  36853. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  36854. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  36855. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  36856. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  36857. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  36858. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  36859. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  36860. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  36861. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  36862. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  36863. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  36864. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  36865. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  36866. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  36867. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  36868. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  36869. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  36870. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  36871. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  36872. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  36873. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  36874. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  36875. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  36876. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  36877. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  36878. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  36879. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  36880. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  36881. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  36882. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  36883. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  36884. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  36885. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  36886. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  36887. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  36888. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  36889. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  36890. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  36891. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  36892. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  36893. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  36894. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  36895. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  36896. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  36897. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  36898. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  36899. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  36900. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  36901. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  36902. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  36903. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  36904. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  36905. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  36906. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  36907. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  36908. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  36909. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  36910. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  36911. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  36912. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  36913. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  36914. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  36915. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  36916. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  36917. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  36918. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  36919. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  36920. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  36921. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  36922. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  36923. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  36924. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  36925. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  36926. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  36927. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  36928. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  36929. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  36930. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  36931. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  36932. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  36933. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  36934. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  36935. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  36936. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  36937. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  36938. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  36939. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  36940. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  36941. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  36942. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  36943. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  36944. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  36945. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  36946. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  36947. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  36948. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  36949. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  36950. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  36951. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  36952. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  36953. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  36954. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  36955. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  36956. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  36957. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  36958. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  36959. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  36960. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  36961. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  36962. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  36963. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  36964. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  36965. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  36966. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  36967. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  36968. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  36969. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  36970. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  36971. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  36972. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  36973. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  36974. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  36975. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  36976. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  36977. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  36978. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  36979. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  36980. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  36981. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  36982. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  36983. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  36984. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  36985. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  36986. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  36987. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  36988. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  36989. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  36990. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  36991. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  36992. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  36993. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  36994. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  36995. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  36996. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  36997. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  36998. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  36999. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  37000. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  37001. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  37002. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  37003. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  37004. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  37005. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  37006. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  37007. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  37008. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  37009. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  37010. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  37011. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  37012. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  37013. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  37014. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  37015. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  37016. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  37017. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  37018. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  37019. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  37020. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  37021. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  37022. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  37023. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  37024. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  37025. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  37026. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  37027. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  37028. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  37029. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  37030. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  37031. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  37032. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  37033. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  37034. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  37035. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  37036. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  37037. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  37038. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  37039. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  37040. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  37041. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  37042. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  37043. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  37044. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  37045. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  37046. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  37047. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  37048. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  37049. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  37050. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  37051. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  37052. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  37053. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  37054. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  37055. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  37056. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  37057. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  37058. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  37059. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  37060. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  37061. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  37062. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  37063. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  37064. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  37065. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  37066. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  37067. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  37068. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  37069. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  37070. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  37071. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  37072. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  37073. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  37074. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  37075. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  37076. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  37077. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  37078. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  37079. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  37080. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  37081. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  37082. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  37083. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  37084. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  37085. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  37086. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  37087. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  37088. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  37089. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  37090. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  37091. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  37092. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  37093. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  37094. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  37095. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  37096. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  37097. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  37098. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  37099. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  37100. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  37101. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  37102. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  37103. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  37104. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  37105. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  37106. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  37107. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  37108. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  37109. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  37110. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  37111. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  37112. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  37113. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  37114. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  37115. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  37116. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  37117. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  37118. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  37119. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  37120. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  37121. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  37122. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  37123. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  37124. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  37125. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  37126. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  37127. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  37128. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  37129. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  37130. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  37131. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  37132. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  37133. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  37134. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  37135. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  37136. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  37137. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  37138. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  37139. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  37140. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  37141. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  37142. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  37143. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  37144. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  37145. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  37146. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  37147. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  37148. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  37149. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  37150. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  37151. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  37152. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  37153. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  37154. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  37155. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  37156. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  37157. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  37158. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  37159. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  37160. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  37161. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  37162. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  37163. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  37164. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  37165. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  37166. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  37167. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  37168. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  37169. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  37170. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  37171. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  37172. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  37173. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  37174. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  37175. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  37176. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  37177. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  37178. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  37179. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  37180. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  37181. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  37182. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  37183. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  37184. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  37185. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  37186. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  37187. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  37188. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  37189. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  37190. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  37191. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  37192. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  37193. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  37194. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  37195. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  37196. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  37197. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  37198. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  37199. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  37200. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  37201. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  37202. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  37203. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  37204. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  37205. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  37206. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  37207. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  37208. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  37209. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  37210. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  37211. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  37212. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  37213. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  37214. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  37215. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  37216. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  37217. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  37218. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  37219. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  37220. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  37221. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  37222. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  37223. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  37224. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  37225. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  37226. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  37227. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  37228. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  37229. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  37230. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  37231. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  37232. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  37233. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  37234. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  37235. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  37236. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  37237. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  37238. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  37239. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  37240. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  37241. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  37242. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  37243. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  37244. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  37245. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  37246. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  37247. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  37248. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  37249. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  37250. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  37251. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  37252. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  37253. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  37254. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  37255. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  37256. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  37257. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  37258. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  37259. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  37260. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  37261. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  37262. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  37263. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  37264. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  37265. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  37266. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  37267. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  37268. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  37269. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  37270. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  37271. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  37272. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  37273. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  37274. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  37275. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  37276. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  37277. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  37278. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  37279. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  37280. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  37281. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  37282. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  37283. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  37284. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  37285. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  37286. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  37287. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  37288. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  37289. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  37290. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  37291. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  37292. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  37293. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  37294. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  37295. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  37296. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  37297. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  37298. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  37299. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  37300. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  37301. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  37302. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  37303. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  37304. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  37305. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  37306. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  37307. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  37308. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  37309. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  37310. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  37311. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  37312. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  37313. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  37314. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  37315. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  37316. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  37317. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  37318. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  37319. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  37320. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  37321. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  37322. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  37323. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  37324. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  37325. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  37326. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  37327. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  37328. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  37329. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  37330. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  37331. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  37332. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  37333. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  37334. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  37335. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  37336. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  37337. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  37338. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  37339. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  37340. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  37341. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  37342. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  37343. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  37344. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  37345. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  37346. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  37347. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  37348. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  37349. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  37350. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  37351. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  37352. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  37353. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  37354. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  37355. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  37356. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  37357. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  37358. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  37359. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  37360. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  37361. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  37362. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  37363. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  37364. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  37365. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  37366. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  37367. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  37368. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  37369. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  37370. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  37371. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  37372. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  37373. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  37374. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  37375. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  37376. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  37377. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  37378. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  37379. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  37380. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  37381. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  37382. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  37383. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  37384. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  37385. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  37386. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  37387. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  37388. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  37389. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  37390. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  37391. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  37392. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  37393. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  37394. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  37395. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  37396. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  37397. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  37398. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  37399. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  37400. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  37401. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  37402. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  37403. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  37404. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  37405. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  37406. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  37407. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  37408. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  37409. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  37410. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  37411. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  37412. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  37413. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  37414. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  37415. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  37416. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  37417. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  37418. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  37419. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  37420. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  37421. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  37422. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  37423. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  37424. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  37425. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  37426. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  37427. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  37428. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  37429. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  37430. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  37431. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  37432. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  37433. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  37434. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  37435. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  37436. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  37437. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  37438. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  37439. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  37440. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  37441. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  37442. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  37443. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  37444. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  37445. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  37446. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  37447. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  37448. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  37449. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  37450. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  37451. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  37452. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  37453. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  37454. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  37455. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  37456. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  37457. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  37458. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  37459. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  37460. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  37461. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  37462. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  37463. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  37464. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  37465. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  37466. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  37467. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  37468. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  37469. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  37470. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  37471. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  37472. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  37473. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  37474. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  37475. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  37476. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  37477. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  37478. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  37479. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  37480. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  37481. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  37482. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  37483. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  37484. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  37485. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  37486. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  37487. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  37488. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  37489. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  37490. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  37491. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  37492. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  37493. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  37494. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  37495. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  37496. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  37497. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  37498. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  37499. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  37500. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  37501. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  37502. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  37503. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  37504. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  37505. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  37506. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  37507. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  37508. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  37509. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  37510. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  37511. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  37512. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  37513. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  37514. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  37515. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  37516. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  37517. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  37518. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  37519. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  37520. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  37521. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  37522. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  37523. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  37524. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  37525. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  37526. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  37527. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  37528. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  37529. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  37530. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  37531. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  37532. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  37533. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  37534. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  37535. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  37536. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  37537. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  37538. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  37539. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  37540. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  37541. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  37542. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  37543. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  37544. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  37545. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  37546. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  37547. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  37548. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  37549. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  37550. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  37551. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  37552. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  37553. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  37554. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  37555. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  37556. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  37557. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  37558. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  37559. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  37560. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  37561. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  37562. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  37563. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  37564. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  37565. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  37566. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  37567. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  37568. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  37569. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  37570. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  37571. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  37572. 0x60, 0x28, 0x77, 0xEE
  37573. };
  37574. static const byte rnd_65[] = {
  37575. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  37576. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  37577. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  37578. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  37579. };
  37580. static const byte sig_65[] = {
  37581. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  37582. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  37583. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  37584. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  37585. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  37586. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  37587. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  37588. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  37589. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  37590. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  37591. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  37592. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  37593. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  37594. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  37595. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  37596. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  37597. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  37598. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  37599. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  37600. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  37601. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  37602. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  37603. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  37604. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  37605. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  37606. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  37607. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  37608. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  37609. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  37610. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  37611. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  37612. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  37613. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  37614. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  37615. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  37616. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  37617. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  37618. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  37619. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  37620. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  37621. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  37622. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  37623. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  37624. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  37625. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  37626. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  37627. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  37628. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  37629. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  37630. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  37631. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  37632. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  37633. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  37634. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  37635. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  37636. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  37637. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  37638. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  37639. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  37640. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  37641. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  37642. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  37643. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  37644. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  37645. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  37646. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  37647. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  37648. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  37649. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  37650. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  37651. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  37652. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  37653. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  37654. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  37655. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  37656. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  37657. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  37658. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  37659. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  37660. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  37661. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  37662. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  37663. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  37664. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  37665. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  37666. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  37667. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  37668. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  37669. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  37670. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  37671. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  37672. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  37673. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  37674. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  37675. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  37676. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  37677. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  37678. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  37679. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  37680. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  37681. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  37682. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  37683. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  37684. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  37685. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  37686. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  37687. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  37688. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  37689. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  37690. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  37691. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  37692. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  37693. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  37694. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  37695. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  37696. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  37697. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  37698. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  37699. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  37700. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  37701. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  37702. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  37703. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  37704. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  37705. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  37706. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  37707. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  37708. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  37709. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  37710. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  37711. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  37712. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  37713. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  37714. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  37715. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  37716. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  37717. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  37718. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  37719. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  37720. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  37721. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  37722. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  37723. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  37724. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  37725. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  37726. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  37727. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  37728. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  37729. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  37730. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  37731. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  37732. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  37733. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  37734. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  37735. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  37736. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  37737. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  37738. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  37739. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  37740. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  37741. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  37742. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  37743. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  37744. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  37745. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  37746. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  37747. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  37748. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  37749. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  37750. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  37751. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  37752. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  37753. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  37754. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  37755. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  37756. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  37757. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  37758. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  37759. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  37760. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  37761. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  37762. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  37763. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  37764. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  37765. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  37766. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  37767. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  37768. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  37769. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  37770. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  37771. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  37772. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  37773. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  37774. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  37775. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  37776. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  37777. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  37778. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  37779. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  37780. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  37781. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  37782. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  37783. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  37784. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  37785. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  37786. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  37787. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  37788. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  37789. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  37790. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  37791. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  37792. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  37793. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  37794. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  37795. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  37796. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  37797. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  37798. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  37799. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  37800. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  37801. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  37802. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  37803. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  37804. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  37805. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  37806. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  37807. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  37808. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  37809. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  37810. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  37811. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  37812. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  37813. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  37814. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  37815. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  37816. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  37817. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  37818. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  37819. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  37820. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  37821. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  37822. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  37823. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  37824. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  37825. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  37826. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  37827. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  37828. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  37829. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  37830. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  37831. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  37832. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  37833. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  37834. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  37835. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  37836. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  37837. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  37838. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  37839. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  37840. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  37841. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  37842. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  37843. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  37844. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  37845. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  37846. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  37847. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  37848. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  37849. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  37850. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  37851. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  37852. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  37853. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  37854. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  37855. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  37856. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  37857. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  37858. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  37859. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  37860. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  37861. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  37862. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  37863. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  37864. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  37865. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  37866. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  37867. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  37868. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  37869. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  37870. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  37871. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  37872. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  37873. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  37874. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  37875. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  37876. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  37877. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  37878. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  37879. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  37880. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  37881. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  37882. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  37883. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  37884. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  37885. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  37886. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  37887. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  37888. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  37889. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  37890. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  37891. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  37892. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  37893. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  37894. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  37895. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  37896. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  37897. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  37898. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  37899. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  37900. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  37901. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  37902. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  37903. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  37904. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  37905. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  37906. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  37907. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  37908. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  37909. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  37910. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  37911. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  37912. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  37913. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  37914. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  37915. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  37916. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  37917. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  37918. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  37919. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  37920. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  37921. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  37922. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  37923. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  37924. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  37925. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  37926. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  37927. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  37928. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  37929. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  37930. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  37931. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  37932. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  37933. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  37934. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  37935. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  37936. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  37937. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  37938. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  37939. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  37940. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  37941. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  37942. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  37943. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  37944. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  37945. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  37946. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  37947. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  37948. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  37949. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  37950. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  37951. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  37952. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  37953. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  37954. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  37955. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  37956. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  37957. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  37958. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  37959. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  37960. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  37961. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  37962. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  37963. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  37964. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  37965. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  37966. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  37967. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  37968. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  37969. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  37970. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  37971. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  37972. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  37973. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  37974. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  37975. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  37976. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  37977. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  37978. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  37979. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  37980. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  37981. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  37982. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  37983. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  37984. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  37985. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  37986. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  37987. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  37988. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  37989. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  37990. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  37991. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  37992. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37993. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  37994. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  37995. };
  37996. #endif
  37997. #ifndef WOLFSSL_NO_ML_DSA_87
  37998. static const byte sk_87[] = {
  37999. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  38000. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  38001. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  38002. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  38003. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  38004. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  38005. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  38006. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  38007. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  38008. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  38009. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  38010. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  38011. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  38012. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  38013. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  38014. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  38015. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  38016. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  38017. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  38018. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  38019. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  38020. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  38021. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  38022. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  38023. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  38024. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  38025. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  38026. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  38027. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  38028. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  38029. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  38030. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  38031. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  38032. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  38033. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  38034. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  38035. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  38036. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  38037. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  38038. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  38039. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  38040. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  38041. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  38042. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  38043. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  38044. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  38045. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  38046. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  38047. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  38048. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  38049. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  38050. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  38051. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  38052. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  38053. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  38054. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  38055. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  38056. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  38057. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  38058. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  38059. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  38060. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  38061. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  38062. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  38063. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  38064. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  38065. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  38066. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  38067. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  38068. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  38069. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  38070. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  38071. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  38072. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  38073. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  38074. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  38075. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  38076. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  38077. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  38078. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  38079. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  38080. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  38081. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  38082. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  38083. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  38084. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  38085. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  38086. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  38087. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  38088. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  38089. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  38090. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  38091. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  38092. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  38093. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  38094. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  38095. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  38096. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  38097. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  38098. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  38099. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  38100. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  38101. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  38102. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  38103. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  38104. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  38105. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  38106. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  38107. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  38108. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  38109. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  38110. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  38111. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  38112. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  38113. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  38114. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  38115. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  38116. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  38117. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  38118. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  38119. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  38120. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  38121. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  38122. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  38123. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  38124. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  38125. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  38126. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  38127. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  38128. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  38129. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  38130. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  38131. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  38132. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  38133. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  38134. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  38135. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  38136. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  38137. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  38138. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  38139. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  38140. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  38141. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  38142. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  38143. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  38144. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  38145. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  38146. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  38147. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  38148. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  38149. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  38150. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  38151. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  38152. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  38153. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  38154. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  38155. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  38156. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  38157. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  38158. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  38159. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  38160. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  38161. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  38162. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  38163. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  38164. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  38165. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  38166. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  38167. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  38168. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  38169. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  38170. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  38171. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  38172. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  38173. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  38174. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  38175. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  38176. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  38177. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  38178. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  38179. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  38180. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  38181. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  38182. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  38183. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  38184. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  38185. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  38186. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  38187. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  38188. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  38189. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  38190. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  38191. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  38192. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  38193. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  38194. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  38195. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  38196. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  38197. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  38198. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  38199. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  38200. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  38201. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  38202. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  38203. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  38204. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  38205. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  38206. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  38207. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  38208. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  38209. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  38210. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  38211. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  38212. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  38213. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  38214. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  38215. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  38216. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  38217. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  38218. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  38219. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  38220. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  38221. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  38222. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  38223. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  38224. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  38225. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  38226. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  38227. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  38228. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  38229. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  38230. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  38231. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  38232. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  38233. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  38234. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  38235. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  38236. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  38237. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  38238. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  38239. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  38240. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  38241. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  38242. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  38243. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  38244. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  38245. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  38246. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  38247. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  38248. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  38249. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  38250. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  38251. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  38252. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  38253. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  38254. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  38255. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  38256. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  38257. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  38258. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  38259. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  38260. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  38261. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  38262. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  38263. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  38264. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  38265. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  38266. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  38267. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  38268. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  38269. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  38270. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  38271. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  38272. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  38273. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  38274. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  38275. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  38276. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  38277. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  38278. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  38279. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  38280. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  38281. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  38282. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  38283. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  38284. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  38285. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  38286. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  38287. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  38288. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  38289. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  38290. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  38291. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  38292. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  38293. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  38294. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  38295. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  38296. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  38297. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  38298. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  38299. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  38300. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  38301. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  38302. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  38303. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  38304. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  38305. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  38306. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  38307. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  38308. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  38309. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  38310. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  38311. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  38312. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  38313. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  38314. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  38315. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  38316. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  38317. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  38318. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  38319. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  38320. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  38321. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  38322. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  38323. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  38324. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  38325. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  38326. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  38327. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  38328. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  38329. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  38330. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  38331. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  38332. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  38333. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  38334. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  38335. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  38336. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  38337. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  38338. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  38339. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  38340. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  38341. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  38342. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  38343. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  38344. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  38345. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  38346. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  38347. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  38348. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  38349. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  38350. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  38351. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  38352. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  38353. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  38354. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  38355. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  38356. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  38357. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  38358. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  38359. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  38360. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  38361. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  38362. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  38363. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  38364. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  38365. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  38366. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  38367. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  38368. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  38369. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  38370. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  38371. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  38372. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  38373. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  38374. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  38375. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  38376. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  38377. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  38378. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  38379. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  38380. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  38381. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  38382. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  38383. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  38384. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  38385. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  38386. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  38387. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  38388. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  38389. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  38390. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  38391. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  38392. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  38393. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  38394. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  38395. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  38396. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  38397. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  38398. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  38399. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  38400. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  38401. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  38402. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  38403. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  38404. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  38405. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  38406. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  38407. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  38408. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  38409. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  38410. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  38411. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  38412. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  38413. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  38414. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  38415. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  38416. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  38417. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  38418. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  38419. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  38420. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  38421. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  38422. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  38423. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  38424. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  38425. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  38426. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  38427. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  38428. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  38429. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  38430. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  38431. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  38432. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  38433. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  38434. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  38435. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  38436. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  38437. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  38438. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  38439. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  38440. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  38441. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  38442. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  38443. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  38444. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  38445. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  38446. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  38447. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  38448. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  38449. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  38450. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  38451. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  38452. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  38453. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  38454. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  38455. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  38456. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  38457. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  38458. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  38459. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  38460. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  38461. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  38462. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  38463. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  38464. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  38465. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  38466. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  38467. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  38468. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  38469. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  38470. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  38471. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  38472. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  38473. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  38474. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  38475. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  38476. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  38477. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  38478. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  38479. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  38480. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  38481. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  38482. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  38483. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  38484. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  38485. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  38486. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  38487. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  38488. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  38489. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  38490. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  38491. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  38492. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  38493. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  38494. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  38495. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  38496. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  38497. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  38498. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  38499. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  38500. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  38501. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  38502. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  38503. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  38504. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  38505. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  38506. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  38507. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  38508. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  38509. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  38510. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  38511. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  38512. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  38513. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  38514. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  38515. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  38516. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  38517. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  38518. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  38519. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  38520. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  38521. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  38522. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  38523. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  38524. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  38525. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  38526. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  38527. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  38528. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  38529. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  38530. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  38531. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  38532. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  38533. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  38534. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  38535. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  38536. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  38537. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  38538. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  38539. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  38540. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  38541. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  38542. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  38543. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  38544. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  38545. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  38546. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  38547. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  38548. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  38549. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  38550. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  38551. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  38552. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  38553. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  38554. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  38555. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  38556. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  38557. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  38558. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  38559. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  38560. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  38561. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  38562. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  38563. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  38564. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  38565. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  38566. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  38567. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  38568. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  38569. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  38570. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  38571. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  38572. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  38573. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  38574. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  38575. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  38576. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  38577. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  38578. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  38579. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  38580. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  38581. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  38582. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  38583. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  38584. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  38585. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  38586. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  38587. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  38588. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  38589. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  38590. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  38591. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  38592. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  38593. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  38594. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  38595. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  38596. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  38597. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  38598. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  38599. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  38600. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  38601. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  38602. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  38603. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  38604. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  38605. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  38606. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  38607. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  38608. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  38609. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  38610. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  38611. };
  38612. static const byte msg_87[] = {
  38613. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  38614. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  38615. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  38616. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  38617. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  38618. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  38619. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  38620. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  38621. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  38622. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  38623. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  38624. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  38625. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  38626. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  38627. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  38628. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  38629. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  38630. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  38631. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  38632. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  38633. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  38634. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  38635. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  38636. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  38637. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  38638. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  38639. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  38640. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  38641. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  38642. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  38643. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  38644. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  38645. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  38646. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  38647. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  38648. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  38649. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  38650. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  38651. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  38652. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  38653. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  38654. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  38655. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  38656. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  38657. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  38658. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  38659. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  38660. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  38661. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  38662. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  38663. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  38664. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  38665. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  38666. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  38667. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  38668. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  38669. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  38670. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  38671. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  38672. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  38673. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  38674. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  38675. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  38676. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  38677. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  38678. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  38679. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  38680. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  38681. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  38682. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  38683. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  38684. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  38685. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  38686. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  38687. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  38688. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  38689. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  38690. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  38691. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  38692. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  38693. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  38694. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  38695. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  38696. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  38697. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  38698. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  38699. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  38700. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  38701. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  38702. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  38703. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  38704. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  38705. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  38706. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  38707. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  38708. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  38709. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  38710. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  38711. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  38712. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  38713. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  38714. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  38715. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  38716. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  38717. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  38718. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  38719. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  38720. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  38721. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  38722. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  38723. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  38724. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  38725. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  38726. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  38727. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  38728. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  38729. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  38730. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  38731. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  38732. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  38733. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  38734. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  38735. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  38736. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  38737. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  38738. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  38739. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  38740. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  38741. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  38742. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  38743. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  38744. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  38745. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  38746. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  38747. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  38748. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  38749. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  38750. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  38751. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  38752. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  38753. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  38754. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  38755. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  38756. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  38757. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  38758. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  38759. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  38760. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  38761. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  38762. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  38763. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  38764. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  38765. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  38766. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  38767. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  38768. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  38769. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  38770. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  38771. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  38772. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  38773. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  38774. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  38775. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  38776. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  38777. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  38778. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  38779. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  38780. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  38781. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  38782. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  38783. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  38784. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  38785. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  38786. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  38787. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  38788. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  38789. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  38790. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  38791. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  38792. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  38793. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  38794. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  38795. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  38796. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  38797. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  38798. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  38799. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  38800. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  38801. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  38802. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  38803. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  38804. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  38805. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  38806. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  38807. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  38808. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  38809. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  38810. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  38811. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  38812. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  38813. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  38814. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  38815. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  38816. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  38817. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  38818. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  38819. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  38820. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  38821. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  38822. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  38823. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  38824. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  38825. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  38826. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  38827. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  38828. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  38829. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  38830. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  38831. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  38832. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  38833. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  38834. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  38835. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  38836. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  38837. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  38838. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  38839. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  38840. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  38841. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  38842. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  38843. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  38844. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  38845. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  38846. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  38847. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  38848. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  38849. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  38850. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  38851. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  38852. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  38853. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  38854. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  38855. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  38856. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  38857. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  38858. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  38859. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  38860. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  38861. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  38862. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  38863. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  38864. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  38865. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  38866. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  38867. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  38868. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  38869. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  38870. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  38871. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  38872. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  38873. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  38874. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  38875. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  38876. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  38877. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  38878. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  38879. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  38880. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  38881. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  38882. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  38883. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  38884. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  38885. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  38886. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  38887. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  38888. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  38889. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  38890. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  38891. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  38892. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  38893. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  38894. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  38895. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  38896. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  38897. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  38898. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  38899. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  38900. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  38901. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  38902. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  38903. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  38904. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  38905. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  38906. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  38907. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  38908. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  38909. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  38910. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  38911. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  38912. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  38913. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  38914. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  38915. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  38916. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  38917. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  38918. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  38919. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  38920. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  38921. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  38922. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  38923. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  38924. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  38925. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  38926. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  38927. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  38928. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  38929. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  38930. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  38931. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  38932. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  38933. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  38934. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  38935. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  38936. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  38937. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  38938. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  38939. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  38940. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  38941. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  38942. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  38943. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  38944. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  38945. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  38946. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  38947. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  38948. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  38949. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  38950. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  38951. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  38952. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  38953. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  38954. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  38955. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  38956. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  38957. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  38958. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  38959. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  38960. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  38961. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  38962. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  38963. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  38964. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  38965. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  38966. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  38967. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  38968. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  38969. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  38970. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  38971. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  38972. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  38973. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  38974. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  38975. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  38976. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  38977. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  38978. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  38979. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  38980. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  38981. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  38982. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  38983. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  38984. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  38985. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  38986. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  38987. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  38988. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  38989. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  38990. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  38991. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  38992. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  38993. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  38994. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  38995. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  38996. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  38997. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  38998. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  38999. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  39000. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  39001. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  39002. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  39003. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  39004. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  39005. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  39006. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  39007. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  39008. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  39009. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  39010. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  39011. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  39012. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  39013. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  39014. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  39015. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  39016. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  39017. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  39018. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  39019. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  39020. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  39021. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  39022. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  39023. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  39024. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  39025. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  39026. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  39027. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  39028. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  39029. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  39030. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  39031. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  39032. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  39033. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  39034. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  39035. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  39036. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  39037. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  39038. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  39039. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  39040. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  39041. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  39042. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  39043. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  39044. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  39045. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  39046. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  39047. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  39048. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  39049. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  39050. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  39051. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  39052. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  39053. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  39054. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  39055. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  39056. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  39057. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  39058. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  39059. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  39060. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  39061. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  39062. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  39063. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  39064. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  39065. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  39066. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  39067. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  39068. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  39069. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  39070. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  39071. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  39072. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  39073. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  39074. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  39075. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  39076. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  39077. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  39078. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  39079. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  39080. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  39081. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  39082. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  39083. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  39084. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  39085. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  39086. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  39087. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  39088. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  39089. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  39090. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  39091. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  39092. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  39093. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  39094. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  39095. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  39096. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  39097. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  39098. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  39099. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  39100. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  39101. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  39102. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  39103. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  39104. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  39105. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  39106. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  39107. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  39108. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  39109. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  39110. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  39111. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  39112. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  39113. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  39114. 0x94, 0x82, 0x70
  39115. };
  39116. static const byte rnd_87[] = {
  39117. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  39118. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  39119. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  39120. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  39121. };
  39122. static const byte sig_87[] = {
  39123. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  39124. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  39125. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  39126. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  39127. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  39128. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  39129. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  39130. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  39131. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  39132. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  39133. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  39134. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  39135. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  39136. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  39137. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  39138. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  39139. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  39140. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  39141. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  39142. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  39143. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  39144. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  39145. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  39146. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  39147. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  39148. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  39149. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  39150. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  39151. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  39152. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  39153. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  39154. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  39155. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  39156. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  39157. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  39158. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  39159. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  39160. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  39161. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  39162. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  39163. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  39164. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  39165. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  39166. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  39167. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  39168. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  39169. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  39170. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  39171. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  39172. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  39173. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  39174. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  39175. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  39176. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  39177. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  39178. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  39179. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  39180. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  39181. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  39182. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  39183. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  39184. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  39185. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  39186. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  39187. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  39188. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  39189. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  39190. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  39191. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  39192. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  39193. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  39194. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  39195. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  39196. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  39197. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  39198. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  39199. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  39200. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  39201. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  39202. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  39203. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  39204. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  39205. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  39206. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  39207. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  39208. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  39209. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  39210. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  39211. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  39212. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  39213. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  39214. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  39215. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  39216. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  39217. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  39218. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  39219. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  39220. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  39221. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  39222. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  39223. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  39224. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  39225. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  39226. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  39227. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  39228. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  39229. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  39230. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  39231. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  39232. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  39233. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  39234. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  39235. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  39236. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  39237. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  39238. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  39239. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  39240. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  39241. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  39242. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  39243. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  39244. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  39245. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  39246. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  39247. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  39248. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  39249. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  39250. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  39251. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  39252. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  39253. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  39254. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  39255. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  39256. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  39257. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  39258. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  39259. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  39260. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  39261. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  39262. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  39263. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  39264. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  39265. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  39266. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  39267. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  39268. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  39269. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  39270. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  39271. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  39272. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  39273. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  39274. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  39275. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  39276. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  39277. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  39278. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  39279. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  39280. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  39281. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  39282. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  39283. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  39284. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  39285. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  39286. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  39287. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  39288. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  39289. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  39290. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  39291. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  39292. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  39293. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  39294. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  39295. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  39296. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  39297. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  39298. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  39299. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  39300. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  39301. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  39302. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  39303. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  39304. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  39305. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  39306. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  39307. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  39308. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  39309. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  39310. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  39311. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  39312. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  39313. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  39314. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  39315. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  39316. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  39317. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  39318. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  39319. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  39320. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  39321. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  39322. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  39323. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  39324. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  39325. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  39326. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  39327. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  39328. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  39329. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  39330. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  39331. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  39332. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  39333. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  39334. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  39335. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  39336. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  39337. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  39338. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  39339. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  39340. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  39341. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  39342. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  39343. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  39344. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  39345. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  39346. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  39347. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  39348. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  39349. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  39350. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  39351. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  39352. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  39353. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  39354. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  39355. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  39356. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  39357. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  39358. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  39359. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  39360. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  39361. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  39362. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  39363. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  39364. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  39365. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  39366. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  39367. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  39368. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  39369. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  39370. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  39371. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  39372. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  39373. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  39374. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  39375. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  39376. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  39377. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  39378. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  39379. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  39380. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  39381. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  39382. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  39383. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  39384. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  39385. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  39386. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  39387. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  39388. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  39389. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  39390. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  39391. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  39392. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  39393. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  39394. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  39395. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  39396. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  39397. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  39398. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  39399. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  39400. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  39401. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  39402. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  39403. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  39404. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  39405. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  39406. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  39407. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  39408. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  39409. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  39410. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  39411. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  39412. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  39413. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  39414. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  39415. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  39416. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  39417. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  39418. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  39419. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  39420. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  39421. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  39422. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  39423. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  39424. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  39425. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  39426. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  39427. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  39428. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  39429. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  39430. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  39431. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  39432. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  39433. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  39434. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  39435. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  39436. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  39437. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  39438. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  39439. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  39440. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  39441. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  39442. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  39443. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  39444. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  39445. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  39446. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  39447. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  39448. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  39449. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  39450. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  39451. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  39452. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  39453. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  39454. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  39455. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  39456. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  39457. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  39458. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  39459. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  39460. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  39461. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  39462. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  39463. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  39464. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  39465. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  39466. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  39467. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  39468. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  39469. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  39470. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  39471. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  39472. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  39473. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  39474. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  39475. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  39476. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  39477. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  39478. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  39479. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  39480. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  39481. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  39482. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  39483. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  39484. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  39485. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  39486. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  39487. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  39488. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  39489. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  39490. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  39491. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  39492. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  39493. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  39494. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  39495. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  39496. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  39497. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  39498. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  39499. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  39500. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  39501. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  39502. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  39503. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  39504. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  39505. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  39506. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  39507. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  39508. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  39509. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  39510. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  39511. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  39512. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  39513. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  39514. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  39515. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  39516. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  39517. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  39518. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  39519. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  39520. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  39521. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  39522. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  39523. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  39524. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  39525. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  39526. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  39527. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  39528. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  39529. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  39530. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  39531. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  39532. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  39533. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  39534. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  39535. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  39536. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  39537. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  39538. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  39539. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  39540. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  39541. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  39542. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  39543. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  39544. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  39545. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  39546. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  39547. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  39548. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  39549. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  39550. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  39551. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  39552. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  39553. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  39554. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  39555. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  39556. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  39557. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  39558. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  39559. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  39560. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  39561. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  39562. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  39563. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  39564. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  39565. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  39566. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  39567. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  39568. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  39569. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  39570. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  39571. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  39572. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  39573. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  39574. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  39575. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  39576. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  39577. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  39578. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  39579. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  39580. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  39581. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  39582. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  39583. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  39584. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  39585. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  39586. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  39587. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  39588. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  39589. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  39590. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  39591. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  39592. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  39593. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  39594. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  39595. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  39596. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  39597. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  39598. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  39599. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  39600. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  39601. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  39602. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  39603. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  39604. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  39605. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  39606. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  39607. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  39608. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  39609. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  39610. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  39611. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  39612. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  39613. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  39614. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  39615. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  39616. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  39617. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  39618. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  39619. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  39620. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  39621. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  39622. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  39623. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  39624. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  39625. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  39626. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  39627. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  39628. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  39629. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  39630. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  39631. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  39632. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  39633. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  39634. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  39635. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  39636. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  39637. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  39638. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  39639. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  39640. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  39641. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  39642. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  39643. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  39644. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  39645. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  39646. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  39647. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  39648. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  39649. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  39650. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  39651. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  39652. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  39653. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  39654. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  39655. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  39656. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  39657. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  39658. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  39659. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  39660. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  39661. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  39662. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  39663. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  39664. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  39665. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  39666. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  39667. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  39668. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  39669. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  39670. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  39671. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  39672. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  39673. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  39674. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  39675. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  39676. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  39677. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  39678. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  39679. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  39680. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  39681. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  39682. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  39683. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  39684. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  39685. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  39686. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  39687. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  39688. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  39689. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  39690. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  39691. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  39692. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  39693. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  39694. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  39695. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  39696. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  39697. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39698. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39699. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39700. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  39701. 0x27, 0x2C, 0x32
  39702. };
  39703. #endif
  39704. byte sig[DILITHIUM_MAX_SIG_SIZE];
  39705. word32 sigLen;
  39706. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39707. ExpectNotNull(key);
  39708. if (key != NULL) {
  39709. XMEMSET(key, 0, sizeof(*key));
  39710. }
  39711. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  39712. #ifndef WOLFSSL_NO_ML_DSA_44
  39713. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  39714. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  39715. 0);
  39716. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  39717. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  39718. sig, &sigLen, key, rnd_44), 0);
  39719. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  39720. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  39721. #endif
  39722. #ifndef WOLFSSL_NO_ML_DSA_65
  39723. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  39724. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  39725. 0);
  39726. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  39727. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  39728. sig, &sigLen, key, rnd_65), 0);
  39729. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  39730. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  39731. #endif
  39732. #ifndef WOLFSSL_NO_ML_DSA_87
  39733. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  39734. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  39735. 0);
  39736. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  39737. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  39738. sig, &sigLen, key, rnd_87), 0);
  39739. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  39740. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  39741. #endif
  39742. wc_dilithium_free(key);
  39743. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39744. #endif
  39745. return EXPECT_RESULT();
  39746. }
  39747. static int test_wc_dilithium_verify_kats(void)
  39748. {
  39749. EXPECT_DECLS;
  39750. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  39751. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  39752. dilithium_key* key;
  39753. int res;
  39754. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39755. #ifndef WOLFSSL_NO_ML_DSA_44
  39756. static const byte pk_44[] = {
  39757. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  39758. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  39759. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  39760. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  39761. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  39762. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  39763. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  39764. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  39765. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  39766. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  39767. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  39768. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  39769. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  39770. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  39771. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  39772. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  39773. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  39774. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  39775. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  39776. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  39777. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  39778. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  39779. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  39780. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  39781. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  39782. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  39783. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  39784. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  39785. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  39786. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  39787. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  39788. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  39789. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  39790. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  39791. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  39792. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  39793. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  39794. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  39795. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  39796. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  39797. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  39798. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  39799. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  39800. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  39801. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  39802. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  39803. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  39804. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  39805. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  39806. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  39807. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  39808. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  39809. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  39810. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  39811. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  39812. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  39813. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  39814. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  39815. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  39816. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  39817. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  39818. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  39819. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  39820. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  39821. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  39822. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  39823. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  39824. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  39825. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  39826. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  39827. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  39828. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  39829. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  39830. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  39831. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  39832. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  39833. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  39834. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  39835. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  39836. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  39837. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  39838. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  39839. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  39840. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  39841. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  39842. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  39843. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  39844. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  39845. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  39846. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  39847. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  39848. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  39849. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  39850. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  39851. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  39852. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  39853. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  39854. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  39855. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  39856. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  39857. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  39858. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  39859. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  39860. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  39861. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  39862. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  39863. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  39864. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  39865. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  39866. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  39867. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  39868. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  39869. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  39870. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  39871. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  39872. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  39873. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  39874. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  39875. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  39876. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  39877. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  39878. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  39879. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  39880. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  39881. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  39882. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  39883. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  39884. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  39885. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  39886. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  39887. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  39888. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  39889. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  39890. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  39891. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  39892. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  39893. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  39894. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  39895. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  39896. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  39897. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  39898. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  39899. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  39900. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  39901. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  39902. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  39903. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  39904. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  39905. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  39906. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  39907. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  39908. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  39909. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  39910. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  39911. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  39912. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  39913. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  39914. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  39915. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  39916. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  39917. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  39918. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  39919. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  39920. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  39921. };
  39922. static const byte msg_44[] = {
  39923. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  39924. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  39925. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  39926. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  39927. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  39928. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  39929. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  39930. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  39931. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  39932. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  39933. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  39934. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  39935. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  39936. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  39937. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  39938. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  39939. };
  39940. static const byte sig_44[] = {
  39941. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  39942. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  39943. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  39944. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  39945. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  39946. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  39947. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  39948. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  39949. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  39950. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  39951. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  39952. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  39953. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  39954. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  39955. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  39956. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  39957. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  39958. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  39959. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  39960. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  39961. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  39962. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  39963. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  39964. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  39965. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  39966. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  39967. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  39968. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  39969. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  39970. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  39971. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  39972. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  39973. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  39974. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  39975. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  39976. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  39977. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  39978. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  39979. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  39980. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  39981. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  39982. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  39983. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  39984. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  39985. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  39986. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  39987. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  39988. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  39989. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  39990. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  39991. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  39992. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  39993. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  39994. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  39995. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  39996. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  39997. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  39998. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  39999. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  40000. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  40001. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  40002. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  40003. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  40004. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  40005. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  40006. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  40007. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  40008. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  40009. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  40010. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  40011. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  40012. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  40013. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  40014. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  40015. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  40016. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  40017. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  40018. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  40019. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  40020. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  40021. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  40022. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  40023. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  40024. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  40025. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  40026. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  40027. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  40028. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  40029. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  40030. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  40031. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  40032. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  40033. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  40034. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  40035. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  40036. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  40037. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  40038. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  40039. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  40040. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  40041. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  40042. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  40043. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  40044. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  40045. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  40046. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  40047. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  40048. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  40049. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  40050. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  40051. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  40052. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  40053. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  40054. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  40055. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  40056. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  40057. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  40058. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  40059. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  40060. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  40061. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  40062. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  40063. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  40064. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  40065. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  40066. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  40067. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  40068. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  40069. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  40070. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  40071. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  40072. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  40073. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  40074. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  40075. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  40076. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  40077. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  40078. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  40079. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  40080. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  40081. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  40082. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  40083. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  40084. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  40085. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  40086. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  40087. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  40088. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  40089. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  40090. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  40091. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  40092. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  40093. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  40094. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  40095. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  40096. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  40097. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  40098. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  40099. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  40100. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  40101. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  40102. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  40103. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  40104. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  40105. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  40106. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  40107. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  40108. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  40109. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  40110. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  40111. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  40112. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  40113. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  40114. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  40115. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  40116. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  40117. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  40118. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  40119. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  40120. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  40121. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  40122. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  40123. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  40124. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  40125. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  40126. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  40127. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  40128. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  40129. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  40130. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  40131. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  40132. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  40133. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  40134. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  40135. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  40136. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  40137. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  40138. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  40139. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  40140. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  40141. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  40142. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  40143. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  40144. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  40145. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  40146. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  40147. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  40148. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  40149. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  40150. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  40151. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  40152. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  40153. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  40154. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  40155. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  40156. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  40157. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  40158. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  40159. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  40160. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  40161. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  40162. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  40163. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  40164. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  40165. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  40166. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  40167. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  40168. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  40169. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  40170. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  40171. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  40172. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  40173. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  40174. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  40175. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  40176. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  40177. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  40178. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  40179. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  40180. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  40181. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  40182. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  40183. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  40184. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  40185. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  40186. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  40187. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  40188. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  40189. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  40190. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  40191. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  40192. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  40193. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  40194. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  40195. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  40196. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  40197. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  40198. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  40199. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  40200. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  40201. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  40202. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  40203. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  40204. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  40205. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  40206. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  40207. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  40208. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  40209. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  40210. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  40211. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  40212. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  40213. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  40214. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  40215. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  40216. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  40217. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  40218. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  40219. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  40220. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  40221. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  40222. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  40223. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  40224. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  40225. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  40226. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  40227. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  40228. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  40229. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  40230. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  40231. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  40232. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  40233. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  40234. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  40235. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  40236. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  40237. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  40238. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  40239. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  40240. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40241. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40242. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40243. 0x11, 0x19, 0x28, 0x34
  40244. };
  40245. #endif
  40246. #ifndef WOLFSSL_NO_ML_DSA_65
  40247. static const byte pk_65[] = {
  40248. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  40249. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  40250. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  40251. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  40252. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  40253. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  40254. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  40255. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  40256. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  40257. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  40258. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  40259. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  40260. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  40261. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  40262. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  40263. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  40264. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  40265. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  40266. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  40267. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  40268. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  40269. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  40270. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  40271. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  40272. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  40273. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  40274. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  40275. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  40276. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  40277. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  40278. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  40279. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  40280. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  40281. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  40282. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  40283. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  40284. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  40285. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  40286. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  40287. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  40288. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  40289. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  40290. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  40291. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  40292. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  40293. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  40294. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  40295. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  40296. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  40297. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  40298. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  40299. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  40300. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  40301. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  40302. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  40303. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  40304. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  40305. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  40306. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  40307. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  40308. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  40309. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  40310. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  40311. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  40312. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  40313. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  40314. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  40315. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  40316. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  40317. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  40318. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  40319. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  40320. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  40321. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  40322. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  40323. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  40324. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  40325. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  40326. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  40327. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  40328. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  40329. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  40330. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  40331. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  40332. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  40333. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  40334. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  40335. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  40336. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  40337. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  40338. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  40339. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  40340. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  40341. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  40342. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  40343. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  40344. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  40345. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  40346. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  40347. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  40348. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  40349. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  40350. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  40351. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  40352. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  40353. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  40354. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  40355. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  40356. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  40357. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  40358. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  40359. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  40360. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  40361. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  40362. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  40363. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  40364. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  40365. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  40366. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  40367. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  40368. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  40369. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  40370. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  40371. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  40372. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  40373. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  40374. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  40375. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  40376. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  40377. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  40378. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  40379. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  40380. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  40381. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  40382. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  40383. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  40384. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  40385. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  40386. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  40387. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  40388. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  40389. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  40390. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  40391. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  40392. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  40393. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  40394. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  40395. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  40396. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  40397. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  40398. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  40399. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  40400. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  40401. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  40402. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  40403. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  40404. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  40405. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  40406. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  40407. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  40408. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  40409. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  40410. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  40411. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  40412. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  40413. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  40414. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  40415. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  40416. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  40417. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  40418. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  40419. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  40420. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  40421. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  40422. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  40423. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  40424. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  40425. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  40426. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  40427. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  40428. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  40429. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  40430. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  40431. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  40432. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  40433. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  40434. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  40435. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  40436. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  40437. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  40438. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  40439. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  40440. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  40441. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  40442. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  40443. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  40444. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  40445. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  40446. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  40447. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  40448. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  40449. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  40450. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  40451. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  40452. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  40453. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  40454. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  40455. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  40456. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  40457. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  40458. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  40459. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  40460. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  40461. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  40462. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  40463. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  40464. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  40465. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  40466. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  40467. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  40468. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  40469. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  40470. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  40471. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  40472. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  40473. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  40474. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  40475. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  40476. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  40477. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  40478. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  40479. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  40480. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  40481. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  40482. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  40483. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  40484. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  40485. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  40486. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  40487. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  40488. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  40489. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  40490. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  40491. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  40492. };
  40493. static const byte msg_65[] = {
  40494. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  40495. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  40496. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  40497. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  40498. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  40499. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  40500. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  40501. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  40502. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  40503. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  40504. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  40505. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  40506. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  40507. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  40508. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  40509. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  40510. };
  40511. static const byte sig_65[] = {
  40512. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  40513. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  40514. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  40515. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  40516. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  40517. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  40518. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  40519. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  40520. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  40521. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  40522. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  40523. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  40524. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  40525. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  40526. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  40527. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  40528. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  40529. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  40530. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  40531. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  40532. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  40533. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  40534. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  40535. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  40536. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  40537. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  40538. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  40539. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  40540. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  40541. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  40542. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  40543. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  40544. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  40545. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  40546. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  40547. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  40548. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  40549. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  40550. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  40551. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  40552. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  40553. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  40554. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  40555. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  40556. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  40557. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  40558. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  40559. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  40560. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  40561. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  40562. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  40563. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  40564. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  40565. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  40566. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  40567. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  40568. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  40569. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  40570. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  40571. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  40572. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  40573. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  40574. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  40575. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  40576. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  40577. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  40578. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  40579. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  40580. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  40581. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  40582. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  40583. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  40584. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  40585. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  40586. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  40587. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  40588. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  40589. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  40590. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  40591. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  40592. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  40593. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  40594. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  40595. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  40596. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  40597. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  40598. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  40599. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  40600. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  40601. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  40602. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  40603. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  40604. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  40605. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  40606. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  40607. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  40608. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  40609. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  40610. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  40611. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  40612. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  40613. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  40614. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  40615. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  40616. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  40617. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  40618. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  40619. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  40620. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  40621. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  40622. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  40623. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  40624. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  40625. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  40626. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  40627. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  40628. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  40629. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  40630. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  40631. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  40632. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  40633. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  40634. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  40635. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  40636. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  40637. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  40638. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  40639. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  40640. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  40641. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  40642. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  40643. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  40644. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  40645. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  40646. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  40647. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  40648. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  40649. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  40650. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  40651. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  40652. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  40653. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  40654. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  40655. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  40656. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  40657. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  40658. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  40659. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  40660. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  40661. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  40662. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  40663. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  40664. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  40665. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  40666. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  40667. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  40668. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  40669. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  40670. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  40671. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  40672. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  40673. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  40674. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  40675. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  40676. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  40677. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  40678. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  40679. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  40680. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  40681. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  40682. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  40683. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  40684. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  40685. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  40686. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  40687. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  40688. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  40689. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  40690. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  40691. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  40692. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  40693. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  40694. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  40695. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  40696. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  40697. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  40698. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  40699. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  40700. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  40701. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  40702. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  40703. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  40704. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  40705. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  40706. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  40707. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  40708. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  40709. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  40710. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  40711. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  40712. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  40713. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  40714. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  40715. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  40716. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  40717. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  40718. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  40719. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  40720. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  40721. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  40722. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  40723. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  40724. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  40725. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  40726. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  40727. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  40728. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  40729. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  40730. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  40731. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  40732. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  40733. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  40734. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  40735. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  40736. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  40737. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  40738. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  40739. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  40740. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  40741. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  40742. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  40743. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  40744. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  40745. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  40746. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  40747. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  40748. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  40749. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  40750. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  40751. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  40752. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  40753. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  40754. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  40755. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  40756. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  40757. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  40758. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  40759. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  40760. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  40761. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  40762. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  40763. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  40764. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  40765. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  40766. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  40767. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  40768. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  40769. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  40770. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  40771. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  40772. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  40773. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  40774. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  40775. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  40776. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  40777. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  40778. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  40779. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  40780. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  40781. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  40782. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  40783. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  40784. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  40785. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  40786. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  40787. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  40788. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  40789. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  40790. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  40791. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  40792. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  40793. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  40794. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  40795. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  40796. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  40797. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  40798. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  40799. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  40800. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  40801. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  40802. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  40803. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  40804. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  40805. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  40806. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  40807. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  40808. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  40809. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  40810. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  40811. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  40812. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  40813. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  40814. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  40815. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  40816. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  40817. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  40818. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  40819. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  40820. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  40821. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  40822. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  40823. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  40824. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  40825. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  40826. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  40827. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  40828. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  40829. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  40830. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  40831. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  40832. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  40833. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  40834. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  40835. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  40836. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  40837. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  40838. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  40839. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  40840. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  40841. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  40842. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  40843. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  40844. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  40845. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  40846. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  40847. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  40848. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  40849. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  40850. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  40851. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  40852. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  40853. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  40854. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  40855. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  40856. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  40857. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  40858. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  40859. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  40860. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  40861. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  40862. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  40863. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  40864. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  40865. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  40866. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  40867. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  40868. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  40869. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  40870. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  40871. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  40872. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  40873. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  40874. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  40875. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  40876. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  40877. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  40878. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  40879. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  40880. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  40881. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  40882. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  40883. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  40884. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  40885. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  40886. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  40887. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  40888. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  40889. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  40890. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  40891. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  40892. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  40893. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  40894. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  40895. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  40896. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  40897. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  40898. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  40899. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  40900. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  40901. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  40902. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  40903. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  40904. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  40905. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  40906. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  40907. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  40908. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  40909. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  40910. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  40911. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  40912. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  40913. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  40914. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  40915. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  40916. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  40917. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  40918. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  40919. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  40920. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  40921. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  40922. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40923. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40924. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40925. 0x0B, 0x10, 0x18, 0x1A, 0x21
  40926. };
  40927. #endif
  40928. #ifndef WOLFSSL_NO_ML_DSA_87
  40929. static const byte pk_87[] = {
  40930. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  40931. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  40932. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  40933. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  40934. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  40935. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  40936. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  40937. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  40938. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  40939. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  40940. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  40941. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  40942. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  40943. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  40944. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  40945. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  40946. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  40947. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  40948. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  40949. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  40950. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  40951. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  40952. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  40953. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  40954. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  40955. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  40956. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  40957. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  40958. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  40959. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  40960. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  40961. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  40962. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  40963. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  40964. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  40965. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  40966. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  40967. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  40968. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  40969. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  40970. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  40971. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  40972. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  40973. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  40974. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  40975. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  40976. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  40977. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  40978. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  40979. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  40980. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  40981. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  40982. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  40983. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  40984. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  40985. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  40986. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  40987. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  40988. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  40989. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  40990. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  40991. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  40992. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  40993. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  40994. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  40995. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  40996. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  40997. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  40998. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  40999. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  41000. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  41001. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  41002. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  41003. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  41004. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  41005. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  41006. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  41007. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  41008. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  41009. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  41010. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  41011. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  41012. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  41013. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  41014. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  41015. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  41016. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  41017. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  41018. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  41019. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  41020. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  41021. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  41022. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  41023. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  41024. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  41025. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  41026. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  41027. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  41028. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  41029. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  41030. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  41031. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  41032. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  41033. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  41034. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  41035. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  41036. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  41037. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  41038. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  41039. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  41040. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  41041. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  41042. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  41043. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  41044. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  41045. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  41046. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  41047. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  41048. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  41049. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  41050. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  41051. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  41052. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  41053. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  41054. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  41055. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  41056. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  41057. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  41058. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  41059. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  41060. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  41061. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  41062. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  41063. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  41064. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  41065. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  41066. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  41067. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  41068. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  41069. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  41070. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  41071. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  41072. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  41073. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  41074. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  41075. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  41076. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  41077. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  41078. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  41079. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  41080. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  41081. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  41082. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  41083. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  41084. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  41085. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  41086. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  41087. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  41088. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  41089. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  41090. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  41091. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  41092. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  41093. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  41094. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  41095. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  41096. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  41097. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  41098. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  41099. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  41100. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  41101. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  41102. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  41103. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  41104. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  41105. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  41106. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  41107. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  41108. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  41109. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  41110. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  41111. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  41112. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  41113. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  41114. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  41115. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  41116. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  41117. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  41118. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  41119. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  41120. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  41121. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  41122. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  41123. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  41124. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  41125. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  41126. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  41127. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  41128. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  41129. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  41130. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  41131. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  41132. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  41133. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  41134. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  41135. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  41136. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  41137. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  41138. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  41139. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  41140. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  41141. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  41142. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  41143. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  41144. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  41145. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  41146. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  41147. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  41148. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  41149. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  41150. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  41151. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  41152. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  41153. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  41154. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  41155. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  41156. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  41157. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  41158. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  41159. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  41160. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  41161. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  41162. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  41163. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  41164. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  41165. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  41166. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  41167. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  41168. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  41169. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  41170. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  41171. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  41172. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  41173. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  41174. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  41175. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  41176. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  41177. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  41178. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  41179. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  41180. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  41181. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  41182. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  41183. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  41184. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  41185. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  41186. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  41187. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  41188. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  41189. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  41190. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  41191. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  41192. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  41193. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  41194. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  41195. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  41196. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  41197. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  41198. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  41199. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  41200. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  41201. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  41202. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  41203. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  41204. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  41205. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  41206. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  41207. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  41208. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  41209. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  41210. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  41211. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  41212. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  41213. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  41214. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  41215. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  41216. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  41217. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  41218. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  41219. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  41220. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  41221. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  41222. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  41223. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  41224. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  41225. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  41226. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  41227. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  41228. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  41229. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  41230. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  41231. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  41232. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  41233. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  41234. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  41235. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  41236. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  41237. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  41238. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  41239. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  41240. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  41241. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  41242. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  41243. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  41244. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  41245. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  41246. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  41247. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  41248. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  41249. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  41250. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  41251. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  41252. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  41253. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  41254. };
  41255. static const byte msg_87[] = {
  41256. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  41257. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  41258. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  41259. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  41260. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  41261. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  41262. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  41263. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  41264. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  41265. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  41266. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  41267. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  41268. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  41269. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  41270. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  41271. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  41272. };
  41273. static const byte sig_87[] = {
  41274. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  41275. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  41276. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  41277. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  41278. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  41279. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  41280. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  41281. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  41282. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  41283. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  41284. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  41285. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  41286. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  41287. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  41288. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  41289. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  41290. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  41291. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  41292. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  41293. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  41294. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  41295. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  41296. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  41297. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  41298. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  41299. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  41300. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  41301. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  41302. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  41303. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  41304. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  41305. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  41306. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  41307. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  41308. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  41309. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  41310. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  41311. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  41312. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  41313. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  41314. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  41315. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  41316. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  41317. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  41318. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  41319. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  41320. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  41321. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  41322. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  41323. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  41324. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  41325. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  41326. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  41327. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  41328. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  41329. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  41330. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  41331. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  41332. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  41333. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  41334. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  41335. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  41336. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  41337. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  41338. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  41339. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  41340. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  41341. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  41342. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  41343. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  41344. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  41345. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  41346. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  41347. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  41348. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  41349. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  41350. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  41351. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  41352. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  41353. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  41354. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  41355. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  41356. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  41357. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  41358. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  41359. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  41360. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  41361. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  41362. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  41363. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  41364. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  41365. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  41366. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  41367. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  41368. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  41369. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  41370. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  41371. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  41372. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  41373. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  41374. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  41375. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  41376. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  41377. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  41378. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  41379. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  41380. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  41381. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  41382. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  41383. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  41384. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  41385. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  41386. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  41387. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  41388. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  41389. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  41390. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  41391. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  41392. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  41393. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  41394. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  41395. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  41396. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  41397. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  41398. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  41399. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  41400. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  41401. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  41402. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  41403. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  41404. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  41405. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  41406. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  41407. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  41408. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  41409. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  41410. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  41411. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  41412. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  41413. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  41414. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  41415. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  41416. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  41417. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  41418. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  41419. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  41420. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  41421. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  41422. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  41423. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  41424. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  41425. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  41426. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  41427. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  41428. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  41429. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  41430. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  41431. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  41432. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  41433. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  41434. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  41435. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  41436. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  41437. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  41438. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  41439. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  41440. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  41441. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  41442. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  41443. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  41444. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  41445. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  41446. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  41447. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  41448. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  41449. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  41450. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  41451. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  41452. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  41453. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  41454. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  41455. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  41456. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  41457. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  41458. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  41459. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  41460. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  41461. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  41462. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  41463. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  41464. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  41465. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  41466. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  41467. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  41468. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  41469. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  41470. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  41471. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  41472. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  41473. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  41474. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  41475. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  41476. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  41477. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  41478. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  41479. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  41480. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  41481. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  41482. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  41483. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  41484. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  41485. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  41486. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  41487. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  41488. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  41489. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  41490. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  41491. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  41492. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  41493. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  41494. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  41495. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  41496. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  41497. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  41498. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  41499. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  41500. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  41501. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  41502. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  41503. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  41504. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  41505. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  41506. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  41507. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  41508. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  41509. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  41510. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  41511. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  41512. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  41513. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  41514. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  41515. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  41516. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  41517. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  41518. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  41519. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  41520. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  41521. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  41522. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  41523. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  41524. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  41525. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  41526. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  41527. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  41528. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  41529. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  41530. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  41531. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  41532. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  41533. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  41534. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  41535. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  41536. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  41537. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  41538. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  41539. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  41540. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  41541. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  41542. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  41543. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  41544. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  41545. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  41546. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  41547. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  41548. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  41549. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  41550. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  41551. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  41552. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  41553. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  41554. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  41555. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  41556. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  41557. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  41558. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  41559. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  41560. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  41561. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  41562. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  41563. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  41564. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  41565. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  41566. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  41567. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  41568. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  41569. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  41570. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  41571. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  41572. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  41573. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  41574. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  41575. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  41576. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  41577. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  41578. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  41579. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  41580. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  41581. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  41582. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  41583. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  41584. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  41585. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  41586. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  41587. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  41588. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  41589. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  41590. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  41591. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  41592. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  41593. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  41594. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  41595. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  41596. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  41597. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  41598. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  41599. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  41600. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  41601. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  41602. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  41603. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  41604. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  41605. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  41606. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  41607. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  41608. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  41609. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  41610. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  41611. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  41612. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  41613. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  41614. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  41615. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  41616. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  41617. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  41618. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  41619. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  41620. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  41621. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  41622. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  41623. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  41624. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  41625. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  41626. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  41627. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  41628. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  41629. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  41630. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  41631. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  41632. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  41633. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  41634. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  41635. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  41636. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  41637. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  41638. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  41639. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  41640. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  41641. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  41642. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  41643. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  41644. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  41645. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  41646. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  41647. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  41648. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  41649. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  41650. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  41651. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  41652. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  41653. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  41654. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  41655. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  41656. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  41657. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  41658. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  41659. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  41660. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  41661. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  41662. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  41663. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  41664. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  41665. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  41666. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  41667. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  41668. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  41669. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  41670. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  41671. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  41672. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  41673. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  41674. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  41675. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  41676. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  41677. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  41678. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  41679. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  41680. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  41681. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  41682. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  41683. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  41684. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  41685. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  41686. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  41687. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  41688. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  41689. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  41690. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  41691. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  41692. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  41693. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  41694. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  41695. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  41696. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  41697. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  41698. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  41699. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  41700. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  41701. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  41702. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  41703. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  41704. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  41705. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  41706. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  41707. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  41708. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  41709. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  41710. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  41711. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  41712. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  41713. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  41714. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  41715. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  41716. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  41717. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  41718. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  41719. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  41720. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  41721. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  41722. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  41723. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  41724. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  41725. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  41726. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  41727. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  41728. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  41729. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  41730. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  41731. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  41732. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  41733. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  41734. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  41735. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  41736. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  41737. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  41738. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  41739. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  41740. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  41741. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  41742. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  41743. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  41744. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  41745. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  41746. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  41747. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  41748. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  41749. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  41750. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  41751. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  41752. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  41753. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  41754. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  41755. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  41756. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  41757. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  41758. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  41759. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  41760. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  41761. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  41762. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  41763. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  41764. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  41765. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  41766. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  41767. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  41768. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  41769. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  41770. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  41771. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  41772. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  41773. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  41774. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  41775. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  41776. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  41777. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  41778. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  41779. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  41780. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  41781. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  41782. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  41783. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  41784. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  41785. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  41786. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  41787. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  41788. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  41789. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  41790. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  41791. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  41792. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  41793. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  41794. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  41795. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  41796. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  41797. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  41798. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  41799. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  41800. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  41801. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  41802. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  41803. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  41804. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  41805. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  41806. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  41807. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  41808. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  41809. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  41810. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  41811. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  41812. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  41813. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  41814. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  41815. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  41816. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  41817. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  41818. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  41819. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  41820. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  41821. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  41822. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  41823. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  41824. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  41825. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  41826. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  41827. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  41828. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  41829. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  41830. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  41831. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  41832. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  41833. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  41834. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  41835. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  41836. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  41837. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  41838. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  41839. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  41840. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  41841. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  41842. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  41843. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  41844. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  41845. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  41846. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  41847. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  41848. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  41849. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41850. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41851. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  41852. 0x29, 0x2E, 0x36
  41853. };
  41854. #endif
  41855. #else
  41856. #ifndef WOLFSSL_NO_ML_DSA_44
  41857. static const byte pk_44[] = {
  41858. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  41859. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  41860. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  41861. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  41862. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  41863. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  41864. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  41865. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  41866. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  41867. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  41868. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  41869. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  41870. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  41871. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  41872. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  41873. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  41874. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  41875. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  41876. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  41877. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  41878. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  41879. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  41880. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  41881. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  41882. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  41883. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  41884. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  41885. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  41886. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  41887. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  41888. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  41889. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  41890. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  41891. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  41892. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  41893. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  41894. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  41895. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  41896. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  41897. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  41898. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  41899. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  41900. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  41901. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  41902. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  41903. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  41904. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  41905. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  41906. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  41907. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  41908. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  41909. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  41910. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  41911. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  41912. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  41913. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  41914. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  41915. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  41916. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  41917. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  41918. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  41919. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  41920. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  41921. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  41922. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  41923. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  41924. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  41925. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  41926. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  41927. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  41928. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  41929. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  41930. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  41931. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  41932. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  41933. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  41934. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  41935. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  41936. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  41937. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  41938. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  41939. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  41940. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  41941. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  41942. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  41943. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  41944. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  41945. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  41946. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  41947. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  41948. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  41949. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  41950. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  41951. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  41952. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  41953. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  41954. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  41955. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  41956. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  41957. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  41958. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  41959. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  41960. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  41961. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  41962. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  41963. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  41964. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  41965. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  41966. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  41967. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  41968. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  41969. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  41970. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  41971. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  41972. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  41973. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  41974. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  41975. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  41976. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  41977. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  41978. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  41979. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  41980. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  41981. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  41982. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  41983. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  41984. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  41985. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  41986. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  41987. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  41988. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  41989. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  41990. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  41991. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  41992. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  41993. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  41994. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  41995. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  41996. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  41997. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  41998. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  41999. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  42000. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  42001. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  42002. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  42003. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  42004. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  42005. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  42006. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  42007. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  42008. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  42009. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  42010. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  42011. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  42012. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  42013. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  42014. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  42015. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  42016. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  42017. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  42018. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  42019. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  42020. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  42021. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  42022. };
  42023. static const byte msg_44[] = {
  42024. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  42025. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  42026. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  42027. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  42028. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  42029. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  42030. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  42031. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  42032. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  42033. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  42034. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  42035. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  42036. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  42037. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  42038. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  42039. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  42040. };
  42041. static const byte sig_44[] = {
  42042. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  42043. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  42044. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  42045. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  42046. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  42047. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  42048. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  42049. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  42050. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  42051. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  42052. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  42053. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  42054. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  42055. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  42056. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  42057. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  42058. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  42059. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  42060. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  42061. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  42062. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  42063. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  42064. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  42065. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  42066. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  42067. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  42068. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  42069. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  42070. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  42071. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  42072. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  42073. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  42074. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  42075. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  42076. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  42077. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  42078. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  42079. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  42080. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  42081. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  42082. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  42083. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  42084. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  42085. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  42086. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  42087. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  42088. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  42089. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  42090. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  42091. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  42092. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  42093. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  42094. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  42095. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  42096. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  42097. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  42098. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  42099. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  42100. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  42101. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  42102. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  42103. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  42104. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  42105. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  42106. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  42107. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  42108. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  42109. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  42110. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  42111. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  42112. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  42113. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  42114. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  42115. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  42116. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  42117. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  42118. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  42119. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  42120. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  42121. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  42122. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  42123. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  42124. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  42125. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  42126. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  42127. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  42128. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  42129. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  42130. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  42131. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  42132. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  42133. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  42134. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  42135. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  42136. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  42137. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  42138. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  42139. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  42140. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  42141. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  42142. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  42143. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  42144. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  42145. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  42146. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  42147. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  42148. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  42149. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  42150. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  42151. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  42152. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  42153. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  42154. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  42155. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  42156. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  42157. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  42158. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  42159. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  42160. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  42161. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  42162. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  42163. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  42164. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  42165. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  42166. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  42167. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  42168. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  42169. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  42170. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  42171. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  42172. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  42173. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  42174. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  42175. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  42176. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  42177. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  42178. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  42179. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  42180. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  42181. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  42182. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  42183. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  42184. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  42185. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  42186. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  42187. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  42188. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  42189. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  42190. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  42191. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  42192. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  42193. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  42194. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  42195. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  42196. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  42197. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  42198. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  42199. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  42200. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  42201. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  42202. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  42203. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  42204. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  42205. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  42206. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  42207. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  42208. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  42209. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  42210. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  42211. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  42212. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  42213. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  42214. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  42215. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  42216. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  42217. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  42218. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  42219. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  42220. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  42221. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  42222. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  42223. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  42224. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  42225. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  42226. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  42227. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  42228. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  42229. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  42230. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  42231. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  42232. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  42233. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  42234. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  42235. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  42236. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  42237. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  42238. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  42239. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  42240. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  42241. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  42242. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  42243. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  42244. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  42245. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  42246. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  42247. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  42248. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  42249. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  42250. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  42251. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  42252. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  42253. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  42254. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  42255. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  42256. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  42257. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  42258. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  42259. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  42260. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  42261. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  42262. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  42263. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  42264. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  42265. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  42266. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  42267. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  42268. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  42269. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  42270. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  42271. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  42272. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  42273. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  42274. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  42275. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  42276. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  42277. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  42278. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  42279. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  42280. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  42281. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  42282. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  42283. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  42284. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  42285. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  42286. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  42287. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  42288. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  42289. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  42290. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  42291. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  42292. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  42293. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  42294. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  42295. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  42296. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  42297. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  42298. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  42299. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  42300. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  42301. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  42302. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  42303. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  42304. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  42305. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  42306. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  42307. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  42308. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  42309. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  42310. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  42311. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  42312. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  42313. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  42314. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  42315. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  42316. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  42317. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  42318. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  42319. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  42320. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  42321. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  42322. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  42323. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  42324. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  42325. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  42326. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  42327. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  42328. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  42329. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  42330. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  42331. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  42332. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  42333. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  42334. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  42335. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  42336. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  42337. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  42338. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  42339. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  42340. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  42341. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  42342. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42343. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42344. 0x10, 0x18, 0x32, 0x3B
  42345. };
  42346. #endif
  42347. #ifndef WOLFSSL_NO_ML_DSA_65
  42348. static const byte pk_65[] = {
  42349. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  42350. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  42351. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  42352. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  42353. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  42354. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  42355. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  42356. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  42357. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  42358. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  42359. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  42360. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  42361. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  42362. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  42363. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  42364. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  42365. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  42366. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  42367. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  42368. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  42369. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  42370. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  42371. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  42372. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  42373. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  42374. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  42375. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  42376. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  42377. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  42378. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  42379. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  42380. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  42381. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  42382. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  42383. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  42384. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  42385. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  42386. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  42387. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  42388. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  42389. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  42390. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  42391. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  42392. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  42393. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  42394. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  42395. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  42396. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  42397. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  42398. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  42399. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  42400. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  42401. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  42402. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  42403. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  42404. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  42405. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  42406. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  42407. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  42408. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  42409. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  42410. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  42411. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  42412. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  42413. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  42414. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  42415. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  42416. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  42417. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  42418. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  42419. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  42420. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  42421. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  42422. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  42423. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  42424. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  42425. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  42426. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  42427. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  42428. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  42429. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  42430. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  42431. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  42432. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  42433. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  42434. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  42435. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  42436. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  42437. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  42438. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  42439. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  42440. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  42441. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  42442. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  42443. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  42444. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  42445. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  42446. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  42447. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  42448. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  42449. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  42450. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  42451. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  42452. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  42453. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  42454. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  42455. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  42456. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  42457. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  42458. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  42459. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  42460. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  42461. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  42462. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  42463. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  42464. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  42465. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  42466. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  42467. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  42468. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  42469. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  42470. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  42471. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  42472. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  42473. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  42474. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  42475. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  42476. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  42477. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  42478. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  42479. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  42480. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  42481. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  42482. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  42483. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  42484. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  42485. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  42486. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  42487. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  42488. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  42489. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  42490. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  42491. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  42492. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  42493. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  42494. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  42495. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  42496. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  42497. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  42498. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  42499. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  42500. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  42501. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  42502. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  42503. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  42504. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  42505. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  42506. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  42507. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  42508. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  42509. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  42510. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  42511. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  42512. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  42513. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  42514. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  42515. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  42516. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  42517. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  42518. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  42519. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  42520. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  42521. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  42522. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  42523. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  42524. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  42525. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  42526. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  42527. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  42528. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  42529. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  42530. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  42531. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  42532. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  42533. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  42534. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  42535. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  42536. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  42537. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  42538. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  42539. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  42540. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  42541. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  42542. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  42543. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  42544. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  42545. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  42546. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  42547. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  42548. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  42549. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  42550. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  42551. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  42552. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  42553. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  42554. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  42555. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  42556. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  42557. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  42558. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  42559. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  42560. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  42561. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  42562. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  42563. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  42564. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  42565. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  42566. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  42567. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  42568. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  42569. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  42570. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  42571. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  42572. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  42573. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  42574. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  42575. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  42576. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  42577. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  42578. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  42579. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  42580. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  42581. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  42582. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  42583. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  42584. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  42585. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  42586. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  42587. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  42588. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  42589. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  42590. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  42591. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  42592. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  42593. };
  42594. static const byte msg_65[] = {
  42595. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  42596. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  42597. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  42598. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  42599. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  42600. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  42601. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  42602. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  42603. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  42604. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  42605. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  42606. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  42607. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  42608. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  42609. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  42610. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  42611. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  42612. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  42613. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  42614. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  42615. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  42616. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  42617. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  42618. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  42619. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  42620. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  42621. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  42622. 0x8E, 0x99, 0xBB
  42623. };
  42624. static const byte sig_65[] = {
  42625. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  42626. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  42627. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  42628. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  42629. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  42630. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  42631. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  42632. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  42633. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  42634. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  42635. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  42636. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  42637. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  42638. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  42639. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  42640. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  42641. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  42642. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  42643. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  42644. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  42645. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  42646. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  42647. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  42648. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  42649. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  42650. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  42651. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  42652. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  42653. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  42654. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  42655. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  42656. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  42657. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  42658. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  42659. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  42660. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  42661. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  42662. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  42663. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  42664. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  42665. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  42666. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  42667. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  42668. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  42669. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  42670. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  42671. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  42672. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  42673. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  42674. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  42675. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  42676. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  42677. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  42678. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  42679. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  42680. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  42681. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  42682. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  42683. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  42684. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  42685. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  42686. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  42687. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  42688. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  42689. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  42690. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  42691. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  42692. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  42693. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  42694. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  42695. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  42696. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  42697. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  42698. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  42699. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  42700. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  42701. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  42702. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  42703. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  42704. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  42705. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  42706. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  42707. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  42708. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  42709. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  42710. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  42711. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  42712. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  42713. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  42714. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  42715. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  42716. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  42717. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  42718. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  42719. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  42720. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  42721. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  42722. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  42723. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  42724. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  42725. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  42726. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  42727. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  42728. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  42729. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  42730. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  42731. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  42732. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  42733. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  42734. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  42735. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  42736. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  42737. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  42738. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  42739. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  42740. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  42741. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  42742. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  42743. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  42744. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  42745. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  42746. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  42747. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  42748. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  42749. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  42750. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  42751. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  42752. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  42753. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  42754. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  42755. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  42756. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  42757. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  42758. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  42759. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  42760. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  42761. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  42762. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  42763. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  42764. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  42765. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  42766. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  42767. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  42768. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  42769. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  42770. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  42771. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  42772. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  42773. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  42774. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  42775. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  42776. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  42777. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  42778. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  42779. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  42780. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  42781. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  42782. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  42783. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  42784. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  42785. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  42786. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  42787. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  42788. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  42789. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  42790. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  42791. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  42792. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  42793. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  42794. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  42795. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  42796. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  42797. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  42798. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  42799. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  42800. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  42801. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  42802. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  42803. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  42804. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  42805. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  42806. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  42807. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  42808. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  42809. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  42810. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  42811. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  42812. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  42813. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  42814. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  42815. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  42816. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  42817. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  42818. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  42819. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  42820. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  42821. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  42822. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  42823. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  42824. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  42825. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  42826. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  42827. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  42828. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  42829. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  42830. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  42831. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  42832. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  42833. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  42834. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  42835. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  42836. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  42837. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  42838. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  42839. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  42840. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  42841. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  42842. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  42843. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  42844. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  42845. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  42846. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  42847. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  42848. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  42849. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  42850. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  42851. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  42852. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  42853. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  42854. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  42855. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  42856. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  42857. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  42858. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  42859. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  42860. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  42861. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  42862. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  42863. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  42864. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  42865. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  42866. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  42867. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  42868. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  42869. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  42870. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  42871. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  42872. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  42873. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  42874. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  42875. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  42876. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  42877. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  42878. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  42879. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  42880. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  42881. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  42882. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  42883. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  42884. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  42885. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  42886. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  42887. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  42888. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  42889. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  42890. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  42891. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  42892. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  42893. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  42894. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  42895. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  42896. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  42897. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  42898. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  42899. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  42900. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  42901. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  42902. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  42903. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  42904. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  42905. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  42906. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  42907. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  42908. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  42909. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  42910. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  42911. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  42912. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  42913. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  42914. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  42915. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  42916. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  42917. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  42918. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  42919. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  42920. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  42921. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  42922. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  42923. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  42924. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  42925. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  42926. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  42927. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  42928. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  42929. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  42930. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  42931. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  42932. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  42933. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  42934. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  42935. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  42936. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  42937. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  42938. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  42939. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  42940. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  42941. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  42942. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  42943. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  42944. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  42945. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  42946. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  42947. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  42948. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  42949. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  42950. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  42951. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  42952. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  42953. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  42954. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  42955. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  42956. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  42957. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  42958. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  42959. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  42960. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  42961. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  42962. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  42963. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  42964. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  42965. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  42966. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  42967. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  42968. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  42969. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  42970. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  42971. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  42972. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  42973. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  42974. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  42975. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  42976. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  42977. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  42978. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  42979. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  42980. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  42981. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  42982. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  42983. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  42984. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  42985. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  42986. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  42987. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  42988. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  42989. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  42990. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  42991. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  42992. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  42993. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  42994. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  42995. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  42996. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  42997. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  42998. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  42999. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  43000. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  43001. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  43002. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  43003. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  43004. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  43005. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  43006. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  43007. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  43008. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  43009. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  43010. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  43011. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  43012. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  43013. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  43014. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  43015. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  43016. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  43017. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  43018. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  43019. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  43020. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  43021. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  43022. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  43023. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  43024. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  43025. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  43026. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  43027. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  43028. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  43029. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  43030. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  43031. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  43032. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  43033. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  43034. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  43035. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43036. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43037. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  43038. 0x08, 0x0E, 0x12, 0x19, 0x20
  43039. };
  43040. #endif
  43041. #ifndef WOLFSSL_NO_ML_DSA_87
  43042. static const byte pk_87[] = {
  43043. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  43044. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  43045. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  43046. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  43047. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  43048. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  43049. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  43050. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  43051. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  43052. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  43053. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  43054. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  43055. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  43056. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  43057. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  43058. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  43059. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  43060. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  43061. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  43062. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  43063. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  43064. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  43065. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  43066. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  43067. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  43068. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  43069. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  43070. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  43071. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  43072. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  43073. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  43074. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  43075. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  43076. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  43077. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  43078. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  43079. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  43080. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  43081. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  43082. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  43083. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  43084. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  43085. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  43086. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  43087. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  43088. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  43089. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  43090. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  43091. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  43092. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  43093. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  43094. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  43095. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  43096. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  43097. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  43098. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  43099. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  43100. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  43101. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  43102. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  43103. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  43104. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  43105. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  43106. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  43107. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  43108. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  43109. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  43110. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  43111. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  43112. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  43113. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  43114. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  43115. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  43116. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  43117. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  43118. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  43119. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  43120. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  43121. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  43122. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  43123. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  43124. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  43125. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  43126. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  43127. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  43128. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  43129. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  43130. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  43131. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  43132. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  43133. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  43134. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  43135. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  43136. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  43137. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  43138. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  43139. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  43140. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  43141. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  43142. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  43143. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  43144. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  43145. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  43146. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  43147. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  43148. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  43149. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  43150. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  43151. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  43152. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  43153. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  43154. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  43155. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  43156. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  43157. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  43158. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  43159. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  43160. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  43161. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  43162. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  43163. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  43164. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  43165. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  43166. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  43167. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  43168. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  43169. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  43170. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  43171. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  43172. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  43173. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  43174. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  43175. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  43176. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  43177. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  43178. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  43179. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  43180. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  43181. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  43182. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  43183. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  43184. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  43185. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  43186. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  43187. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  43188. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  43189. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  43190. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  43191. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  43192. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  43193. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  43194. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  43195. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  43196. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  43197. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  43198. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  43199. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  43200. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  43201. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  43202. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  43203. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  43204. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  43205. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  43206. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  43207. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  43208. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  43209. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  43210. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  43211. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  43212. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  43213. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  43214. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  43215. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  43216. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  43217. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  43218. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  43219. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  43220. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  43221. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  43222. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  43223. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  43224. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  43225. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  43226. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  43227. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  43228. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  43229. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  43230. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  43231. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  43232. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  43233. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  43234. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  43235. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  43236. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  43237. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  43238. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  43239. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  43240. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  43241. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  43242. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  43243. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  43244. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  43245. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  43246. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  43247. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  43248. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  43249. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  43250. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  43251. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  43252. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  43253. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  43254. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  43255. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  43256. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  43257. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  43258. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  43259. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  43260. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  43261. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  43262. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  43263. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  43264. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  43265. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  43266. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  43267. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  43268. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  43269. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  43270. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  43271. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  43272. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  43273. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  43274. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  43275. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  43276. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  43277. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  43278. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  43279. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  43280. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  43281. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  43282. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  43283. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  43284. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  43285. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  43286. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  43287. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  43288. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  43289. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  43290. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  43291. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  43292. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  43293. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  43294. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  43295. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  43296. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  43297. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  43298. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  43299. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  43300. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  43301. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  43302. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  43303. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  43304. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  43305. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  43306. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  43307. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  43308. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  43309. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  43310. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  43311. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  43312. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  43313. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  43314. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  43315. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  43316. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  43317. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  43318. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  43319. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  43320. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  43321. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  43322. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  43323. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  43324. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  43325. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  43326. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  43327. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  43328. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  43329. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  43330. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  43331. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  43332. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  43333. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  43334. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  43335. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  43336. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  43337. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  43338. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  43339. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  43340. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  43341. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  43342. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  43343. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  43344. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  43345. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  43346. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  43347. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  43348. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  43349. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  43350. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  43351. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  43352. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  43353. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  43354. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  43355. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  43356. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  43357. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  43358. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  43359. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  43360. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  43361. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  43362. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  43363. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  43364. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  43365. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  43366. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  43367. };
  43368. static const byte msg_87[] = {
  43369. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  43370. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  43371. 0xC4, 0xC3, 0xED, 0x36
  43372. };
  43373. static const byte sig_87[] = {
  43374. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  43375. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  43376. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  43377. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  43378. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  43379. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  43380. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  43381. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  43382. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  43383. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  43384. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  43385. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  43386. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  43387. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  43388. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  43389. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  43390. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  43391. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  43392. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  43393. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  43394. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  43395. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  43396. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  43397. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  43398. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  43399. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  43400. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  43401. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  43402. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  43403. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  43404. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  43405. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  43406. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  43407. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  43408. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  43409. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  43410. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  43411. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  43412. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  43413. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  43414. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  43415. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  43416. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  43417. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  43418. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  43419. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  43420. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  43421. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  43422. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  43423. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  43424. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  43425. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  43426. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  43427. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  43428. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  43429. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  43430. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  43431. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  43432. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  43433. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  43434. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  43435. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  43436. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  43437. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  43438. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  43439. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  43440. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  43441. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  43442. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  43443. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  43444. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  43445. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  43446. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  43447. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  43448. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  43449. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  43450. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  43451. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  43452. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  43453. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  43454. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  43455. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  43456. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  43457. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  43458. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  43459. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  43460. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  43461. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  43462. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  43463. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  43464. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  43465. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  43466. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  43467. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  43468. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  43469. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  43470. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  43471. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  43472. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  43473. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  43474. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  43475. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  43476. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  43477. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  43478. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  43479. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  43480. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  43481. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  43482. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  43483. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  43484. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  43485. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  43486. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  43487. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  43488. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  43489. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  43490. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  43491. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  43492. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  43493. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  43494. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  43495. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  43496. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  43497. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  43498. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  43499. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  43500. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  43501. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  43502. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  43503. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  43504. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  43505. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  43506. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  43507. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  43508. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  43509. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  43510. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  43511. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  43512. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  43513. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  43514. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  43515. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  43516. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  43517. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  43518. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  43519. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  43520. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  43521. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  43522. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  43523. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  43524. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  43525. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  43526. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  43527. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  43528. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  43529. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  43530. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  43531. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  43532. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  43533. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  43534. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  43535. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  43536. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  43537. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  43538. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  43539. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  43540. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  43541. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  43542. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  43543. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  43544. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  43545. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  43546. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  43547. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  43548. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  43549. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  43550. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  43551. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  43552. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  43553. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  43554. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  43555. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  43556. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  43557. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  43558. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  43559. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  43560. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  43561. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  43562. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  43563. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  43564. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  43565. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  43566. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  43567. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  43568. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  43569. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  43570. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  43571. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  43572. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  43573. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  43574. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  43575. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  43576. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  43577. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  43578. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  43579. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  43580. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  43581. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  43582. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  43583. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  43584. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  43585. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  43586. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  43587. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  43588. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  43589. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  43590. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  43591. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  43592. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  43593. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  43594. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  43595. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  43596. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  43597. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  43598. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  43599. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  43600. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  43601. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  43602. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  43603. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  43604. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  43605. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  43606. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  43607. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  43608. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  43609. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  43610. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  43611. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  43612. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  43613. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  43614. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  43615. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  43616. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  43617. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  43618. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  43619. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  43620. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  43621. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  43622. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  43623. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  43624. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  43625. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  43626. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  43627. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  43628. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  43629. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  43630. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  43631. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  43632. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  43633. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  43634. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  43635. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  43636. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  43637. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  43638. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  43639. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  43640. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  43641. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  43642. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  43643. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  43644. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  43645. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  43646. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  43647. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  43648. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  43649. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  43650. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  43651. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  43652. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  43653. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  43654. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  43655. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  43656. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  43657. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  43658. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  43659. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  43660. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  43661. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  43662. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  43663. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  43664. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  43665. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  43666. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  43667. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  43668. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  43669. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  43670. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  43671. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  43672. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  43673. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  43674. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  43675. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  43676. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  43677. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  43678. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  43679. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  43680. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  43681. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  43682. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  43683. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  43684. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  43685. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  43686. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  43687. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  43688. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  43689. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  43690. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  43691. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  43692. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  43693. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  43694. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  43695. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  43696. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  43697. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  43698. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  43699. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  43700. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  43701. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  43702. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  43703. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  43704. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  43705. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  43706. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  43707. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  43708. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  43709. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  43710. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  43711. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  43712. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  43713. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  43714. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  43715. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  43716. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  43717. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  43718. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  43719. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  43720. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  43721. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  43722. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  43723. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  43724. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  43725. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  43726. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  43727. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  43728. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  43729. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  43730. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  43731. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  43732. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  43733. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  43734. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  43735. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  43736. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  43737. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  43738. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  43739. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  43740. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  43741. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  43742. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  43743. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  43744. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  43745. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  43746. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  43747. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  43748. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  43749. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  43750. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  43751. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  43752. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  43753. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  43754. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  43755. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  43756. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  43757. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  43758. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  43759. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  43760. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  43761. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  43762. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  43763. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  43764. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  43765. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  43766. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  43767. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  43768. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  43769. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  43770. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  43771. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  43772. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  43773. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  43774. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  43775. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  43776. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  43777. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  43778. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  43779. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  43780. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  43781. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  43782. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  43783. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  43784. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  43785. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  43786. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  43787. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  43788. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  43789. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  43790. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  43791. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  43792. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  43793. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  43794. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  43795. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  43796. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  43797. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  43798. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  43799. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  43800. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  43801. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  43802. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  43803. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  43804. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  43805. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  43806. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  43807. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  43808. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  43809. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  43810. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  43811. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  43812. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  43813. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  43814. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  43815. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  43816. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  43817. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  43818. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  43819. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  43820. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  43821. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  43822. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  43823. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  43824. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  43825. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  43826. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  43827. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  43828. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  43829. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  43830. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  43831. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  43832. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  43833. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  43834. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  43835. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  43836. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  43837. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  43838. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  43839. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  43840. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  43841. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  43842. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  43843. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  43844. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  43845. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  43846. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  43847. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  43848. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  43849. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  43850. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  43851. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  43852. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  43853. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  43854. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  43855. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  43856. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  43857. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  43858. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  43859. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  43860. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  43861. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  43862. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  43863. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  43864. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  43865. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  43866. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  43867. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  43868. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  43869. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  43870. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  43871. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  43872. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  43873. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  43874. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  43875. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  43876. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  43877. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  43878. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  43879. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  43880. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  43881. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  43882. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  43883. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  43884. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  43885. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  43886. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  43887. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  43888. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  43889. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  43890. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  43891. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  43892. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  43893. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  43894. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  43895. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  43896. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  43897. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  43898. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  43899. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  43900. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  43901. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  43902. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  43903. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  43904. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  43905. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  43906. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  43907. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  43908. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  43909. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  43910. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  43911. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  43912. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  43913. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  43914. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  43915. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  43916. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  43917. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  43918. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  43919. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  43920. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  43921. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  43922. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  43923. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  43924. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  43925. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  43926. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  43927. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  43928. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  43929. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  43930. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  43931. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  43932. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  43933. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  43934. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  43935. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  43936. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  43937. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  43938. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  43939. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  43940. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  43941. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  43942. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  43943. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  43944. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  43945. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  43946. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  43947. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  43948. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43949. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43950. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43951. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  43952. 0x1F, 0x27, 0x2E
  43953. };
  43954. #endif
  43955. #endif
  43956. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43957. ExpectNotNull(key);
  43958. if (key != NULL) {
  43959. XMEMSET(key, 0, sizeof(*key));
  43960. }
  43961. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  43962. #ifndef WOLFSSL_NO_ML_DSA_44
  43963. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  43964. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  43965. 0);
  43966. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  43967. (word32)sizeof(msg_44), &res, key), 0);
  43968. ExpectIntEQ(res, 1);
  43969. #endif
  43970. #ifndef WOLFSSL_NO_ML_DSA_65
  43971. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  43972. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  43973. 0);
  43974. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  43975. (word32)sizeof(msg_65), &res, key), 0);
  43976. ExpectIntEQ(res, 1);
  43977. #endif
  43978. #ifndef WOLFSSL_NO_ML_DSA_87
  43979. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  43980. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  43981. 0);
  43982. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  43983. (word32)sizeof(msg_87), &res, key), 0);
  43984. ExpectIntEQ(res, 1);
  43985. #endif
  43986. wc_dilithium_free(key);
  43987. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43988. #endif
  43989. return EXPECT_RESULT();
  43990. }
  43991. /*
  43992. * Testing wc_SetSubjectBuffer
  43993. */
  43994. static int test_wc_SetSubjectBuffer(void)
  43995. {
  43996. EXPECT_DECLS;
  43997. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  43998. Cert cert;
  43999. XFILE file = XBADFILE;
  44000. byte* der = NULL;
  44001. word32 derSz;
  44002. derSz = FOURK_BUF;
  44003. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  44004. DYNAMIC_TYPE_TMP_BUFFER));
  44005. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  44006. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  44007. if (file != XBADFILE)
  44008. XFCLOSE(file);
  44009. ExpectIntEQ(wc_InitCert(&cert), 0);
  44010. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  44011. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44012. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44013. #endif
  44014. return EXPECT_RESULT();
  44015. } /* End test_wc_SetSubjectBuffer*/
  44016. /*
  44017. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  44018. */
  44019. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  44020. {
  44021. EXPECT_DECLS;
  44022. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44023. WC_RNG rng;
  44024. Cert cert;
  44025. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44026. RsaKey rsaKey;
  44027. int bits = 2048;
  44028. #endif
  44029. #if defined(HAVE_ECC)
  44030. ecc_key eccKey;
  44031. int ret;
  44032. #endif
  44033. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44034. ed25519_key ed25519Key;
  44035. #endif
  44036. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44037. ed448_key ed448Key;
  44038. #endif
  44039. #ifndef HAVE_FIPS
  44040. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44041. #else
  44042. ExpectIntEQ(wc_InitRng(&rng), 0);
  44043. #endif
  44044. ExpectIntEQ(wc_InitCert(&cert), 0);
  44045. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44046. /* RSA */
  44047. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44048. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44049. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44050. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  44051. 0);
  44052. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44053. #endif
  44054. #if defined(HAVE_ECC)
  44055. /* ECC */
  44056. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44057. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44058. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44059. #if defined(WOLFSSL_ASYNC_CRYPT)
  44060. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44061. #endif
  44062. ExpectIntEQ(ret, 0);
  44063. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  44064. 0);
  44065. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44066. #endif
  44067. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44068. /* ED25519 */
  44069. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44070. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44071. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44072. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44073. &ed25519Key), 0);
  44074. wc_ed25519_free(&ed25519Key);
  44075. #endif
  44076. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44077. /* ED448 */
  44078. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44079. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44080. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44081. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  44082. &ed448Key), 0);
  44083. wc_ed448_free(&ed448Key);
  44084. #endif
  44085. wc_FreeRng(&rng);
  44086. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44087. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  44088. return EXPECT_RESULT();
  44089. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  44090. /*
  44091. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  44092. */
  44093. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  44094. {
  44095. EXPECT_DECLS;
  44096. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44097. WC_RNG rng;
  44098. Cert cert;
  44099. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44100. RsaKey rsaKey;
  44101. int bits = 2048;
  44102. #endif
  44103. #if defined(HAVE_ECC)
  44104. ecc_key eccKey;
  44105. int ret;
  44106. #endif
  44107. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44108. ed25519_key ed25519Key;
  44109. #endif
  44110. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44111. ed448_key ed448Key;
  44112. #endif
  44113. #ifndef HAVE_FIPS
  44114. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44115. #else
  44116. ExpectIntEQ(wc_InitRng(&rng), 0);
  44117. #endif
  44118. ExpectIntEQ(wc_InitCert(&cert), 0);
  44119. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44120. /* RSA */
  44121. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44122. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44123. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44124. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  44125. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44126. #endif
  44127. #if defined(HAVE_ECC)
  44128. /* ECC */
  44129. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44130. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44131. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44132. #if defined(WOLFSSL_ASYNC_CRYPT)
  44133. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44134. #endif
  44135. ExpectIntEQ(ret, 0);
  44136. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  44137. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44138. #endif
  44139. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44140. /* ED25519 */
  44141. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44142. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44143. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44144. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44145. &ed25519Key), 0);
  44146. wc_ed25519_free(&ed25519Key);
  44147. #endif
  44148. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44149. /* ED448 */
  44150. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44151. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44152. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44153. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  44154. 0);
  44155. wc_ed448_free(&ed448Key);
  44156. #endif
  44157. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44158. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  44159. return EXPECT_RESULT();
  44160. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  44161. /*
  44162. * Testing wc_PKCS7_New()
  44163. */
  44164. static int test_wc_PKCS7_New(void)
  44165. {
  44166. EXPECT_DECLS;
  44167. #if defined(HAVE_PKCS7)
  44168. PKCS7* pkcs7 = NULL;
  44169. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  44170. wc_PKCS7_Free(pkcs7);
  44171. #endif
  44172. return EXPECT_RESULT();
  44173. } /* END test-wc_PKCS7_New */
  44174. /*
  44175. * Testing wc_PKCS7_Init()
  44176. */
  44177. static int test_wc_PKCS7_Init(void)
  44178. {
  44179. EXPECT_DECLS;
  44180. #if defined(HAVE_PKCS7)
  44181. PKCS7* pkcs7 = NULL;
  44182. void* heap = NULL;
  44183. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  44184. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  44185. /* Pass in bad args. */
  44186. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44187. wc_PKCS7_Free(pkcs7);
  44188. #endif
  44189. return EXPECT_RESULT();
  44190. } /* END test-wc_PKCS7_Init */
  44191. /*
  44192. * Testing wc_PKCS7_InitWithCert()
  44193. */
  44194. static int test_wc_PKCS7_InitWithCert(void)
  44195. {
  44196. EXPECT_DECLS;
  44197. #if defined(HAVE_PKCS7)
  44198. PKCS7* pkcs7 = NULL;
  44199. #ifndef NO_RSA
  44200. #if defined(USE_CERT_BUFFERS_2048)
  44201. unsigned char cert[sizeof(client_cert_der_2048)];
  44202. int certSz = (int)sizeof(cert);
  44203. XMEMSET(cert, 0, certSz);
  44204. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  44205. #elif defined(USE_CERT_BUFFERS_1024)
  44206. unsigned char cert[sizeof(client_cert_der_1024)];
  44207. int certSz = (int)sizeof(cert);
  44208. XMEMSET(cert, 0, certSz);
  44209. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  44210. #else
  44211. unsigned char cert[ONEK_BUF];
  44212. XFILE fp = XBADFILE;
  44213. int certSz;
  44214. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44215. XBADFILE);
  44216. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44217. fp), 0);
  44218. if (fp != XBADFILE)
  44219. XFCLOSE(fp);
  44220. #endif
  44221. #elif defined(HAVE_ECC)
  44222. #if defined(USE_CERT_BUFFERS_256)
  44223. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44224. int certSz = (int)sizeof(cert);
  44225. XMEMSET(cert, 0, certSz);
  44226. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  44227. #else
  44228. unsigned char cert[ONEK_BUF];
  44229. XFILE fp = XBADFILE;
  44230. int certSz;
  44231. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44232. XBADFILE);
  44233. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  44234. fp), 0);
  44235. if (fp != XBADFILE)
  44236. XFCLOSE(fp);
  44237. #endif
  44238. #else
  44239. #error PKCS7 requires ECC or RSA
  44240. #endif
  44241. #ifdef HAVE_ECC
  44242. {
  44243. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  44244. static unsigned char certWithInvalidEccKey[] = {
  44245. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  44246. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  44247. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  44248. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  44249. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44250. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  44251. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44252. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44253. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44254. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44255. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44256. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44257. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44258. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44259. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44260. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  44261. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  44262. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  44263. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  44264. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  44265. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  44266. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  44267. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  44268. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  44269. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  44270. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  44271. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  44272. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  44273. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  44274. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  44275. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  44276. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  44277. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  44278. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  44279. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  44280. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  44281. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  44282. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  44283. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  44284. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  44285. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44286. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  44287. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  44288. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44289. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  44290. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44291. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  44292. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44293. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44294. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44295. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44296. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44297. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44298. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44299. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44300. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44301. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  44302. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  44303. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  44304. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  44305. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  44306. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  44307. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  44308. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  44309. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  44310. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  44311. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  44312. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  44313. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  44314. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  44315. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  44316. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  44317. 0x08, 0xA8, 0xB4
  44318. };
  44319. #endif
  44320. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44321. /* If initialization is not successful, it's free'd in init func. */
  44322. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  44323. 0);
  44324. wc_PKCS7_Free(pkcs7);
  44325. pkcs7 = NULL;
  44326. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44327. /* Valid initialization usage. */
  44328. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44329. /* Pass in bad args. No need free for null checks, free at end.*/
  44330. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  44331. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44332. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  44333. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44334. #ifdef HAVE_ECC
  44335. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  44336. sizeof(certWithInvalidEccKey)), 0);
  44337. }
  44338. #endif
  44339. wc_PKCS7_Free(pkcs7);
  44340. #endif
  44341. return EXPECT_RESULT();
  44342. } /* END test_wc_PKCS7_InitWithCert */
  44343. /*
  44344. * Testing wc_PKCS7_EncodeData()
  44345. */
  44346. static int test_wc_PKCS7_EncodeData(void)
  44347. {
  44348. EXPECT_DECLS;
  44349. #if defined(HAVE_PKCS7)
  44350. PKCS7* pkcs7 = NULL;
  44351. byte output[FOURK_BUF];
  44352. byte data[] = "My encoded DER cert.";
  44353. #ifndef NO_RSA
  44354. #if defined(USE_CERT_BUFFERS_2048)
  44355. unsigned char cert[sizeof(client_cert_der_2048)];
  44356. unsigned char key[sizeof(client_key_der_2048)];
  44357. int certSz = (int)sizeof(cert);
  44358. int keySz = (int)sizeof(key);
  44359. XMEMSET(cert, 0, certSz);
  44360. XMEMSET(key, 0, keySz);
  44361. XMEMCPY(cert, client_cert_der_2048, certSz);
  44362. XMEMCPY(key, client_key_der_2048, keySz);
  44363. #elif defined(USE_CERT_BUFFERS_1024)
  44364. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  44365. unsigned char key[sizeof_client_key_der_1024];
  44366. int certSz = (int)sizeof(cert);
  44367. int keySz = (int)sizeof(key);
  44368. XMEMSET(cert, 0, certSz);
  44369. XMEMSET(key, 0, keySz);
  44370. XMEMCPY(cert, client_cert_der_1024, certSz);
  44371. XMEMCPY(key, client_key_der_1024, keySz);
  44372. #else
  44373. unsigned char cert[ONEK_BUF];
  44374. unsigned char key[ONEK_BUF];
  44375. XFILE fp = XBADFILE;
  44376. int certSz;
  44377. int keySz;
  44378. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44379. XBADFILE);
  44380. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44381. fp), 0);
  44382. if (fp != XBADFILE) {
  44383. XFCLOSE(fp);
  44384. fp = XBADFILE;
  44385. }
  44386. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44387. XBADFILE);
  44388. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44389. 0);
  44390. if (fp != XBADFILE)
  44391. XFCLOSE(fp);
  44392. #endif
  44393. #elif defined(HAVE_ECC)
  44394. #if defined(USE_CERT_BUFFERS_256)
  44395. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44396. unsigned char key[sizeof(ecc_clikey_der_256)];
  44397. int certSz = (int)sizeof(cert);
  44398. int keySz = (int)sizeof(key);
  44399. XMEMSET(cert, 0, certSz);
  44400. XMEMSET(key, 0, keySz);
  44401. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44402. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44403. #else
  44404. unsigned char cert[ONEK_BUF];
  44405. unsigned char key[ONEK_BUF];
  44406. XFILE fp = XBADFILE;
  44407. int certSz, keySz;
  44408. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44409. XBADFILE);
  44410. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44411. fp), 0);
  44412. if (fp != XBADFILE) {
  44413. XFCLOSE(fp);
  44414. fp = XBADFILE;
  44415. }
  44416. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44417. XBADFILE);
  44418. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44419. 0);
  44420. if (fp != XBADFILE)
  44421. XFCLOSE(fp);
  44422. #endif
  44423. #endif
  44424. XMEMSET(output, 0, sizeof(output));
  44425. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44426. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44427. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  44428. if (pkcs7 != NULL) {
  44429. pkcs7->content = data;
  44430. pkcs7->contentSz = sizeof(data);
  44431. pkcs7->privateKey = key;
  44432. pkcs7->privateKeySz = (word32)keySz;
  44433. }
  44434. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  44435. /* Test bad args. */
  44436. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  44437. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44438. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  44439. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44440. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  44441. wc_PKCS7_Free(pkcs7);
  44442. #endif
  44443. return EXPECT_RESULT();
  44444. } /* END test_wc_PKCS7_EncodeData */
  44445. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44446. !defined(NO_RSA) && !defined(NO_SHA256)
  44447. /* RSA sign raw digest callback */
  44448. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  44449. byte* out, word32 outSz, byte* privateKey,
  44450. word32 privateKeySz, int devid, int hashOID)
  44451. {
  44452. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  44453. byte digInfoEncoding[] = {
  44454. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  44455. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  44456. 0x00, 0x04, 0x20
  44457. };
  44458. int ret;
  44459. byte digestInfo[ONEK_BUF];
  44460. byte sig[FOURK_BUF];
  44461. word32 digestInfoSz = 0;
  44462. word32 idx = 0;
  44463. RsaKey rsa;
  44464. /* SHA-256 required only for this example callback due to above
  44465. * digInfoEncoding[] */
  44466. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  44467. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  44468. (hashOID != SHA256h)) {
  44469. return -1;
  44470. }
  44471. /* build DigestInfo */
  44472. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  44473. digestInfoSz += sizeof(digInfoEncoding);
  44474. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  44475. digestInfoSz += digestSz;
  44476. /* set up RSA key */
  44477. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  44478. if (ret != 0) {
  44479. return ret;
  44480. }
  44481. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  44482. /* sign DigestInfo */
  44483. if (ret == 0) {
  44484. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  44485. &rsa, pkcs7->rng);
  44486. if (ret > 0) {
  44487. if (ret > (int)outSz) {
  44488. /* output buffer too small */
  44489. ret = -1;
  44490. }
  44491. else {
  44492. /* success, ret holds sig size */
  44493. XMEMCPY(out, sig, ret);
  44494. }
  44495. }
  44496. }
  44497. wc_FreeRsaKey(&rsa);
  44498. return ret;
  44499. }
  44500. #endif
  44501. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  44502. typedef struct encodeSignedDataStream {
  44503. byte out[FOURK_BUF*3];
  44504. int idx;
  44505. word32 outIdx;
  44506. } encodeSignedDataStream;
  44507. /* content is 8k of partially created bundle */
  44508. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  44509. {
  44510. int ret = 0;
  44511. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44512. if (strm->outIdx < pkcs7->contentSz) {
  44513. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  44514. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  44515. *content = strm->out + strm->outIdx;
  44516. strm->outIdx += ret;
  44517. }
  44518. (void)pkcs7;
  44519. return ret;
  44520. }
  44521. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  44522. void* ctx)
  44523. {
  44524. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44525. XMEMCPY(strm->out + strm->idx, output, outputSz);
  44526. strm->idx += outputSz;
  44527. (void)pkcs7;
  44528. return 0;
  44529. }
  44530. #endif
  44531. /*
  44532. * Testing wc_PKCS7_EncodeSignedData()
  44533. */
  44534. static int test_wc_PKCS7_EncodeSignedData(void)
  44535. {
  44536. EXPECT_DECLS;
  44537. #if defined(HAVE_PKCS7)
  44538. PKCS7* pkcs7 = NULL;
  44539. WC_RNG rng;
  44540. byte output[FOURK_BUF];
  44541. byte badOut[1];
  44542. word32 outputSz = (word32)sizeof(output);
  44543. word32 badOutSz = 0;
  44544. byte data[] = "Test data to encode.";
  44545. #ifndef NO_RSA
  44546. #if defined(USE_CERT_BUFFERS_2048)
  44547. byte key[sizeof(client_key_der_2048)];
  44548. byte cert[sizeof(client_cert_der_2048)];
  44549. word32 keySz = (word32)sizeof(key);
  44550. word32 certSz = (word32)sizeof(cert);
  44551. XMEMSET(key, 0, keySz);
  44552. XMEMSET(cert, 0, certSz);
  44553. XMEMCPY(key, client_key_der_2048, keySz);
  44554. XMEMCPY(cert, client_cert_der_2048, certSz);
  44555. #elif defined(USE_CERT_BUFFERS_1024)
  44556. byte key[sizeof_client_key_der_1024];
  44557. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44558. word32 keySz = (word32)sizeof(key);
  44559. word32 certSz = (word32)sizeof(cert);
  44560. XMEMSET(key, 0, keySz);
  44561. XMEMSET(cert, 0, certSz);
  44562. XMEMCPY(key, client_key_der_1024, keySz);
  44563. XMEMCPY(cert, client_cert_der_1024, certSz);
  44564. #else
  44565. unsigned char cert[ONEK_BUF];
  44566. unsigned char key[ONEK_BUF];
  44567. XFILE fp = XBADFILE;
  44568. int certSz;
  44569. int keySz;
  44570. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44571. XBADFILE);
  44572. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44573. fp), 0);
  44574. if (fp != XBADFILE) {
  44575. XFCLOSE(fp);
  44576. fp = XBADFILE;
  44577. }
  44578. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44579. XBADFILE);
  44580. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44581. 0);
  44582. if (fp != XBADFILE)
  44583. XFCLOSE(fp);
  44584. #endif
  44585. #elif defined(HAVE_ECC)
  44586. #if defined(USE_CERT_BUFFERS_256)
  44587. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44588. unsigned char key[sizeof(ecc_clikey_der_256)];
  44589. int certSz = (int)sizeof(cert);
  44590. int keySz = (int)sizeof(key);
  44591. XMEMSET(cert, 0, certSz);
  44592. XMEMSET(key, 0, keySz);
  44593. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  44594. XMEMCPY(key, ecc_clikey_der_256, keySz);
  44595. #else
  44596. unsigned char cert[ONEK_BUF];
  44597. unsigned char key[ONEK_BUF];
  44598. XFILE fp = XBADFILE;
  44599. int certSz;
  44600. int keySz;
  44601. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44602. XBADFILE);
  44603. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  44604. if (fp != XBADFILE) {
  44605. XFCLOSE(fp);
  44606. fp = XBADFILE;
  44607. }
  44608. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44609. XBADFILE);
  44610. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  44611. if (fp != XBADFILE)
  44612. XFCLOSE(fp);
  44613. #endif
  44614. #endif
  44615. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44616. XMEMSET(output, 0, outputSz);
  44617. ExpectIntEQ(wc_InitRng(&rng), 0);
  44618. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44619. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44620. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44621. if (pkcs7 != NULL) {
  44622. pkcs7->content = data;
  44623. pkcs7->contentSz = (word32)sizeof(data);
  44624. pkcs7->privateKey = key;
  44625. pkcs7->privateKeySz = (word32)sizeof(key);
  44626. pkcs7->encryptOID = RSAk;
  44627. #ifdef NO_SHA
  44628. pkcs7->hashOID = SHA256h;
  44629. #else
  44630. pkcs7->hashOID = SHAh;
  44631. #endif
  44632. pkcs7->rng = &rng;
  44633. }
  44634. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44635. wc_PKCS7_Free(pkcs7);
  44636. pkcs7 = NULL;
  44637. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44638. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44639. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44640. #ifdef ASN_BER_TO_DER
  44641. wc_PKCS7_Free(pkcs7);
  44642. /* reinitialize and test setting stream mode */
  44643. {
  44644. int signedSz = 0;
  44645. encodeSignedDataStream strm;
  44646. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44647. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44648. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44649. if (pkcs7 != NULL) {
  44650. pkcs7->content = data;
  44651. pkcs7->contentSz = (word32)sizeof(data);
  44652. pkcs7->privateKey = key;
  44653. pkcs7->privateKeySz = (word32)sizeof(key);
  44654. pkcs7->encryptOID = RSAk;
  44655. #ifdef NO_SHA
  44656. pkcs7->hashOID = SHA256h;
  44657. #else
  44658. pkcs7->hashOID = SHAh;
  44659. #endif
  44660. pkcs7->rng = &rng;
  44661. }
  44662. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  44663. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  44664. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  44665. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44666. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  44667. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  44668. outputSz), 0);
  44669. wc_PKCS7_Free(pkcs7);
  44670. pkcs7 = NULL;
  44671. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44672. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44673. /* use exact signed buffer size since BER encoded */
  44674. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  44675. wc_PKCS7_Free(pkcs7);
  44676. /* now try with using callbacks for IO */
  44677. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44678. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44679. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44680. if (pkcs7 != NULL) {
  44681. pkcs7->contentSz = FOURK_BUF*2;
  44682. pkcs7->privateKey = key;
  44683. pkcs7->privateKeySz = (word32)sizeof(key);
  44684. pkcs7->encryptOID = RSAk;
  44685. #ifdef NO_SHA
  44686. pkcs7->hashOID = SHA256h;
  44687. #else
  44688. pkcs7->hashOID = SHAh;
  44689. #endif
  44690. pkcs7->rng = &rng;
  44691. }
  44692. XMEMSET(&strm, 0, sizeof(strm));
  44693. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  44694. StreamOutputCB, (void*)&strm), 0);
  44695. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  44696. wc_PKCS7_Free(pkcs7);
  44697. pkcs7 = NULL;
  44698. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44699. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44700. /* use exact signed buffer size since BER encoded */
  44701. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  44702. }
  44703. #endif
  44704. #ifndef NO_PKCS7_STREAM
  44705. wc_PKCS7_Free(pkcs7);
  44706. pkcs7 = NULL;
  44707. {
  44708. word32 z;
  44709. int ret;
  44710. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44711. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44712. /* test for streaming mode */
  44713. ret = -1;
  44714. for (z = 0; z < outputSz && ret != 0; z++) {
  44715. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44716. if (ret < 0){
  44717. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44718. }
  44719. }
  44720. ExpectIntEQ(ret, 0);
  44721. ExpectIntNE(pkcs7->contentSz, 0);
  44722. ExpectNotNull(pkcs7->contentDynamic);
  44723. }
  44724. #endif /* !NO_PKCS7_STREAM */
  44725. /* Pass in bad args. */
  44726. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  44727. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44728. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44729. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  44730. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44731. if (pkcs7 != NULL) {
  44732. pkcs7->hashOID = 0; /* bad hashOID */
  44733. }
  44734. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  44735. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44736. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44737. !defined(NO_RSA) && !defined(NO_SHA256)
  44738. /* test RSA sign raw digest callback, if using RSA and compiled in.
  44739. * Example callback assumes SHA-256, so only run test if compiled in. */
  44740. wc_PKCS7_Free(pkcs7);
  44741. pkcs7 = NULL;
  44742. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44743. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44744. if (pkcs7 != NULL) {
  44745. pkcs7->content = data;
  44746. pkcs7->contentSz = (word32)sizeof(data);
  44747. pkcs7->privateKey = key;
  44748. pkcs7->privateKeySz = (word32)sizeof(key);
  44749. pkcs7->encryptOID = RSAk;
  44750. pkcs7->hashOID = SHA256h;
  44751. pkcs7->rng = &rng;
  44752. }
  44753. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  44754. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44755. #endif
  44756. wc_PKCS7_Free(pkcs7);
  44757. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44758. #endif
  44759. return EXPECT_RESULT();
  44760. } /* END test_wc_PKCS7_EncodeSignedData */
  44761. /*
  44762. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  44763. */
  44764. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  44765. {
  44766. EXPECT_DECLS;
  44767. #if defined(HAVE_PKCS7)
  44768. int i;
  44769. PKCS7* pkcs7 = NULL;
  44770. WC_RNG rng;
  44771. byte outputHead[FOURK_BUF/2];
  44772. byte outputFoot[FOURK_BUF/2];
  44773. word32 outputHeadSz = (word32)sizeof(outputHead);
  44774. word32 outputFootSz = (word32)sizeof(outputFoot);
  44775. byte data[FOURK_BUF];
  44776. wc_HashAlg hash;
  44777. #ifdef NO_SHA
  44778. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  44779. #else
  44780. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  44781. #endif
  44782. byte hashBuf[WC_MAX_DIGEST_SIZE];
  44783. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  44784. #ifndef NO_RSA
  44785. #if defined(USE_CERT_BUFFERS_2048)
  44786. byte key[sizeof(client_key_der_2048)];
  44787. byte cert[sizeof(client_cert_der_2048)];
  44788. word32 keySz = (word32)sizeof(key);
  44789. word32 certSz = (word32)sizeof(cert);
  44790. XMEMSET(key, 0, keySz);
  44791. XMEMSET(cert, 0, certSz);
  44792. XMEMCPY(key, client_key_der_2048, keySz);
  44793. XMEMCPY(cert, client_cert_der_2048, certSz);
  44794. #elif defined(USE_CERT_BUFFERS_1024)
  44795. byte key[sizeof_client_key_der_1024];
  44796. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44797. word32 keySz = (word32)sizeof(key);
  44798. word32 certSz = (word32)sizeof(cert);
  44799. XMEMSET(key, 0, keySz);
  44800. XMEMSET(cert, 0, certSz);
  44801. XMEMCPY(key, client_key_der_1024, keySz);
  44802. XMEMCPY(cert, client_cert_der_1024, certSz);
  44803. #else
  44804. unsigned char cert[ONEK_BUF];
  44805. unsigned char key[ONEK_BUF];
  44806. XFILE fp = XBADFILE;
  44807. int certSz;
  44808. int keySz;
  44809. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44810. XBADFILE);
  44811. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44812. fp), 0);
  44813. if (fp != XBADFILE) {
  44814. XFCLOSE(fp);
  44815. fp = XBADFILE;
  44816. }
  44817. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44818. XBADFILE);
  44819. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44820. 0);
  44821. if (fp != XBADFILE)
  44822. XFCLOSE(fp);
  44823. #endif
  44824. #elif defined(HAVE_ECC)
  44825. #if defined(USE_CERT_BUFFERS_256)
  44826. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44827. unsigned char key[sizeof(ecc_clikey_der_256)];
  44828. int certSz = (int)sizeof(cert);
  44829. int keySz = (int)sizeof(key);
  44830. XMEMSET(cert, 0, certSz);
  44831. XMEMSET(key, 0, keySz);
  44832. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44833. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44834. #else
  44835. unsigned char cert[ONEK_BUF];
  44836. unsigned char key[ONEK_BUF];
  44837. XFILE fp = XBADFILE;
  44838. int certSz;
  44839. int keySz;
  44840. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44841. XBADFILE);
  44842. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44843. fp), 0);
  44844. if (fp != XBADFILE) {
  44845. XFCLOSE(fp);
  44846. fp = XBADFILE;
  44847. }
  44848. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44849. XBADFILE);
  44850. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44851. 0);
  44852. if (fp != XBADFILE)
  44853. XFCLOSE(fp);
  44854. #endif
  44855. #endif
  44856. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44857. /* initialize large data with sequence */
  44858. for (i=0; i<(int)sizeof(data); i++)
  44859. data[i] = i & 0xff;
  44860. XMEMSET(outputHead, 0, outputHeadSz);
  44861. XMEMSET(outputFoot, 0, outputFootSz);
  44862. ExpectIntEQ(wc_InitRng(&rng), 0);
  44863. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44864. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44865. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44866. if (pkcs7 != NULL) {
  44867. pkcs7->content = NULL; /* not used for ex */
  44868. pkcs7->contentSz = (word32)sizeof(data);
  44869. pkcs7->privateKey = key;
  44870. pkcs7->privateKeySz = (word32)sizeof(key);
  44871. pkcs7->encryptOID = RSAk;
  44872. #ifdef NO_SHA
  44873. pkcs7->hashOID = SHA256h;
  44874. #else
  44875. pkcs7->hashOID = SHAh;
  44876. #endif
  44877. pkcs7->rng = &rng;
  44878. }
  44879. /* calculate hash for content */
  44880. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  44881. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  44882. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  44883. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  44884. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  44885. /* Perform PKCS7 sign using hash directly */
  44886. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44887. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  44888. ExpectIntGT(outputHeadSz, 0);
  44889. ExpectIntGT(outputFootSz, 0);
  44890. wc_PKCS7_Free(pkcs7);
  44891. pkcs7 = NULL;
  44892. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44893. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44894. /* required parameter even on verify when using _ex, if using outputHead
  44895. * and outputFoot */
  44896. if (pkcs7 != NULL) {
  44897. pkcs7->contentSz = (word32)sizeof(data);
  44898. }
  44899. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44900. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  44901. wc_PKCS7_Free(pkcs7);
  44902. pkcs7 = NULL;
  44903. /* assembly complete PKCS7 sign and use normal verify */
  44904. {
  44905. byte* output = NULL;
  44906. word32 outputSz = 0;
  44907. #ifndef NO_PKCS7_STREAM
  44908. word32 z;
  44909. int ret;
  44910. #endif /* !NO_PKCS7_STREAM */
  44911. ExpectNotNull(output = (byte*)XMALLOC(
  44912. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  44913. DYNAMIC_TYPE_TMP_BUFFER));
  44914. if (output != NULL) {
  44915. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  44916. outputSz += outputHeadSz;
  44917. XMEMCPY(&output[outputSz], data, sizeof(data));
  44918. outputSz += sizeof(data);
  44919. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  44920. outputSz += outputFootSz;
  44921. }
  44922. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44923. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44924. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44925. #ifndef NO_PKCS7_STREAM
  44926. wc_PKCS7_Free(pkcs7);
  44927. pkcs7 = NULL;
  44928. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44929. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44930. /* test for streaming mode */
  44931. ret = -1;
  44932. for (z = 0; z < outputSz && ret != 0; z++) {
  44933. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44934. if (ret < 0){
  44935. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44936. }
  44937. }
  44938. ExpectIntEQ(ret, 0);
  44939. ExpectIntNE(pkcs7->contentSz, 0);
  44940. ExpectNotNull(pkcs7->contentDynamic);
  44941. wc_PKCS7_Free(pkcs7);
  44942. pkcs7 = NULL;
  44943. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44944. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44945. #endif /* !NO_PKCS7_STREAM */
  44946. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44947. }
  44948. /* Pass in bad args. */
  44949. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44950. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44951. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44952. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44953. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44954. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44955. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44956. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44957. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44958. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44959. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44960. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44961. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44962. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44963. if (pkcs7 != NULL) {
  44964. pkcs7->hashOID = 0; /* bad hashOID */
  44965. }
  44966. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44967. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44968. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44969. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44970. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44971. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44972. #ifndef NO_PKCS7_STREAM
  44973. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44974. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44975. #else
  44976. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44977. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  44978. #endif
  44979. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44980. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44981. #ifndef NO_PKCS7_STREAM
  44982. /* can pass in 0 buffer length with streaming API */
  44983. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44984. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44985. #else
  44986. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44987. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44988. #endif
  44989. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44990. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44991. #ifndef NO_PKCS7_STREAM
  44992. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44993. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44994. #else
  44995. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44996. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  44997. #endif
  44998. wc_PKCS7_Free(pkcs7);
  44999. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45000. #endif
  45001. return EXPECT_RESULT();
  45002. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  45003. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  45004. /**
  45005. * Loads certs/keys from files or buffers into the argument buffers,
  45006. * helper function called by CreatePKCS7SignedData().
  45007. *
  45008. * Returns 0 on success, negative on error.
  45009. */
  45010. static int LoadPKCS7SignedDataCerts(
  45011. int useIntermediateCertChain, int pkAlgoType,
  45012. byte* intCARoot, word32* intCARootSz,
  45013. byte* intCA1, word32* intCA1Sz,
  45014. byte* intCA2, word32* intCA2Sz,
  45015. byte* cert, word32* certSz,
  45016. byte* key, word32* keySz)
  45017. {
  45018. EXPECT_DECLS;
  45019. int ret = 0;
  45020. XFILE fp = XBADFILE;
  45021. #ifndef NO_RSA
  45022. const char* intCARootRSA = "./certs/ca-cert.der";
  45023. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  45024. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  45025. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  45026. const char* intServKeyRSA = "./certs/server-key.der";
  45027. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  45028. const char* cli1024Cert = "./certs/1024/client-cert.der";
  45029. const char* cli1024Key = "./certs/1024/client-key.der";
  45030. #endif
  45031. #endif
  45032. #ifdef HAVE_ECC
  45033. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  45034. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  45035. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  45036. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  45037. const char* intServKeyECC = "./certs/ecc-key.der";
  45038. #ifndef USE_CERT_BUFFERS_256
  45039. const char* cliEccCert = "./certs/client-ecc-cert.der";
  45040. const char* cliEccKey = "./certs/client-ecc-key.der";
  45041. #endif
  45042. #endif
  45043. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  45044. ((useIntermediateCertChain == 1) &&
  45045. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  45046. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  45047. return BAD_FUNC_ARG;
  45048. }
  45049. /* Read/load certs and keys to use for signing based on PK type and chain */
  45050. switch (pkAlgoType) {
  45051. #ifndef NO_RSA
  45052. case RSA_TYPE:
  45053. if (useIntermediateCertChain == 1) {
  45054. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  45055. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  45056. if (fp != XBADFILE) {
  45057. XFCLOSE(fp);
  45058. fp = XBADFILE;
  45059. }
  45060. ExpectIntGT(*intCARootSz, 0);
  45061. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  45062. if (fp != XBADFILE) {
  45063. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45064. XFCLOSE(fp);
  45065. fp = XBADFILE;
  45066. }
  45067. ExpectIntGT(*intCA1Sz, 0);
  45068. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  45069. if (fp != XBADFILE) {
  45070. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45071. XFCLOSE(fp);
  45072. fp = XBADFILE;
  45073. }
  45074. ExpectIntGT(*intCA2Sz, 0);
  45075. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  45076. if (fp != XBADFILE) {
  45077. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45078. XFCLOSE(fp);
  45079. fp = XBADFILE;
  45080. }
  45081. ExpectIntGT(*certSz, 0);
  45082. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  45083. if (fp != XBADFILE) {
  45084. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45085. XFCLOSE(fp);
  45086. fp = XBADFILE;
  45087. }
  45088. ExpectIntGT(*keySz, 0);
  45089. }
  45090. else {
  45091. #if defined(USE_CERT_BUFFERS_2048)
  45092. *keySz = sizeof_client_key_der_2048;
  45093. *certSz = sizeof_client_cert_der_2048;
  45094. XMEMCPY(key, client_key_der_2048, *keySz);
  45095. XMEMCPY(cert, client_cert_der_2048, *certSz);
  45096. #elif defined(USE_CERT_BUFFERS_1024)
  45097. *keySz = sizeof_client_key_der_1024;
  45098. *certSz = sizeof_client_cert_der_1024;
  45099. XMEMCPY(key, client_key_der_1024, *keySz);
  45100. XMEMCPY(cert, client_cert_der_1024, *certSz);
  45101. #else
  45102. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  45103. if (fp != XBADFILE) {
  45104. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45105. XFCLOSE(fp);
  45106. fp = XBADFILE;
  45107. }
  45108. ExpectIntGT(*keySz, 0);
  45109. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  45110. if (fp != XBADFILE) {
  45111. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45112. XFCLOSE(fp);
  45113. fp = XBADFILE;
  45114. }
  45115. ExpectIntGT(*certSz, 0);
  45116. #endif /* USE_CERT_BUFFERS_2048 */
  45117. }
  45118. break;
  45119. #endif /* !NO_RSA */
  45120. #ifdef HAVE_ECC
  45121. case ECC_TYPE:
  45122. if (useIntermediateCertChain == 1) {
  45123. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  45124. if (fp != XBADFILE) {
  45125. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  45126. fp);
  45127. XFCLOSE(fp);
  45128. fp = XBADFILE;
  45129. }
  45130. ExpectIntGT(*intCARootSz, 0);
  45131. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  45132. if (fp != XBADFILE) {
  45133. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45134. XFCLOSE(fp);
  45135. fp = XBADFILE;
  45136. }
  45137. ExpectIntGT(*intCA1Sz, 0);
  45138. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  45139. if (fp != XBADFILE) {
  45140. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45141. XFCLOSE(fp);
  45142. fp = XBADFILE;
  45143. }
  45144. ExpectIntGT(*intCA2Sz, 0);
  45145. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  45146. if (fp != XBADFILE) {
  45147. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45148. XFCLOSE(fp);
  45149. fp = XBADFILE;
  45150. }
  45151. ExpectIntGT(*certSz, 0);
  45152. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  45153. if (fp != XBADFILE) {
  45154. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45155. XFCLOSE(fp);
  45156. fp = XBADFILE;
  45157. }
  45158. ExpectIntGT(*keySz, 0);
  45159. }
  45160. else {
  45161. #if defined(USE_CERT_BUFFERS_256)
  45162. *keySz = sizeof_ecc_clikey_der_256;
  45163. *certSz = sizeof_cliecc_cert_der_256;
  45164. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  45165. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  45166. #else
  45167. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  45168. if (fp != XBADFILE) {
  45169. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45170. XFCLOSE(fp);
  45171. fp = XBADFILE;
  45172. }
  45173. ExpectIntGT(*keySz, 0);
  45174. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  45175. if (fp != XBADFILE) {
  45176. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45177. XFCLOSE(fp);
  45178. fp = XBADFILE;
  45179. }
  45180. ExpectIntGT(*certSz, 0);
  45181. #endif /* USE_CERT_BUFFERS_256 */
  45182. }
  45183. break;
  45184. #endif /* HAVE_ECC */
  45185. default:
  45186. WOLFSSL_MSG("Unsupported SignedData PK type");
  45187. ret = BAD_FUNC_ARG;
  45188. break;
  45189. }
  45190. if (EXPECT_FAIL() && (ret == 0)) {
  45191. ret = BAD_FUNC_ARG;
  45192. }
  45193. return ret;
  45194. }
  45195. /**
  45196. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  45197. *
  45198. * output output buffer to place SignedData
  45199. * outputSz size of output buffer
  45200. * data data buffer to be signed
  45201. * dataSz size of data buffer
  45202. * withAttribs [1/0] include attributes in SignedData message
  45203. * detachedSig [1/0] create detached signature, no content
  45204. * useIntCertChain [1/0] use certificate chain and include intermediate and
  45205. * root CAs in bundle
  45206. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  45207. *
  45208. * Return size of bundle created on success, negative on error */
  45209. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  45210. byte* data, word32 dataSz,
  45211. int withAttribs, int detachedSig,
  45212. int useIntermediateCertChain,
  45213. int pkAlgoType)
  45214. {
  45215. EXPECT_DECLS;
  45216. int ret = 0;
  45217. WC_RNG rng;
  45218. PKCS7* pkcs7 = NULL;
  45219. static byte messageTypeOid[] =
  45220. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  45221. 0x09, 0x02 };
  45222. static byte messageType[] = { 0x13, 2, '1', '9' };
  45223. PKCS7Attrib attribs[] =
  45224. {
  45225. { messageTypeOid, sizeof(messageTypeOid), messageType,
  45226. sizeof(messageType) }
  45227. };
  45228. byte intCARoot[TWOK_BUF];
  45229. byte intCA1[TWOK_BUF];
  45230. byte intCA2[TWOK_BUF];
  45231. byte cert[TWOK_BUF];
  45232. byte key[TWOK_BUF];
  45233. word32 intCARootSz = sizeof(intCARoot);
  45234. word32 intCA1Sz = sizeof(intCA1);
  45235. word32 intCA2Sz = sizeof(intCA2);
  45236. word32 certSz = sizeof(cert);
  45237. word32 keySz = sizeof(key);
  45238. XMEMSET(intCARoot, 0, intCARootSz);
  45239. XMEMSET(intCA1, 0, intCA1Sz);
  45240. XMEMSET(intCA2, 0, intCA2Sz);
  45241. XMEMSET(cert, 0, certSz);
  45242. XMEMSET(key, 0, keySz);
  45243. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  45244. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  45245. cert, &certSz, key, &keySz);
  45246. ExpectIntEQ(ret, 0);
  45247. XMEMSET(output, 0, outputSz);
  45248. ExpectIntEQ(wc_InitRng(&rng), 0);
  45249. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45250. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45251. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45252. if (useIntermediateCertChain == 1) {
  45253. /* Add intermediate and root CA certs into SignedData Certs SET */
  45254. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  45255. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  45256. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  45257. }
  45258. if (pkcs7 != NULL) {
  45259. pkcs7->content = data;
  45260. pkcs7->contentSz = dataSz;
  45261. pkcs7->privateKey = key;
  45262. pkcs7->privateKeySz = (word32)sizeof(key);
  45263. if (pkAlgoType == RSA_TYPE) {
  45264. pkcs7->encryptOID = RSAk;
  45265. }
  45266. else {
  45267. pkcs7->encryptOID = ECDSAk;
  45268. }
  45269. #ifdef NO_SHA
  45270. pkcs7->hashOID = SHA256h;
  45271. #else
  45272. pkcs7->hashOID = SHAh;
  45273. #endif
  45274. pkcs7->rng = &rng;
  45275. if (withAttribs) {
  45276. /* include a signed attribute */
  45277. pkcs7->signedAttribs = attribs;
  45278. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  45279. }
  45280. }
  45281. if (detachedSig) {
  45282. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  45283. }
  45284. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  45285. ExpectIntGT(outputSz, 0);
  45286. wc_PKCS7_Free(pkcs7);
  45287. pkcs7 = NULL;
  45288. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45289. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45290. if (detachedSig && (pkcs7 != NULL)) {
  45291. pkcs7->content = data;
  45292. pkcs7->contentSz = dataSz;
  45293. }
  45294. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  45295. wc_PKCS7_Free(pkcs7);
  45296. wc_FreeRng(&rng);
  45297. if (EXPECT_FAIL()) {
  45298. outputSz = 0;
  45299. }
  45300. return outputSz;
  45301. }
  45302. #endif
  45303. /*
  45304. * Testing wc_PKCS_VerifySignedData()
  45305. */
  45306. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  45307. {
  45308. EXPECT_DECLS;
  45309. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  45310. PKCS7* pkcs7 = NULL;
  45311. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45312. word32 outputSz = sizeof(output);
  45313. byte data[] = "Test data to encode.";
  45314. byte badOut[1];
  45315. word32 badOutSz = 0;
  45316. byte badContent[] = "This is different content than was signed";
  45317. wc_HashAlg hash;
  45318. #ifdef NO_SHA
  45319. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45320. #else
  45321. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45322. #endif
  45323. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45324. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45325. #ifndef NO_RSA
  45326. PKCS7DecodedAttrib* decodedAttrib = NULL;
  45327. /* contentType OID (1.2.840.113549.1.9.3) */
  45328. static const byte contentTypeOid[] =
  45329. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  45330. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  45331. static const byte dataType[] =
  45332. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  45333. /* messageDigest OID (1.2.840.113549.1.9.4) */
  45334. static const byte messageDigestOid[] =
  45335. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  45336. #ifndef NO_ASN_TIME
  45337. /* signingTime OID () */
  45338. static const byte signingTimeOid[] =
  45339. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  45340. #endif
  45341. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45342. int dateLength = 0;
  45343. byte dateFormat;
  45344. const byte* datePart = NULL;
  45345. struct tm timearg;
  45346. time_t now;
  45347. struct tm* nowTm = NULL;
  45348. #ifdef NEED_TMP_TIME
  45349. struct tm tmpTimeStorage;
  45350. struct tm* tmpTime = &tmpTimeStorage;
  45351. #endif
  45352. #endif /* !NO_ASN && !NO_ASN_TIME */
  45353. #ifndef NO_PKCS7_STREAM
  45354. word32 z;
  45355. int ret;
  45356. #endif /* !NO_PKCS7_STREAM */
  45357. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45358. /* Success test with RSA certs/key */
  45359. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45360. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  45361. /* calculate hash for content, used later */
  45362. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45363. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45364. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45365. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45366. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45367. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45368. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45369. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45370. #ifndef NO_PKCS7_STREAM
  45371. wc_PKCS7_Free(pkcs7);
  45372. pkcs7 = NULL;
  45373. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45374. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45375. /* test for streaming */
  45376. ret = -1;
  45377. for (z = 0; z < outputSz && ret != 0; z++) {
  45378. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45379. if (ret < 0){
  45380. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45381. }
  45382. }
  45383. ExpectIntEQ(ret, 0);
  45384. ExpectIntNE(pkcs7->contentSz, 0);
  45385. ExpectNotNull(pkcs7->contentDynamic);
  45386. #endif /* !NO_PKCS7_STREAM */
  45387. /* Check that decoded signed attributes are correct */
  45388. /* messageDigest should be first */
  45389. if (pkcs7 != NULL) {
  45390. decodedAttrib = pkcs7->decodedAttrib;
  45391. }
  45392. ExpectNotNull(decodedAttrib);
  45393. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  45394. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  45395. decodedAttrib->oidSz), 0);
  45396. /* + 2 for OCTET STRING and length bytes */
  45397. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  45398. ExpectNotNull(decodedAttrib->value);
  45399. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  45400. #ifndef NO_ASN_TIME
  45401. /* signingTime should be second */
  45402. if (decodedAttrib != NULL) {
  45403. decodedAttrib = decodedAttrib->next;
  45404. }
  45405. ExpectNotNull(decodedAttrib);
  45406. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  45407. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  45408. decodedAttrib->oidSz), 0);
  45409. ExpectIntGT(decodedAttrib->valueSz, 0);
  45410. ExpectNotNull(decodedAttrib->value);
  45411. #endif
  45412. /* Verify signingTime if ASN and time are available */
  45413. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45414. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  45415. &datePart, &dateFormat, &dateLength), 0);
  45416. ExpectNotNull(datePart);
  45417. ExpectIntGT(dateLength, 0);
  45418. XMEMSET(&timearg, 0, sizeof(timearg));
  45419. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  45420. &timearg), 0);
  45421. /* Get current time and compare year/month/day against attribute value */
  45422. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  45423. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  45424. ExpectNotNull(nowTm);
  45425. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  45426. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  45427. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  45428. #endif /* !NO_ASN && !NO_ASN_TIME */
  45429. /* contentType should be third */
  45430. if (decodedAttrib != NULL) {
  45431. decodedAttrib = decodedAttrib->next;
  45432. }
  45433. ExpectNotNull(decodedAttrib);
  45434. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  45435. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  45436. decodedAttrib->oidSz), 0);
  45437. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  45438. ExpectNotNull(decodedAttrib->value);
  45439. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  45440. 0);
  45441. #endif /* !NO_RSA */
  45442. /* Test bad args. */
  45443. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  45444. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45445. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  45446. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45447. #ifndef NO_PKCS7_STREAM
  45448. /* can pass in 0 buffer length with streaming API */
  45449. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45450. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45451. #else
  45452. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45453. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45454. #endif
  45455. wc_PKCS7_Free(pkcs7);
  45456. pkcs7 = NULL;
  45457. #ifndef NO_RSA
  45458. /* Try RSA certs/key/sig first */
  45459. outputSz = sizeof(output);
  45460. XMEMSET(output, 0, outputSz);
  45461. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45462. (word32)sizeof(data),
  45463. 1, 1, 0, RSA_TYPE)), 0);
  45464. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45465. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45466. if (pkcs7 != NULL) {
  45467. pkcs7->content = badContent;
  45468. pkcs7->contentSz = sizeof(badContent);
  45469. }
  45470. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45471. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45472. wc_PKCS7_Free(pkcs7);
  45473. pkcs7 = NULL;
  45474. #ifndef NO_PKCS7_STREAM
  45475. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45476. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45477. if (pkcs7 != NULL) {
  45478. pkcs7->content = badContent;
  45479. pkcs7->contentSz = sizeof(badContent);
  45480. }
  45481. /* test for streaming */
  45482. ret = -1;
  45483. for (z = 0; z < outputSz && ret != 0; z++) {
  45484. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45485. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45486. continue;
  45487. }
  45488. else if (ret < 0) {
  45489. break;
  45490. }
  45491. }
  45492. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45493. ExpectIntNE(pkcs7->contentSz, 0);
  45494. ExpectNotNull(pkcs7->contentDynamic);
  45495. wc_PKCS7_Free(pkcs7);
  45496. pkcs7 = NULL;
  45497. #endif /* !NO_PKCS7_STREAM */
  45498. /* Test success case with detached signature and valid content */
  45499. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45500. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45501. if (pkcs7 != NULL) {
  45502. pkcs7->content = data;
  45503. pkcs7->contentSz = sizeof(data);
  45504. }
  45505. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45506. wc_PKCS7_Free(pkcs7);
  45507. pkcs7 = NULL;
  45508. #ifndef NO_PKCS7_STREAM
  45509. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45510. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45511. if (pkcs7 != NULL) {
  45512. pkcs7->content = data;
  45513. pkcs7->contentSz = sizeof(data);
  45514. }
  45515. /* test for streaming */
  45516. ret = -1;
  45517. for (z = 0; z < outputSz && ret != 0; z++) {
  45518. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45519. if (ret < 0){
  45520. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45521. }
  45522. }
  45523. ExpectIntEQ(ret, 0);
  45524. ExpectIntNE(pkcs7->contentSz, 0);
  45525. ExpectNotNull(pkcs7->contentDynamic);
  45526. wc_PKCS7_Free(pkcs7);
  45527. pkcs7 = NULL;
  45528. #endif /* !NO_PKCS7_STREAM */
  45529. /* verify using pre-computed content digest only (no content) */
  45530. {
  45531. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45532. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45533. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45534. output, outputSz, NULL, 0), 0);
  45535. wc_PKCS7_Free(pkcs7);
  45536. pkcs7 = NULL;
  45537. }
  45538. #endif /* !NO_RSA */
  45539. /* Test verify on signedData containing intermediate/root CA certs */
  45540. #ifndef NO_RSA
  45541. outputSz = sizeof(output);
  45542. XMEMSET(output, 0, outputSz);
  45543. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45544. (word32)sizeof(data),
  45545. 0, 0, 1, RSA_TYPE)), 0);
  45546. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45547. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45548. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45549. wc_PKCS7_Free(pkcs7);
  45550. pkcs7 = NULL;
  45551. #ifndef NO_PKCS7_STREAM
  45552. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45553. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45554. /* test for streaming */
  45555. ret = -1;
  45556. for (z = 0; z < outputSz && ret != 0; z++) {
  45557. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45558. if (ret < 0){
  45559. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45560. }
  45561. }
  45562. ExpectIntEQ(ret, 0);
  45563. ExpectIntNE(pkcs7->contentSz, 0);
  45564. ExpectNotNull(pkcs7->contentDynamic);
  45565. wc_PKCS7_Free(pkcs7);
  45566. pkcs7 = NULL;
  45567. #endif /* !NO_PKCS7_STREAM */
  45568. #endif /* !NO_RSA */
  45569. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  45570. !defined(NO_FILESYSTEM)
  45571. {
  45572. XFILE signedBundle = XBADFILE;
  45573. int signedBundleSz = 0;
  45574. int chunkSz = 1;
  45575. int i, rc = 0;
  45576. byte* buf = NULL;
  45577. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  45578. "rb")) != XBADFILE);
  45579. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  45580. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  45581. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  45582. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  45583. DYNAMIC_TYPE_FILE));
  45584. if (buf != NULL) {
  45585. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  45586. signedBundleSz);
  45587. }
  45588. if (signedBundle != XBADFILE) {
  45589. XFCLOSE(signedBundle);
  45590. signedBundle = XBADFILE;
  45591. }
  45592. if (buf != NULL) {
  45593. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45594. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45595. for (i = 0; i < signedBundleSz;) {
  45596. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45597. chunkSz;
  45598. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45599. if (rc < 0 ) {
  45600. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45601. i += sz;
  45602. continue;
  45603. }
  45604. break;
  45605. }
  45606. else {
  45607. break;
  45608. }
  45609. }
  45610. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  45611. wc_PKCS7_Free(pkcs7);
  45612. pkcs7 = NULL;
  45613. }
  45614. /* now try with malformed bundle */
  45615. if (buf != NULL) {
  45616. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45617. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45618. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  45619. for (i = 0; i < signedBundleSz;) {
  45620. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45621. chunkSz;
  45622. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45623. if (rc < 0 ) {
  45624. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45625. i += sz;
  45626. continue;
  45627. }
  45628. break;
  45629. }
  45630. else {
  45631. break;
  45632. }
  45633. }
  45634. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  45635. wc_PKCS7_Free(pkcs7);
  45636. pkcs7 = NULL;
  45637. }
  45638. if (buf != NULL)
  45639. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  45640. }
  45641. #endif /* BER and stream */
  45642. #endif
  45643. return EXPECT_RESULT();
  45644. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  45645. /*
  45646. * Testing wc_PKCS_VerifySignedData()
  45647. */
  45648. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  45649. {
  45650. EXPECT_DECLS;
  45651. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  45652. PKCS7* pkcs7 = NULL;
  45653. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45654. word32 outputSz = sizeof(output);
  45655. byte data[] = "Test data to encode.";
  45656. byte badContent[] = "This is different content than was signed";
  45657. wc_HashAlg hash;
  45658. #ifndef NO_PKCS7_STREAM
  45659. word32 z;
  45660. int ret;
  45661. #endif /* !NO_PKCS7_STREAM */
  45662. #ifdef NO_SHA
  45663. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45664. #else
  45665. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45666. #endif
  45667. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45668. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45669. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45670. /* Success test with ECC certs/key */
  45671. outputSz = sizeof(output);
  45672. XMEMSET(output, 0, outputSz);
  45673. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45674. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  45675. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45676. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45677. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45678. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45679. wc_PKCS7_Free(pkcs7);
  45680. pkcs7 = NULL;
  45681. #ifndef NO_PKCS7_STREAM
  45682. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45683. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45684. /* test for streaming */
  45685. ret = -1;
  45686. for (z = 0; z < outputSz && ret != 0; z++) {
  45687. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45688. if (ret < 0){
  45689. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45690. }
  45691. }
  45692. ExpectIntEQ(ret, 0);
  45693. ExpectIntNE(pkcs7->contentSz, 0);
  45694. ExpectNotNull(pkcs7->contentDynamic);
  45695. wc_PKCS7_Free(pkcs7);
  45696. pkcs7 = NULL;
  45697. #endif /* !NO_PKCS7_STREAM */
  45698. /* Invalid content should error, use detached signature so we can
  45699. * easily change content */
  45700. outputSz = sizeof(output);
  45701. XMEMSET(output, 0, outputSz);
  45702. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45703. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  45704. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45705. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45706. if (pkcs7 != NULL) {
  45707. pkcs7->content = badContent;
  45708. pkcs7->contentSz = sizeof(badContent);
  45709. }
  45710. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45711. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45712. wc_PKCS7_Free(pkcs7);
  45713. pkcs7 = NULL;
  45714. #ifndef NO_PKCS7_STREAM
  45715. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45716. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45717. if (pkcs7 != NULL) {
  45718. pkcs7->content = badContent;
  45719. pkcs7->contentSz = sizeof(badContent);
  45720. }
  45721. /* test for streaming */
  45722. ret = -1;
  45723. for (z = 0; z < outputSz && ret != 0; z++) {
  45724. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45725. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45726. continue;
  45727. }
  45728. else if (ret < 0) {
  45729. break;
  45730. }
  45731. }
  45732. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45733. ExpectIntNE(pkcs7->contentSz, 0);
  45734. ExpectNotNull(pkcs7->contentDynamic);
  45735. wc_PKCS7_Free(pkcs7);
  45736. pkcs7 = NULL;
  45737. #endif /* !NO_PKCS7_STREAM */
  45738. /* Test success case with detached signature and valid content */
  45739. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45740. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45741. if (pkcs7 != NULL) {
  45742. pkcs7->content = data;
  45743. pkcs7->contentSz = sizeof(data);
  45744. }
  45745. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45746. wc_PKCS7_Free(pkcs7);
  45747. pkcs7 = NULL;
  45748. #ifndef NO_PKCS7_STREAM
  45749. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45750. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45751. if (pkcs7 != NULL) {
  45752. pkcs7->content = data;
  45753. pkcs7->contentSz = sizeof(data);
  45754. }
  45755. /* test for streaming */
  45756. ret = -1;
  45757. for (z = 0; z < outputSz && ret != 0; z++) {
  45758. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45759. if (ret < 0){
  45760. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45761. }
  45762. }
  45763. ExpectIntEQ(ret, 0);
  45764. ExpectIntNE(pkcs7->contentSz, 0);
  45765. ExpectNotNull(pkcs7->contentDynamic);
  45766. wc_PKCS7_Free(pkcs7);
  45767. pkcs7 = NULL;
  45768. #endif /* !NO_PKCS7_STREAM */
  45769. /* verify using pre-computed content digest only (no content) */
  45770. {
  45771. /* calculate hash for content */
  45772. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45773. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45774. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45775. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45776. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45777. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45778. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45779. output, outputSz, NULL, 0), 0);
  45780. wc_PKCS7_Free(pkcs7);
  45781. pkcs7 = NULL;
  45782. }
  45783. /* Test verify on signedData containing intermediate/root CA certs */
  45784. outputSz = sizeof(output);
  45785. XMEMSET(output, 0, outputSz);
  45786. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45787. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  45788. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45789. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45790. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45791. wc_PKCS7_Free(pkcs7);
  45792. pkcs7 = NULL;
  45793. #ifndef NO_PKCS7_STREAM
  45794. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45795. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45796. /* test for streaming */
  45797. ret = -1;
  45798. for (z = 0; z < outputSz && ret != 0; z++) {
  45799. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45800. if (ret < 0){
  45801. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45802. }
  45803. }
  45804. ExpectIntEQ(ret, 0);
  45805. ExpectIntNE(pkcs7->contentSz, 0);
  45806. ExpectNotNull(pkcs7->contentDynamic);
  45807. wc_PKCS7_Free(pkcs7);
  45808. pkcs7 = NULL;
  45809. #endif /* !NO_PKCS7_STREAM */
  45810. #endif
  45811. return EXPECT_RESULT();
  45812. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  45813. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  45814. !defined(NO_AES_256)
  45815. static const byte defKey[] = {
  45816. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45817. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45818. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45819. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45820. };
  45821. static byte aesHandle[32]; /* simulated hardware key handle */
  45822. /* return 0 on success */
  45823. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45824. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45825. byte* in, int inSz, byte* out, void* usrCtx)
  45826. {
  45827. int ret;
  45828. Aes aes;
  45829. if (usrCtx == NULL) {
  45830. /* no simulated handle passed in */
  45831. return -1;
  45832. }
  45833. switch (encryptOID) {
  45834. case AES256CBCb:
  45835. if (ivSz != AES_BLOCK_SIZE)
  45836. return BAD_FUNC_ARG;
  45837. break;
  45838. default:
  45839. WOLFSSL_MSG("Unsupported content cipher type for test");
  45840. return ALGO_ID_E;
  45841. };
  45842. /* simulate using handle to get key */
  45843. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  45844. if (ret == 0) {
  45845. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  45846. if (ret == 0)
  45847. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  45848. wc_AesFree(&aes);
  45849. }
  45850. (void)aad;
  45851. (void)aadSz;
  45852. (void)authTag;
  45853. (void)authTagSz;
  45854. (void)pkcs7;
  45855. return ret;
  45856. }
  45857. /* returns key size on success */
  45858. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  45859. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  45860. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  45861. {
  45862. int ret = -1;
  45863. (void)cekSz;
  45864. (void)cek;
  45865. (void)outSz;
  45866. (void)keyIdSz;
  45867. (void)direction;
  45868. (void)orginKey; /* used with KAKRI */
  45869. (void)orginKeySz;
  45870. if (out == NULL)
  45871. return BAD_FUNC_ARG;
  45872. if (keyId[0] != 0x00) {
  45873. return -1;
  45874. }
  45875. if (type != (int)PKCS7_KEKRI) {
  45876. return -1;
  45877. }
  45878. switch (keyWrapAlgo) {
  45879. case AES256_WRAP:
  45880. /* simulate setting a handle for later decryption but use key
  45881. * as handle in the test case here */
  45882. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  45883. aesHandle, sizeof(aesHandle), NULL);
  45884. if (ret < 0)
  45885. return ret;
  45886. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  45887. if (ret < 0)
  45888. return ret;
  45889. /* return key size on success */
  45890. return sizeof(defKey);
  45891. default:
  45892. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  45893. return BAD_KEYWRAP_ALG_E;
  45894. };
  45895. }
  45896. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  45897. /*
  45898. * Testing wc_PKCS7_EncodeEnvelopedData()
  45899. */
  45900. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  45901. {
  45902. EXPECT_DECLS;
  45903. #if defined(HAVE_PKCS7)
  45904. PKCS7* pkcs7 = NULL;
  45905. #ifdef ASN_BER_TO_DER
  45906. int encodedSz = 0;
  45907. #endif
  45908. #ifdef ECC_TIMING_RESISTANT
  45909. WC_RNG rng;
  45910. #endif
  45911. word32 tempWrd32 = 0;
  45912. byte* tmpBytePtr = NULL;
  45913. const char input[] = "Test data to encode.";
  45914. int i;
  45915. int testSz = 0;
  45916. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  45917. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45918. byte* rsaCert = NULL;
  45919. byte* rsaPrivKey = NULL;
  45920. word32 rsaCertSz;
  45921. word32 rsaPrivKeySz;
  45922. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  45923. !defined(USE_CERT_BUFFERS_2048) )
  45924. static const char* rsaClientCert = "./certs/client-cert.der";
  45925. static const char* rsaClientKey = "./certs/client-key.der";
  45926. rsaCertSz = (word32)sizeof(rsaClientCert);
  45927. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  45928. #endif
  45929. #endif
  45930. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45931. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45932. byte* eccCert = NULL;
  45933. byte* eccPrivKey = NULL;
  45934. word32 eccCertSz;
  45935. word32 eccPrivKeySz;
  45936. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  45937. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  45938. static const char* eccClientKey = "./certs/ecc-client-key.der";
  45939. #endif
  45940. #endif
  45941. /* Generic buffer size. */
  45942. byte output[ONEK_BUF];
  45943. byte decoded[sizeof(input)/sizeof(char)];
  45944. int decodedSz = 0;
  45945. #ifndef NO_FILESYSTEM
  45946. XFILE certFile = XBADFILE;
  45947. XFILE keyFile = XBADFILE;
  45948. #endif
  45949. #ifdef ECC_TIMING_RESISTANT
  45950. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45951. #endif
  45952. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45953. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45954. /* RSA certs and keys. */
  45955. #if defined(USE_CERT_BUFFERS_1024)
  45956. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  45957. /* Allocate buffer space. */
  45958. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45959. DYNAMIC_TYPE_TMP_BUFFER));
  45960. /* Init buffer. */
  45961. if (rsaCert != NULL) {
  45962. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  45963. }
  45964. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  45965. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45966. DYNAMIC_TYPE_TMP_BUFFER));
  45967. if (rsaPrivKey != NULL) {
  45968. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  45969. }
  45970. #elif defined(USE_CERT_BUFFERS_2048)
  45971. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  45972. /* Allocate buffer */
  45973. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45974. DYNAMIC_TYPE_TMP_BUFFER));
  45975. /* Init buffer. */
  45976. if (rsaCert != NULL) {
  45977. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  45978. }
  45979. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  45980. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45981. DYNAMIC_TYPE_TMP_BUFFER));
  45982. if (rsaPrivKey != NULL) {
  45983. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  45984. }
  45985. #else
  45986. /* File system. */
  45987. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  45988. rsaCertSz = (word32)FOURK_BUF;
  45989. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45990. DYNAMIC_TYPE_TMP_BUFFER));
  45991. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  45992. certFile)) > 0);
  45993. if (certFile != XBADFILE)
  45994. XFCLOSE(certFile);
  45995. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  45996. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45997. DYNAMIC_TYPE_TMP_BUFFER));
  45998. rsaPrivKeySz = (word32)FOURK_BUF;
  45999. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  46000. keyFile)) > 0);
  46001. if (keyFile != XBADFILE)
  46002. XFCLOSE(keyFile);
  46003. #endif /* USE_CERT_BUFFERS */
  46004. #endif /* NO_RSA */
  46005. /* ECC */
  46006. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46007. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46008. #ifdef USE_CERT_BUFFERS_256
  46009. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46010. DYNAMIC_TYPE_TMP_BUFFER));
  46011. /* Init buffer. */
  46012. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  46013. if (eccCert != NULL) {
  46014. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  46015. }
  46016. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46017. DYNAMIC_TYPE_TMP_BUFFER));
  46018. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  46019. if (eccPrivKey != NULL) {
  46020. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  46021. }
  46022. #else /* File system. */
  46023. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  46024. eccCertSz = (word32)FOURK_BUF;
  46025. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46026. DYNAMIC_TYPE_TMP_BUFFER));
  46027. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  46028. certFile)) > 0);
  46029. if (certFile != XBADFILE) {
  46030. XFCLOSE(certFile);
  46031. }
  46032. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  46033. eccPrivKeySz = (word32)FOURK_BUF;
  46034. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46035. DYNAMIC_TYPE_TMP_BUFFER));
  46036. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  46037. keyFile)) > 0);
  46038. if (keyFile != XBADFILE) {
  46039. XFCLOSE(keyFile);
  46040. }
  46041. #endif /* USE_CERT_BUFFERS_256 */
  46042. #endif /* END HAVE_ECC */
  46043. #ifndef NO_FILESYSTEM
  46044. /* Silence. */
  46045. (void)keyFile;
  46046. (void)certFile;
  46047. #endif
  46048. {
  46049. const pkcs7EnvelopedVector testVectors[] = {
  46050. /* DATA is a global variable defined in the makefile. */
  46051. #if !defined(NO_RSA)
  46052. #ifndef NO_DES3
  46053. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  46054. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46055. #endif /* NO_DES3 */
  46056. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46057. #ifndef NO_AES_128
  46058. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  46059. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46060. #endif
  46061. #ifndef NO_AES_192
  46062. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  46063. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46064. #endif
  46065. #ifndef NO_AES_256
  46066. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  46067. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46068. #endif
  46069. #endif /* NO_AES && HAVE_AES_CBC */
  46070. #endif /* NO_RSA */
  46071. #if defined(HAVE_ECC)
  46072. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46073. #if !defined(NO_SHA) && !defined(NO_AES_128)
  46074. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46075. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  46076. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46077. #endif
  46078. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  46079. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46080. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  46081. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46082. #endif
  46083. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  46084. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46085. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  46086. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46087. #endif
  46088. #endif /* NO_AES && HAVE_AES_CBC*/
  46089. #endif /* END HAVE_ECC */
  46090. }; /* END pkcs7EnvelopedVector */
  46091. #ifdef ECC_TIMING_RESISTANT
  46092. ExpectIntEQ(wc_InitRng(&rng), 0);
  46093. #endif
  46094. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46095. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46096. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  46097. for (i = 0; i < testSz; i++) {
  46098. #ifdef ASN_BER_TO_DER
  46099. encodeSignedDataStream strm;
  46100. /* test setting stream mode, the first one using IO callbacks */
  46101. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46102. (word32)(testVectors + i)->certSz), 0);
  46103. if (pkcs7 != NULL) {
  46104. #ifdef ECC_TIMING_RESISTANT
  46105. pkcs7->rng = &rng;
  46106. #endif
  46107. if (i != 0)
  46108. pkcs7->content = (byte*)(testVectors + i)->content;
  46109. pkcs7->contentSz = (testVectors + i)->contentSz;
  46110. pkcs7->contentOID = (testVectors + i)->contentOID;
  46111. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46112. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46113. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46114. pkcs7->privateKey = (testVectors + i)->privateKey;
  46115. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46116. }
  46117. if (i == 0) {
  46118. XMEMSET(&strm, 0, sizeof(strm));
  46119. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  46120. StreamOutputCB, (void*)&strm), 0);
  46121. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  46122. }
  46123. else {
  46124. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  46125. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46126. (word32)sizeof(output));
  46127. }
  46128. switch ((testVectors + i)->encryptOID) {
  46129. #ifndef NO_DES3
  46130. case DES3b:
  46131. case DESb:
  46132. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46133. break;
  46134. #endif
  46135. #ifdef HAVE_AESCCM
  46136. #ifdef WOLFSSL_AES_128
  46137. case AES128CCMb:
  46138. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46139. break;
  46140. #endif
  46141. #ifdef WOLFSSL_AES_192
  46142. case AES192CCMb:
  46143. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46144. break;
  46145. #endif
  46146. #ifdef WOLFSSL_AES_256
  46147. case AES256CCMb:
  46148. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46149. break;
  46150. #endif
  46151. #endif
  46152. default:
  46153. ExpectIntGE(encodedSz, 0);
  46154. }
  46155. if (encodedSz > 0) {
  46156. if (i == 0) {
  46157. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  46158. strm.out, (word32)encodedSz, decoded,
  46159. (word32)sizeof(decoded));
  46160. }
  46161. else {
  46162. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46163. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  46164. }
  46165. ExpectIntGE(decodedSz, 0);
  46166. /* Verify the size of each buffer. */
  46167. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  46168. }
  46169. wc_PKCS7_Free(pkcs7);
  46170. pkcs7 = NULL;
  46171. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46172. #endif
  46173. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46174. (word32)(testVectors + i)->certSz), 0);
  46175. if (pkcs7 != NULL) {
  46176. #ifdef ECC_TIMING_RESISTANT
  46177. pkcs7->rng = &rng;
  46178. #endif
  46179. pkcs7->content = (byte*)(testVectors + i)->content;
  46180. pkcs7->contentSz = (testVectors + i)->contentSz;
  46181. pkcs7->contentOID = (testVectors + i)->contentOID;
  46182. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46183. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46184. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46185. pkcs7->privateKey = (testVectors + i)->privateKey;
  46186. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46187. }
  46188. #ifdef ASN_BER_TO_DER
  46189. /* test without setting stream mode */
  46190. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  46191. #endif
  46192. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46193. (word32)sizeof(output)), 0);
  46194. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46195. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  46196. ExpectIntGE(decodedSz, 0);
  46197. /* Verify the size of each buffer. */
  46198. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  46199. /* Don't free the last time through the loop. */
  46200. if (i < testSz - 1) {
  46201. wc_PKCS7_Free(pkcs7);
  46202. pkcs7 = NULL;
  46203. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46204. }
  46205. } /* END test loop. */
  46206. }
  46207. /* Test bad args. */
  46208. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  46209. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46210. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  46211. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46212. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46213. /* Decode. */
  46214. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  46215. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46216. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46217. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46218. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46219. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46220. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46221. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  46222. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46223. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46224. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  46225. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46226. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  46227. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46228. /* only a failure for KARI test cases */
  46229. if (pkcs7 != NULL) {
  46230. tempWrd32 = pkcs7->singleCertSz;
  46231. pkcs7->singleCertSz = 0;
  46232. }
  46233. #if defined(WOLFSSL_ASN_TEMPLATE)
  46234. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46235. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46236. WC_NO_ERR_TRACE(BUFFER_E));
  46237. #else
  46238. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46239. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46240. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46241. #endif
  46242. if (pkcs7 != NULL) {
  46243. pkcs7->singleCertSz = tempWrd32;
  46244. tmpBytePtr = pkcs7->singleCert;
  46245. pkcs7->singleCert = NULL;
  46246. }
  46247. #ifndef NO_RSA
  46248. #if defined(NO_PKCS7_STREAM)
  46249. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  46250. * is returned from kari parse which gets set to bad func arg */
  46251. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46252. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46254. #else
  46255. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46256. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46257. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46258. #endif
  46259. #endif /* !NO_RSA */
  46260. if (pkcs7 != NULL) {
  46261. pkcs7->singleCert = tmpBytePtr;
  46262. }
  46263. #endif
  46264. if (pkcs7 != NULL) {
  46265. tempWrd32 = pkcs7->privateKeySz;
  46266. pkcs7->privateKeySz = 0;
  46267. }
  46268. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46269. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46270. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46271. if (pkcs7 != NULL) {
  46272. pkcs7->privateKeySz = tempWrd32;
  46273. tmpBytePtr = pkcs7->privateKey;
  46274. pkcs7->privateKey = NULL;
  46275. }
  46276. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46277. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46278. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46279. if (pkcs7 != NULL) {
  46280. pkcs7->privateKey = tmpBytePtr;
  46281. }
  46282. wc_PKCS7_Free(pkcs7);
  46283. pkcs7 = NULL;
  46284. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  46285. /* test of decrypt callback with KEKRI enveloped data */
  46286. {
  46287. int envelopedSz = 0;
  46288. const byte keyId[] = { 0x00 };
  46289. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46290. if (pkcs7 != NULL) {
  46291. pkcs7->content = (byte*)input;
  46292. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  46293. pkcs7->contentOID = DATA;
  46294. pkcs7->encryptOID = AES256CBCb;
  46295. }
  46296. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  46297. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  46298. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  46299. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  46300. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46301. (word32)sizeof(output))), 0);
  46302. wc_PKCS7_Free(pkcs7);
  46303. pkcs7 = NULL;
  46304. /* decode envelopedData */
  46305. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46306. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  46307. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  46308. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46309. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  46310. wc_PKCS7_Free(pkcs7);
  46311. pkcs7 = NULL;
  46312. }
  46313. #endif /* !NO_AES && !NO_AES_256 */
  46314. #ifndef NO_RSA
  46315. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46316. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46317. #endif /* NO_RSA */
  46318. #ifdef HAVE_ECC
  46319. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46320. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46321. #endif /* HAVE_ECC */
  46322. #ifdef ECC_TIMING_RESISTANT
  46323. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46324. #endif
  46325. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  46326. !defined(NO_RSA) && !defined(NO_SHA)
  46327. {
  46328. byte out[7];
  46329. byte *cms = NULL;
  46330. word32 cmsSz;
  46331. XFILE cmsFile = XBADFILE;
  46332. XMEMSET(out, 0, sizeof(out));
  46333. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46334. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  46335. != XBADFILE);
  46336. cmsSz = (word32)FOURK_BUF;
  46337. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46338. DYNAMIC_TYPE_TMP_BUFFER));
  46339. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  46340. if (cmsFile != XBADFILE)
  46341. XFCLOSE(cmsFile);
  46342. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  46343. sizeof_client_cert_der_2048), 0);
  46344. if (pkcs7 != NULL) {
  46345. pkcs7->privateKey = (byte*)client_key_der_2048;
  46346. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  46347. }
  46348. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46349. 2), 0);
  46350. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46351. sizeof(out)), 0);
  46352. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46353. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  46354. wc_PKCS7_Free(pkcs7);
  46355. pkcs7 = NULL;
  46356. }
  46357. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  46358. #endif /* HAVE_PKCS7 */
  46359. return EXPECT_RESULT();
  46360. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  46361. /*
  46362. * Testing wc_PKCS7_EncodeEncryptedData()
  46363. */
  46364. static int test_wc_PKCS7_EncodeEncryptedData(void)
  46365. {
  46366. EXPECT_DECLS;
  46367. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  46368. PKCS7* pkcs7 = NULL;
  46369. byte* tmpBytePtr = NULL;
  46370. byte encrypted[TWOK_BUF];
  46371. byte decoded[TWOK_BUF];
  46372. word32 tmpWrd32 = 0;
  46373. int tmpInt = 0;
  46374. int decodedSz = 0;
  46375. int encryptedSz = 0;
  46376. int testSz = 0;
  46377. int i = 0;
  46378. const byte data[] = { /* Hello World */
  46379. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46380. 0x72,0x6c,0x64
  46381. };
  46382. #ifndef NO_DES3
  46383. byte desKey[] = {
  46384. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  46385. };
  46386. byte des3Key[] = {
  46387. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  46388. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  46389. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  46390. };
  46391. #endif
  46392. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46393. #ifndef NO_AES_128
  46394. byte aes128Key[] = {
  46395. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46396. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46397. };
  46398. #endif
  46399. #ifndef NO_AES_192
  46400. byte aes192Key[] = {
  46401. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46402. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46403. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46404. };
  46405. #endif
  46406. #ifndef NO_AES_256
  46407. byte aes256Key[] = {
  46408. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46409. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46410. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46411. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46412. };
  46413. #endif
  46414. #endif /* !NO_AES && HAVE_AES_CBC */
  46415. const pkcs7EncryptedVector testVectors[] =
  46416. {
  46417. #ifndef NO_DES3
  46418. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  46419. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  46420. #endif /* !NO_DES3 */
  46421. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46422. #ifndef NO_AES_128
  46423. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  46424. sizeof(aes128Key)},
  46425. #endif
  46426. #ifndef NO_AES_192
  46427. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  46428. sizeof(aes192Key)},
  46429. #endif
  46430. #ifndef NO_AES_256
  46431. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46432. sizeof(aes256Key)},
  46433. #endif
  46434. #endif /* !NO_AES && HAVE_AES_CBC */
  46435. };
  46436. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  46437. for (i = 0; i < testSz; i++) {
  46438. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46439. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46440. if (pkcs7 != NULL) {
  46441. pkcs7->content = (byte*)testVectors[i].content;
  46442. pkcs7->contentSz = testVectors[i].contentSz;
  46443. pkcs7->contentOID = testVectors[i].contentOID;
  46444. pkcs7->encryptOID = testVectors[i].encryptOID;
  46445. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  46446. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  46447. pkcs7->heap = HEAP_HINT;
  46448. }
  46449. /* encode encryptedData */
  46450. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46451. sizeof(encrypted)), 0);
  46452. /* Decode encryptedData */
  46453. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  46454. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  46455. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  46456. /* Keep values for last itr. */
  46457. if (i < testSz - 1) {
  46458. wc_PKCS7_Free(pkcs7);
  46459. pkcs7 = NULL;
  46460. }
  46461. }
  46462. if (pkcs7 == NULL || testSz == 0) {
  46463. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46464. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46465. }
  46466. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  46467. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46468. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  46469. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46470. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46471. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46472. /* Testing the struct. */
  46473. if (pkcs7 != NULL) {
  46474. tmpBytePtr = pkcs7->content;
  46475. pkcs7->content = NULL;
  46476. }
  46477. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46478. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46479. if (pkcs7 != NULL) {
  46480. pkcs7->content = tmpBytePtr;
  46481. tmpWrd32 = pkcs7->contentSz;
  46482. pkcs7->contentSz = 0;
  46483. }
  46484. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46485. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46486. if (pkcs7 != NULL) {
  46487. pkcs7->contentSz = tmpWrd32;
  46488. tmpInt = pkcs7->encryptOID;
  46489. pkcs7->encryptOID = 0;
  46490. }
  46491. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46492. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46493. if (pkcs7 != NULL) {
  46494. pkcs7->encryptOID = tmpInt;
  46495. tmpBytePtr = pkcs7->encryptionKey;
  46496. pkcs7->encryptionKey = NULL;
  46497. }
  46498. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46499. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46500. if (pkcs7 != NULL) {
  46501. pkcs7->encryptionKey = tmpBytePtr;
  46502. tmpWrd32 = pkcs7->encryptionKeySz;
  46503. pkcs7->encryptionKeySz = 0;
  46504. }
  46505. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46506. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46507. if (pkcs7 != NULL) {
  46508. pkcs7->encryptionKeySz = tmpWrd32;
  46509. }
  46510. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  46511. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46512. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  46513. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46514. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  46515. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46516. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46517. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46518. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46519. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46520. /* Test struct fields */
  46521. if (pkcs7 != NULL) {
  46522. tmpBytePtr = pkcs7->encryptionKey;
  46523. pkcs7->encryptionKey = NULL;
  46524. }
  46525. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46526. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46527. if (pkcs7 != NULL) {
  46528. pkcs7->encryptionKey = tmpBytePtr;
  46529. pkcs7->encryptionKeySz = 0;
  46530. }
  46531. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46532. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46533. wc_PKCS7_Free(pkcs7);
  46534. #endif
  46535. return EXPECT_RESULT();
  46536. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  46537. /*
  46538. * Testing wc_PKCS7_Degenerate()
  46539. */
  46540. static int test_wc_PKCS7_Degenerate(void)
  46541. {
  46542. EXPECT_DECLS;
  46543. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  46544. PKCS7* pkcs7 = NULL;
  46545. char fName[] = "./certs/test-degenerate.p7b";
  46546. XFILE f = XBADFILE;
  46547. byte der[4096];
  46548. word32 derSz = 0;
  46549. #ifndef NO_PKCS7_STREAM
  46550. word32 z;
  46551. int ret;
  46552. #endif /* !NO_PKCS7_STREAM */
  46553. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46554. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46555. if (f != XBADFILE)
  46556. XFCLOSE(f);
  46557. /* test degenerate success */
  46558. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46559. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46560. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46561. #ifndef NO_RSA
  46562. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46563. #ifndef NO_PKCS7_STREAM
  46564. wc_PKCS7_Free(pkcs7);
  46565. pkcs7 = NULL;
  46566. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46567. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46568. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46569. /* test for streaming */
  46570. ret = -1;
  46571. for (z = 0; z < derSz && ret != 0; z++) {
  46572. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46573. if (ret < 0){
  46574. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46575. }
  46576. }
  46577. ExpectIntEQ(ret, 0);
  46578. #endif /* !NO_PKCS7_STREAM */
  46579. #else
  46580. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46581. #endif /* NO_RSA */
  46582. wc_PKCS7_Free(pkcs7);
  46583. pkcs7 = NULL;
  46584. /* test with turning off degenerate cases */
  46585. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46586. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46587. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46588. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46589. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  46590. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46591. #ifndef NO_PKCS7_STREAM
  46592. wc_PKCS7_Free(pkcs7);
  46593. pkcs7 = NULL;
  46594. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46595. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46596. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46597. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46598. /* test for streaming */
  46599. ret = -1;
  46600. for (z = 0; z < derSz && ret != 0; z++) {
  46601. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46602. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46603. continue;
  46604. }
  46605. else
  46606. break;
  46607. }
  46608. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46609. #endif /* !NO_PKCS7_STREAM */
  46610. wc_PKCS7_Free(pkcs7);
  46611. #endif
  46612. return EXPECT_RESULT();
  46613. } /* END test_wc_PKCS7_Degenerate() */
  46614. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46615. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  46616. static byte berContent[] = {
  46617. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46618. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  46619. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  46620. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  46621. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  46622. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  46623. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  46624. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  46625. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  46626. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  46627. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  46628. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  46629. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  46630. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  46631. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  46632. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  46633. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  46634. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  46635. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  46636. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  46637. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  46638. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  46639. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  46640. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  46641. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  46642. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  46643. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46644. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  46645. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  46646. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  46647. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  46648. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  46649. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  46650. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  46651. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  46652. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  46653. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  46654. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  46655. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  46656. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  46657. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  46658. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  46659. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  46660. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  46661. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46662. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  46663. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  46664. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  46665. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  46666. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  46667. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  46668. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  46669. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  46670. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  46671. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  46672. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  46673. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  46674. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  46675. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  46676. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  46677. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  46678. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  46679. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  46680. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  46681. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  46682. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  46683. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  46684. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  46685. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  46686. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  46687. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  46688. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  46689. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  46690. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  46691. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  46692. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  46693. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  46694. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  46695. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  46696. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  46697. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  46698. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  46699. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  46700. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  46701. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  46702. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  46703. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  46704. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  46705. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  46706. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  46707. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  46708. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  46709. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  46710. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  46711. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  46712. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  46713. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  46714. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  46715. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  46716. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  46717. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  46718. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  46719. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  46720. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  46721. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  46722. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  46723. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  46724. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  46725. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  46726. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  46727. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  46728. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  46729. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  46730. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  46731. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  46732. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  46733. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  46734. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  46735. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  46736. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  46737. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  46738. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  46739. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  46740. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  46741. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  46742. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  46743. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  46744. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  46745. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  46746. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  46747. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  46748. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  46749. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  46750. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  46751. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  46752. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  46753. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  46754. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  46755. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  46756. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  46757. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  46758. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  46759. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  46760. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  46761. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  46762. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  46763. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  46764. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  46765. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  46766. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  46767. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  46768. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  46769. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  46770. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  46771. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  46772. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  46773. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  46774. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  46775. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  46776. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  46777. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  46778. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  46779. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  46780. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  46781. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  46782. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  46783. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  46784. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  46785. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  46786. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  46787. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  46788. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  46789. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  46790. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  46791. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  46792. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  46793. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  46794. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  46795. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  46796. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  46797. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  46798. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  46799. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  46800. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  46801. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  46802. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  46803. 0x00, 0x00, 0x00, 0x00, 0x00
  46804. };
  46805. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  46806. * !NO_DES3 && !NO_SHA
  46807. */
  46808. /*
  46809. * Testing wc_PKCS7_BER()
  46810. */
  46811. static int test_wc_PKCS7_BER(void)
  46812. {
  46813. EXPECT_DECLS;
  46814. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46815. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  46816. PKCS7* pkcs7 = NULL;
  46817. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  46818. XFILE f = XBADFILE;
  46819. byte der[4096];
  46820. #ifndef NO_DES3
  46821. byte decoded[2048];
  46822. #endif
  46823. word32 derSz = 0;
  46824. #ifndef NO_PKCS7_STREAM
  46825. word32 z;
  46826. int ret;
  46827. #endif /* !NO_PKCS7_STREAM */
  46828. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46829. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46830. if (f != XBADFILE) {
  46831. XFCLOSE(f);
  46832. f = XBADFILE;
  46833. }
  46834. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46835. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46836. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46837. #ifndef NO_RSA
  46838. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46839. #ifndef NO_PKCS7_STREAM
  46840. wc_PKCS7_Free(pkcs7);
  46841. pkcs7 = NULL;
  46842. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46843. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46844. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46845. /* test for streaming */
  46846. ret = -1;
  46847. for (z = 0; z < derSz && ret != 0; z++) {
  46848. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46849. if (ret < 0){
  46850. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46851. }
  46852. }
  46853. ExpectIntEQ(ret, 0);
  46854. #endif /* !NO_PKCS7_STREAM */
  46855. #else
  46856. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46857. #endif
  46858. wc_PKCS7_Free(pkcs7);
  46859. pkcs7 = NULL;
  46860. #ifndef NO_DES3
  46861. /* decode BER content */
  46862. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  46863. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46864. if (f != XBADFILE) {
  46865. XFCLOSE(f);
  46866. f = XBADFILE;
  46867. }
  46868. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46869. #ifndef NO_RSA
  46870. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46871. #else
  46872. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46873. #endif
  46874. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  46875. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46876. if (f != XBADFILE) {
  46877. XFCLOSE(f);
  46878. f = XBADFILE;
  46879. }
  46880. if (pkcs7 != NULL) {
  46881. pkcs7->privateKey = der;
  46882. pkcs7->privateKeySz = derSz;
  46883. }
  46884. #ifndef NO_RSA
  46885. #ifdef WOLFSSL_SP_MATH
  46886. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46887. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  46888. #else
  46889. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46890. sizeof(berContent), decoded, sizeof(decoded)), 0);
  46891. #endif
  46892. #else
  46893. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46894. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  46895. #endif
  46896. wc_PKCS7_Free(pkcs7);
  46897. #endif /* !NO_DES3 */
  46898. #endif
  46899. return EXPECT_RESULT();
  46900. } /* END test_wc_PKCS7_BER() */
  46901. static int test_wc_PKCS7_signed_enveloped(void)
  46902. {
  46903. EXPECT_DECLS;
  46904. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  46905. !defined(NO_FILESYSTEM)
  46906. XFILE f = XBADFILE;
  46907. PKCS7* pkcs7 = NULL;
  46908. #ifdef HAVE_AES_CBC
  46909. PKCS7* inner = NULL;
  46910. #endif
  46911. WC_RNG rng;
  46912. unsigned char key[FOURK_BUF/2];
  46913. unsigned char cert[FOURK_BUF/2];
  46914. unsigned char env[FOURK_BUF];
  46915. int envSz = FOURK_BUF;
  46916. int keySz = 0;
  46917. int certSz = 0;
  46918. unsigned char sig[FOURK_BUF * 2];
  46919. int sigSz = FOURK_BUF * 2;
  46920. #ifdef HAVE_AES_CBC
  46921. unsigned char decoded[FOURK_BUF];
  46922. int decodedSz = FOURK_BUF;
  46923. #endif
  46924. #ifndef NO_PKCS7_STREAM
  46925. int z;
  46926. int ret;
  46927. #endif /* !NO_PKCS7_STREAM */
  46928. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46929. /* load cert */
  46930. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  46931. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  46932. if (f != XBADFILE) {
  46933. XFCLOSE(f);
  46934. f = XBADFILE;
  46935. }
  46936. /* load key */
  46937. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  46938. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  46939. if (f != XBADFILE) {
  46940. XFCLOSE(f);
  46941. f = XBADFILE;
  46942. }
  46943. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  46944. /* sign cert for envelope */
  46945. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46946. ExpectIntEQ(wc_InitRng(&rng), 0);
  46947. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46948. if (pkcs7 != NULL) {
  46949. pkcs7->content = cert;
  46950. pkcs7->contentSz = (word32)certSz;
  46951. pkcs7->contentOID = DATA;
  46952. pkcs7->privateKey = key;
  46953. pkcs7->privateKeySz = (word32)keySz;
  46954. pkcs7->encryptOID = RSAk;
  46955. pkcs7->hashOID = SHA256h;
  46956. pkcs7->rng = &rng;
  46957. }
  46958. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46959. wc_PKCS7_Free(pkcs7);
  46960. pkcs7 = NULL;
  46961. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46962. #ifdef HAVE_AES_CBC
  46963. /* create envelope */
  46964. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46965. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46966. if (pkcs7 != NULL) {
  46967. pkcs7->content = sig;
  46968. pkcs7->contentSz = (word32)sigSz;
  46969. pkcs7->contentOID = DATA;
  46970. pkcs7->encryptOID = AES256CBCb;
  46971. pkcs7->privateKey = key;
  46972. pkcs7->privateKeySz = (word32)keySz;
  46973. }
  46974. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  46975. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  46976. wc_PKCS7_Free(pkcs7);
  46977. pkcs7 = NULL;
  46978. #endif
  46979. /* create bad signed enveloped data */
  46980. sigSz = FOURK_BUF * 2;
  46981. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46982. ExpectIntEQ(wc_InitRng(&rng), 0);
  46983. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46984. if (pkcs7 != NULL) {
  46985. pkcs7->content = env;
  46986. pkcs7->contentSz = (word32)envSz;
  46987. pkcs7->contentOID = DATA;
  46988. pkcs7->privateKey = key;
  46989. pkcs7->privateKeySz = (word32)keySz;
  46990. pkcs7->encryptOID = RSAk;
  46991. pkcs7->hashOID = SHA256h;
  46992. pkcs7->rng = &rng;
  46993. }
  46994. /* Set no certs in bundle for this test. */
  46995. if (pkcs7 != NULL) {
  46996. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  46997. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46998. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  46999. }
  47000. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47001. wc_PKCS7_Free(pkcs7);
  47002. pkcs7 = NULL;
  47003. /* check verify fails */
  47004. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47005. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47006. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  47007. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  47008. /* try verifying the signature manually */
  47009. {
  47010. RsaKey rKey;
  47011. word32 idx = 0;
  47012. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  47013. WC_MAX_DIGEST_SIZE];
  47014. int digestSz = 0;
  47015. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  47016. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  47017. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  47018. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  47019. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  47020. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  47021. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  47022. /* verify was success */
  47023. }
  47024. wc_PKCS7_Free(pkcs7);
  47025. pkcs7 = NULL;
  47026. /* initializing the PKCS7 struct with the signing certificate should pass */
  47027. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47028. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47029. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47030. #ifndef NO_PKCS7_STREAM
  47031. wc_PKCS7_Free(pkcs7);
  47032. pkcs7 = NULL;
  47033. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47034. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47035. /* test for streaming */
  47036. ret = -1;
  47037. for (z = 0; z < sigSz && ret != 0; z++) {
  47038. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47039. if (ret < 0){
  47040. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47041. }
  47042. }
  47043. ExpectIntEQ(ret, 0);
  47044. #endif /* !NO_PKCS7_STREAM */
  47045. wc_PKCS7_Free(pkcs7);
  47046. pkcs7 = NULL;
  47047. /* create valid degenerate bundle */
  47048. sigSz = FOURK_BUF * 2;
  47049. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47050. if (pkcs7 != NULL) {
  47051. pkcs7->content = env;
  47052. pkcs7->contentSz = (word32)envSz;
  47053. pkcs7->contentOID = DATA;
  47054. pkcs7->privateKey = key;
  47055. pkcs7->privateKeySz = (word32)keySz;
  47056. pkcs7->encryptOID = RSAk;
  47057. pkcs7->hashOID = SHA256h;
  47058. pkcs7->rng = &rng;
  47059. }
  47060. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47061. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47062. wc_PKCS7_Free(pkcs7);
  47063. pkcs7 = NULL;
  47064. wc_FreeRng(&rng);
  47065. /* check verify */
  47066. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47067. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47068. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47069. ExpectNotNull(pkcs7->content);
  47070. #ifndef NO_PKCS7_STREAM
  47071. wc_PKCS7_Free(pkcs7);
  47072. pkcs7 = NULL;
  47073. /* create valid degenerate bundle */
  47074. sigSz = FOURK_BUF * 2;
  47075. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47076. if (pkcs7 != NULL) {
  47077. pkcs7->content = env;
  47078. pkcs7->contentSz = (word32)envSz;
  47079. pkcs7->contentOID = DATA;
  47080. pkcs7->privateKey = key;
  47081. pkcs7->privateKeySz = (word32)keySz;
  47082. pkcs7->encryptOID = RSAk;
  47083. pkcs7->hashOID = SHA256h;
  47084. pkcs7->rng = &rng;
  47085. }
  47086. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47087. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47088. wc_PKCS7_Free(pkcs7);
  47089. pkcs7 = NULL;
  47090. wc_FreeRng(&rng);
  47091. /* check verify */
  47092. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47093. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47094. /* test for streaming */
  47095. ret = -1;
  47096. for (z = 0; z < sigSz && ret != 0; z++) {
  47097. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47098. if (ret < 0){
  47099. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47100. }
  47101. }
  47102. ExpectIntEQ(ret, 0);
  47103. #endif /* !NO_PKCS7_STREAM */
  47104. #ifdef HAVE_AES_CBC
  47105. /* check decode */
  47106. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  47107. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  47108. if (inner != NULL) {
  47109. inner->privateKey = key;
  47110. inner->privateKeySz = (word32)keySz;
  47111. }
  47112. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  47113. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  47114. wc_PKCS7_Free(inner);
  47115. inner = NULL;
  47116. #endif
  47117. wc_PKCS7_Free(pkcs7);
  47118. pkcs7 = NULL;
  47119. #ifdef HAVE_AES_CBC
  47120. /* check cert set */
  47121. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47122. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47123. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  47124. ExpectNotNull(pkcs7->singleCert);
  47125. ExpectIntNE(pkcs7->singleCertSz, 0);
  47126. wc_PKCS7_Free(pkcs7);
  47127. pkcs7 = NULL;
  47128. #ifndef NO_PKCS7_STREAM
  47129. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47130. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47131. /* test for streaming */
  47132. ret = -1;
  47133. for (z = 0; z < decodedSz && ret != 0; z++) {
  47134. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  47135. if (ret < 0){
  47136. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47137. }
  47138. }
  47139. ExpectIntEQ(ret, 0);
  47140. ExpectNotNull(pkcs7->singleCert);
  47141. ExpectIntNE(pkcs7->singleCertSz, 0);
  47142. wc_PKCS7_Free(pkcs7);
  47143. pkcs7 = NULL;
  47144. #endif /* !NO_PKCS7_STREAM */
  47145. #endif
  47146. {
  47147. /* arbitrary custom SKID */
  47148. const byte customSKID[] = {
  47149. 0x40, 0x25, 0x77, 0x56
  47150. };
  47151. ExpectIntEQ(wc_InitRng(&rng), 0);
  47152. sigSz = FOURK_BUF * 2;
  47153. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47154. if (pkcs7 != NULL) {
  47155. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47156. pkcs7->content = cert;
  47157. pkcs7->contentSz = (word32)certSz;
  47158. pkcs7->contentOID = DATA;
  47159. pkcs7->privateKey = key;
  47160. pkcs7->privateKeySz = (word32)keySz;
  47161. pkcs7->encryptOID = RSAk;
  47162. pkcs7->hashOID = SHA256h;
  47163. pkcs7->rng = &rng;
  47164. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  47165. ExpectIntEQ(wc_PKCS7_SetCustomSKID(pkcs7, customSKID,
  47166. sizeof(customSKID)), 0);
  47167. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig,
  47168. (word32)sigSz)), 0);
  47169. }
  47170. wc_PKCS7_Free(pkcs7);
  47171. pkcs7 = NULL;
  47172. wc_FreeRng(&rng);
  47173. }
  47174. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  47175. return EXPECT_RESULT();
  47176. }
  47177. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  47178. {
  47179. EXPECT_DECLS;
  47180. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47181. && !defined(NO_AES)
  47182. PKCS7* pkcs7 = NULL;
  47183. void* heap = NULL;
  47184. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47185. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47186. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47187. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  47188. wc_PKCS7_Free(pkcs7);
  47189. #endif
  47190. return EXPECT_RESULT();
  47191. }
  47192. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  47193. {
  47194. EXPECT_DECLS;
  47195. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47196. && !defined(NO_AES)
  47197. PKCS7* pkcs7 = NULL;
  47198. void* heap = NULL;
  47199. WOLFSSL_CTX* ctx = NULL;
  47200. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47201. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47202. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47203. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  47204. wc_PKCS7_Free(pkcs7);
  47205. #endif
  47206. return EXPECT_RESULT();
  47207. }
  47208. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  47209. {
  47210. EXPECT_DECLS;
  47211. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47212. && !defined(NO_AES)
  47213. PKCS7* pkcs7 = NULL;
  47214. void* heap = NULL;
  47215. WOLFSSL_CTX* ctx = NULL;
  47216. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47217. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47218. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47219. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  47220. wc_PKCS7_Free(pkcs7);
  47221. #endif
  47222. return EXPECT_RESULT();
  47223. }
  47224. static int test_wc_PKCS7_DecodeCompressedData(void)
  47225. {
  47226. EXPECT_DECLS;
  47227. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47228. && !defined(NO_AES) && defined(HAVE_LIBZ)
  47229. PKCS7* pkcs7 = NULL;
  47230. void* heap = NULL;
  47231. byte out[4096];
  47232. byte* decompressed = NULL;
  47233. int outSz;
  47234. int decompressedSz;
  47235. const char* cert = "./certs/client-cert.pem";
  47236. byte* cert_buf = NULL;
  47237. size_t cert_sz = 0;
  47238. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  47239. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  47240. DYNAMIC_TYPE_TMP_BUFFER)));
  47241. decompressedSz = (int)cert_sz;
  47242. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  47243. if (pkcs7 != NULL) {
  47244. pkcs7->content = (byte*)cert_buf;
  47245. pkcs7->contentSz = (word32)cert_sz;
  47246. pkcs7->contentOID = DATA;
  47247. }
  47248. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  47249. sizeof(out))), 0);
  47250. wc_PKCS7_Free(pkcs7);
  47251. pkcs7 = NULL;
  47252. /* compressed key should be smaller than when started */
  47253. ExpectIntLT(outSz, cert_sz);
  47254. /* test decompression */
  47255. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  47256. ExpectIntEQ(pkcs7->contentOID, 0);
  47257. /* fail case with out buffer too small */
  47258. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  47259. decompressed, outSz), 0);
  47260. /* success case */
  47261. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  47262. decompressed, decompressedSz), cert_sz);
  47263. ExpectIntEQ(pkcs7->contentOID, DATA);
  47264. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47265. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47266. decompressed = NULL;
  47267. /* test decompression function with different 'max' inputs */
  47268. outSz = sizeof(out);
  47269. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  47270. 0);
  47271. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  47272. out, outSz, 0, heap), 0);
  47273. ExpectNull(decompressed);
  47274. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  47275. out, outSz, 0, heap), 0);
  47276. ExpectNotNull(decompressed);
  47277. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47278. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47279. decompressed = NULL;
  47280. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  47281. out, outSz, 0, heap), 0);
  47282. ExpectNotNull(decompressed);
  47283. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47284. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47285. if (cert_buf != NULL)
  47286. free(cert_buf);
  47287. wc_PKCS7_Free(pkcs7);
  47288. #endif
  47289. return EXPECT_RESULT();
  47290. }
  47291. static int test_wc_i2d_PKCS12(void)
  47292. {
  47293. EXPECT_DECLS;
  47294. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  47295. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47296. && !defined(NO_AES) && !defined(NO_SHA)
  47297. WC_PKCS12* pkcs12 = NULL;
  47298. unsigned char der[FOURK_BUF * 2];
  47299. unsigned char* pt;
  47300. int derSz = 0;
  47301. unsigned char out[FOURK_BUF * 2];
  47302. int outSz = FOURK_BUF * 2;
  47303. const char p12_f[] = "./certs/test-servercert.p12";
  47304. XFILE f = XBADFILE;
  47305. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  47306. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  47307. if (f != XBADFILE)
  47308. XFCLOSE(f);
  47309. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47310. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  47311. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47312. ExpectIntEQ(outSz, derSz);
  47313. outSz = derSz - 1;
  47314. pt = out;
  47315. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  47316. outSz = derSz;
  47317. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  47318. ExpectIntEQ((pt == out), 0);
  47319. pt = NULL;
  47320. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  47321. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  47322. wc_PKCS12_free(pkcs12);
  47323. pkcs12 = NULL;
  47324. /* Run the same test but use wc_d2i_PKCS12_fp. */
  47325. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47326. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47327. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47328. ExpectIntEQ(outSz, derSz);
  47329. wc_PKCS12_free(pkcs12);
  47330. pkcs12 = NULL;
  47331. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  47332. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47333. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47334. ExpectIntEQ(outSz, derSz);
  47335. wc_PKCS12_free(pkcs12);
  47336. pkcs12 = NULL;
  47337. #endif
  47338. return EXPECT_RESULT();
  47339. }
  47340. /* Testing wc_SignatureGetSize() for signature type ECC */
  47341. static int test_wc_SignatureGetSize_ecc(void)
  47342. {
  47343. EXPECT_DECLS;
  47344. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  47345. enum wc_SignatureType sig_type;
  47346. word32 key_len;
  47347. ecc_key ecc;
  47348. const char* qx =
  47349. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  47350. const char* qy =
  47351. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  47352. const char* d =
  47353. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  47354. XMEMSET(&ecc, 0, sizeof(ecc_key));
  47355. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  47356. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  47357. /* Input for signature type ECC */
  47358. sig_type = WC_SIGNATURE_TYPE_ECC;
  47359. key_len = sizeof(ecc_key);
  47360. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  47361. /* Test bad args */
  47362. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47363. sig_type = (enum wc_SignatureType) 100;
  47364. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47365. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47366. sig_type = WC_SIGNATURE_TYPE_ECC;
  47367. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  47368. key_len = (word32)0;
  47369. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47370. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  47371. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  47372. return EXPECT_RESULT();
  47373. } /* END test_wc_SignatureGetSize_ecc() */
  47374. /* Testing wc_SignatureGetSize() for signature type rsa */
  47375. static int test_wc_SignatureGetSize_rsa(void)
  47376. {
  47377. EXPECT_DECLS;
  47378. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  47379. enum wc_SignatureType sig_type;
  47380. word32 key_len;
  47381. word32 idx = 0;
  47382. RsaKey rsa_key;
  47383. byte* tmp = NULL;
  47384. size_t bytes;
  47385. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  47386. #ifdef USE_CERT_BUFFERS_1024
  47387. bytes = (size_t)sizeof_client_key_der_1024;
  47388. if (bytes < (size_t)sizeof_client_key_der_1024)
  47389. bytes = (size_t)sizeof_client_cert_der_1024;
  47390. #elif defined(USE_CERT_BUFFERS_2048)
  47391. bytes = (size_t)sizeof_client_key_der_2048;
  47392. if (bytes < (size_t)sizeof_client_cert_der_2048)
  47393. bytes = (size_t)sizeof_client_cert_der_2048;
  47394. #else
  47395. bytes = FOURK_BUF;
  47396. #endif
  47397. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  47398. DYNAMIC_TYPE_TMP_BUFFER));
  47399. if (tmp != NULL) {
  47400. #ifdef USE_CERT_BUFFERS_1024
  47401. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  47402. #elif defined(USE_CERT_BUFFERS_2048)
  47403. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  47404. #elif !defined(NO_FILESYSTEM)
  47405. XFILE file = XBADFILE;
  47406. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  47407. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  47408. if (file != XBADFILE)
  47409. XFCLOSE(file);
  47410. }
  47411. #else
  47412. ExpectFail();
  47413. #endif
  47414. }
  47415. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  47416. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  47417. /* Input for signature type RSA */
  47418. sig_type = WC_SIGNATURE_TYPE_RSA;
  47419. key_len = sizeof(RsaKey);
  47420. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  47421. /* Test bad args */
  47422. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47423. sig_type = (enum wc_SignatureType)100;
  47424. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47425. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47426. sig_type = WC_SIGNATURE_TYPE_RSA;
  47427. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47428. key_len = (word32)0;
  47429. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47430. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  47431. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47432. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  47433. return EXPECT_RESULT();
  47434. } /* END test_wc_SignatureGetSize_rsa(void) */
  47435. /*----------------------------------------------------------------------------*
  47436. | hash.h Tests
  47437. *----------------------------------------------------------------------------*/
  47438. static int test_wc_HashInit(void)
  47439. {
  47440. EXPECT_DECLS;
  47441. int i; /* 0 indicates tests passed, 1 indicates failure */
  47442. wc_HashAlg hash;
  47443. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47444. enum wc_HashType enumArray[] = {
  47445. #ifndef NO_MD5
  47446. WC_HASH_TYPE_MD5,
  47447. #endif
  47448. #ifndef NO_SHA
  47449. WC_HASH_TYPE_SHA,
  47450. #endif
  47451. #ifdef WOLFSSL_SHA224
  47452. WC_HASH_TYPE_SHA224,
  47453. #endif
  47454. #ifndef NO_SHA256
  47455. WC_HASH_TYPE_SHA256,
  47456. #endif
  47457. #ifdef WOLFSSL_SHA384
  47458. WC_HASH_TYPE_SHA384,
  47459. #endif
  47460. #ifdef WOLFSSL_SHA512
  47461. WC_HASH_TYPE_SHA512,
  47462. #endif
  47463. };
  47464. /* dynamically finds the length */
  47465. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47466. /* For loop to test various arguments... */
  47467. for (i = 0; i < enumlen; i++) {
  47468. /* check for bad args */
  47469. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47470. wc_HashFree(&hash, enumArray[i]);
  47471. /* check for null ptr */
  47472. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47473. } /* end of for loop */
  47474. return EXPECT_RESULT();
  47475. } /* end of test_wc_HashInit */
  47476. /*
  47477. * Unit test function for wc_HashSetFlags()
  47478. */
  47479. static int test_wc_HashSetFlags(void)
  47480. {
  47481. EXPECT_DECLS;
  47482. #ifdef WOLFSSL_HASH_FLAGS
  47483. wc_HashAlg hash;
  47484. word32 flags = 0;
  47485. int i, j;
  47486. int notSupportedLen;
  47487. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47488. enum wc_HashType enumArray[] = {
  47489. #ifndef NO_MD5
  47490. WC_HASH_TYPE_MD5,
  47491. #endif
  47492. #ifndef NO_SHA
  47493. WC_HASH_TYPE_SHA,
  47494. #endif
  47495. #ifdef WOLFSSL_SHA224
  47496. WC_HASH_TYPE_SHA224,
  47497. #endif
  47498. #ifndef NO_SHA256
  47499. WC_HASH_TYPE_SHA256,
  47500. #endif
  47501. #ifdef WOLFSSL_SHA384
  47502. WC_HASH_TYPE_SHA384,
  47503. #endif
  47504. #ifdef WOLFSSL_SHA512
  47505. WC_HASH_TYPE_SHA512,
  47506. #endif
  47507. #ifdef WOLFSSL_SHA3
  47508. WC_HASH_TYPE_SHA3_224,
  47509. #endif
  47510. };
  47511. enum wc_HashType notSupported[] = {
  47512. WC_HASH_TYPE_MD5_SHA,
  47513. WC_HASH_TYPE_MD2,
  47514. WC_HASH_TYPE_MD4,
  47515. WC_HASH_TYPE_BLAKE2B,
  47516. WC_HASH_TYPE_BLAKE2S,
  47517. WC_HASH_TYPE_NONE,
  47518. };
  47519. /* dynamically finds the length */
  47520. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47521. /* For loop to test various arguments... */
  47522. for (i = 0; i < enumlen; i++) {
  47523. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47524. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  47525. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47526. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47527. wc_HashFree(&hash, enumArray[i]);
  47528. }
  47529. /* For loop to test not supported cases */
  47530. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47531. for (j = 0; j < notSupportedLen; j++) {
  47532. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47533. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  47534. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47535. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47536. }
  47537. #endif
  47538. return EXPECT_RESULT();
  47539. } /* END test_wc_HashSetFlags */
  47540. /*
  47541. * Unit test function for wc_HashGetFlags()
  47542. */
  47543. static int test_wc_HashGetFlags(void)
  47544. {
  47545. EXPECT_DECLS;
  47546. #ifdef WOLFSSL_HASH_FLAGS
  47547. wc_HashAlg hash;
  47548. word32 flags = 0;
  47549. int i, j;
  47550. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47551. enum wc_HashType enumArray[] = {
  47552. #ifndef NO_MD5
  47553. WC_HASH_TYPE_MD5,
  47554. #endif
  47555. #ifndef NO_SHA
  47556. WC_HASH_TYPE_SHA,
  47557. #endif
  47558. #ifdef WOLFSSL_SHA224
  47559. WC_HASH_TYPE_SHA224,
  47560. #endif
  47561. #ifndef NO_SHA256
  47562. WC_HASH_TYPE_SHA256,
  47563. #endif
  47564. #ifdef WOLFSSL_SHA384
  47565. WC_HASH_TYPE_SHA384,
  47566. #endif
  47567. #ifdef WOLFSSL_SHA512
  47568. WC_HASH_TYPE_SHA512,
  47569. #endif
  47570. #ifdef WOLFSSL_SHA3
  47571. WC_HASH_TYPE_SHA3_224,
  47572. #endif
  47573. };
  47574. enum wc_HashType notSupported[] = {
  47575. WC_HASH_TYPE_MD5_SHA,
  47576. WC_HASH_TYPE_MD2,
  47577. WC_HASH_TYPE_MD4,
  47578. WC_HASH_TYPE_BLAKE2B,
  47579. WC_HASH_TYPE_BLAKE2S,
  47580. WC_HASH_TYPE_NONE,
  47581. };
  47582. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47583. int notSupportedLen;
  47584. /* For loop to test various arguments... */
  47585. for (i = 0; i < enumlen; i++) {
  47586. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47587. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  47588. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47589. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47590. wc_HashFree(&hash, enumArray[i]);
  47591. }
  47592. /* For loop to test not supported cases */
  47593. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47594. for (j = 0; j < notSupportedLen; j++) {
  47595. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47596. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  47597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47598. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47599. }
  47600. #endif
  47601. return EXPECT_RESULT();
  47602. } /* END test_wc_HashGetFlags */
  47603. /*----------------------------------------------------------------------------*
  47604. | Compatibility Tests
  47605. *----------------------------------------------------------------------------*/
  47606. /*----------------------------------------------------------------------------*
  47607. | ASN.1 Tests
  47608. *----------------------------------------------------------------------------*/
  47609. static int test_wolfSSL_ASN1_BIT_STRING(void)
  47610. {
  47611. EXPECT_DECLS;
  47612. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  47613. ASN1_BIT_STRING* str = NULL;
  47614. ASN1_BIT_STRING* str2 = NULL;
  47615. unsigned char* der = NULL;
  47616. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47617. /* Empty data testing. */
  47618. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  47619. ASN1_BIT_STRING_free(str);
  47620. str = NULL;
  47621. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47622. /* Invalid parameter testing. */
  47623. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  47624. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  47625. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  47626. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  47627. /* No bit string - bit is always 0. */
  47628. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  47629. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  47630. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47631. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  47632. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  47633. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  47634. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  47635. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47636. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  47637. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  47638. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  47639. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  47640. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  47641. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  47642. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  47643. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  47644. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  47645. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  47646. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  47647. #ifdef WOLFSSL_ASN_TEMPLATE
  47648. {
  47649. const unsigned char* tmp = der;
  47650. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  47651. }
  47652. #endif
  47653. ASN1_BIT_STRING_free(str);
  47654. ASN1_BIT_STRING_free(str2);
  47655. ASN1_BIT_STRING_free(NULL);
  47656. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  47657. #endif
  47658. return EXPECT_RESULT();
  47659. }
  47660. static int test_wolfSSL_ASN1_INTEGER(void)
  47661. {
  47662. EXPECT_DECLS;
  47663. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47664. ASN1_INTEGER* a = NULL;
  47665. ASN1_INTEGER* dup = NULL;
  47666. const unsigned char invalidLenDer[] = {
  47667. 0x02, 0x20, 0x00
  47668. };
  47669. const unsigned char longDer[] = {
  47670. 0x02, 0x20,
  47671. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47672. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47673. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47674. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  47675. };
  47676. const unsigned char* p;
  47677. /* Invalid parameter testing. */
  47678. ASN1_INTEGER_free(NULL);
  47679. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  47680. ExpectNotNull(a = ASN1_INTEGER_new());
  47681. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47682. ASN1_INTEGER_free(dup);
  47683. dup = NULL;
  47684. ASN1_INTEGER_free(a);
  47685. a = NULL;
  47686. p = longDer;
  47687. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  47688. p = longDer;
  47689. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  47690. ExpectPtrNE(p, longDer);
  47691. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47692. ASN1_INTEGER_free(dup);
  47693. ASN1_INTEGER_free(a);
  47694. #endif
  47695. return EXPECT_RESULT();
  47696. }
  47697. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  47698. {
  47699. EXPECT_DECLS;
  47700. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47701. ASN1_INTEGER* a = NULL;
  47702. ASN1_INTEGER* b = NULL;
  47703. ExpectNotNull(a = ASN1_INTEGER_new());
  47704. ExpectNotNull(b = ASN1_INTEGER_new());
  47705. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  47706. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47707. /* Invalid parameter testing. */
  47708. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  47709. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  47710. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  47711. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47712. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  47713. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47714. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  47715. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47716. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47717. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47718. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  47719. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  47720. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47721. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  47722. ASN1_INTEGER_free(b);
  47723. ASN1_INTEGER_free(a);
  47724. #endif
  47725. return EXPECT_RESULT();
  47726. }
  47727. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  47728. {
  47729. EXPECT_DECLS;
  47730. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47731. ASN1_INTEGER* ai = NULL;
  47732. ASN1_INTEGER* ai2 = NULL;
  47733. BIGNUM* bn = NULL;
  47734. BIGNUM* bn2 = NULL;
  47735. ExpectNotNull(ai = ASN1_INTEGER_new());
  47736. ExpectNotNull(bn2 = BN_new());
  47737. /* Invalid parameter testing. */
  47738. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  47739. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  47740. /* at the moment hard setting since no set function */
  47741. if (ai != NULL) {
  47742. ai->data[0] = 0xff; /* No DER encoding. */
  47743. ai->length = 1;
  47744. }
  47745. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47746. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47747. BN_free(bn);
  47748. bn = NULL;
  47749. #else
  47750. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47751. #endif
  47752. if (ai != NULL) {
  47753. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47754. ai->data[1] = 0x04; /* bad length of integer */
  47755. ai->data[2] = 0x03;
  47756. ai->length = 3;
  47757. }
  47758. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47759. /* Interpreted as a number 0x020403. */
  47760. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47761. BN_free(bn);
  47762. bn = NULL;
  47763. #else
  47764. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47765. #endif
  47766. if (ai != NULL) {
  47767. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47768. ai->data[1] = 0x01; /* length of integer */
  47769. ai->data[2] = 0x03;
  47770. ai->length = 3;
  47771. }
  47772. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47773. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  47774. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47775. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47776. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47777. if (ai != NULL) {
  47778. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47779. ai->data[1] = 0x02; /* length of integer */
  47780. ai->data[2] = 0x00; /* padding byte to ensure positive */
  47781. ai->data[3] = 0xff;
  47782. ai->length = 4;
  47783. }
  47784. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47785. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47786. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47787. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47788. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47789. if (ai != NULL) {
  47790. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47791. ai->data[1] = 0x01; /* length of integer */
  47792. ai->data[2] = 0x00;
  47793. ai->length = 3;
  47794. }
  47795. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47796. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47797. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47798. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47799. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47800. if (ai != NULL) {
  47801. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47802. ai->data[1] = 0x01; /* length of integer */
  47803. ai->data[2] = 0x01;
  47804. ai->length = 3;
  47805. ai->negative = 1;
  47806. }
  47807. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47808. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47809. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47810. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47811. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47812. BN_free(bn2);
  47813. BN_free(bn);
  47814. ASN1_INTEGER_free(ai2);
  47815. ASN1_INTEGER_free(ai);
  47816. #endif
  47817. return EXPECT_RESULT();
  47818. }
  47819. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  47820. {
  47821. EXPECT_DECLS;
  47822. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47823. ASN1_INTEGER *a = NULL;
  47824. long val;
  47825. ExpectNotNull(a = ASN1_INTEGER_new());
  47826. /* Invalid parameter testing. */
  47827. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  47828. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47829. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  47830. #else
  47831. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  47832. #endif
  47833. ASN1_INTEGER_free(a);
  47834. a = NULL;
  47835. ExpectNotNull(a = ASN1_INTEGER_new());
  47836. val = 0;
  47837. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  47838. ASN1_INTEGER_free(a);
  47839. a = NULL;
  47840. /* 0 */
  47841. ExpectNotNull(a = ASN1_INTEGER_new());
  47842. val = 0;
  47843. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47844. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47845. ASN1_INTEGER_free(a);
  47846. a = NULL;
  47847. /* 40 */
  47848. ExpectNotNull(a = ASN1_INTEGER_new());
  47849. val = 40;
  47850. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47851. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47852. ASN1_INTEGER_free(a);
  47853. a = NULL;
  47854. /* -40 */
  47855. ExpectNotNull(a = ASN1_INTEGER_new());
  47856. val = -40;
  47857. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47858. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47859. ASN1_INTEGER_free(a);
  47860. a = NULL;
  47861. /* 128 */
  47862. ExpectNotNull(a = ASN1_INTEGER_new());
  47863. val = 128;
  47864. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47865. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47866. ASN1_INTEGER_free(a);
  47867. a = NULL;
  47868. /* -128 */
  47869. ExpectNotNull(a = ASN1_INTEGER_new());
  47870. val = -128;
  47871. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47872. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47873. ASN1_INTEGER_free(a);
  47874. a = NULL;
  47875. /* 200 */
  47876. ExpectNotNull(a = ASN1_INTEGER_new());
  47877. val = 200;
  47878. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47879. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47880. ASN1_INTEGER_free(a);
  47881. a = NULL;
  47882. /* int max (2147483647) */
  47883. ExpectNotNull(a = ASN1_INTEGER_new());
  47884. val = 2147483647;
  47885. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47886. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47887. ASN1_INTEGER_free(a);
  47888. a = NULL;
  47889. /* int min (-2147483648) */
  47890. ExpectNotNull(a = ASN1_INTEGER_new());
  47891. val = -2147483647 - 1;
  47892. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47893. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47894. ASN1_INTEGER_free(a);
  47895. a = NULL;
  47896. /* long max positive */
  47897. ExpectNotNull(a = ASN1_INTEGER_new());
  47898. val = (long)(((unsigned long)-1) >> 1);
  47899. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47900. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47901. ASN1_INTEGER_free(a);
  47902. #endif
  47903. return EXPECT_RESULT();
  47904. }
  47905. #if defined(OPENSSL_EXTRA)
  47906. typedef struct ASN1IntTestVector {
  47907. const byte* der;
  47908. const size_t derSz;
  47909. const long value;
  47910. } ASN1IntTestVector;
  47911. #endif
  47912. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  47913. {
  47914. EXPECT_DECLS;
  47915. #if defined(OPENSSL_EXTRA)
  47916. size_t i;
  47917. WOLFSSL_ASN1_INTEGER* a = NULL;
  47918. WOLFSSL_ASN1_INTEGER* b = NULL;
  47919. WOLFSSL_ASN1_INTEGER* c = NULL;
  47920. const byte* p = NULL;
  47921. byte* p2 = NULL;
  47922. byte* reEncoded = NULL;
  47923. int reEncodedSz = 0;
  47924. static const byte zeroDer[] = {
  47925. 0x02, 0x01, 0x00
  47926. };
  47927. static const byte oneDer[] = {
  47928. 0x02, 0x01, 0x01
  47929. };
  47930. static const byte negativeDer[] = {
  47931. 0x02, 0x03, 0xC1, 0x16, 0x0D
  47932. };
  47933. static const byte positiveDer[] = {
  47934. 0x02, 0x03, 0x01, 0x00, 0x01
  47935. };
  47936. static const byte primeDer[] = {
  47937. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  47938. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  47939. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  47940. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  47941. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  47942. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  47943. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  47944. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  47945. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  47946. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  47947. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  47948. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  47949. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  47950. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  47951. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  47952. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  47953. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  47954. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  47955. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  47956. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  47957. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  47958. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  47959. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  47960. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  47961. };
  47962. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  47963. static const ASN1IntTestVector testVectors[] = {
  47964. {zeroDer, sizeof(zeroDer), 0},
  47965. {oneDer, sizeof(oneDer), 1},
  47966. {negativeDer, sizeof(negativeDer), -4123123},
  47967. {positiveDer, sizeof(positiveDer), 65537},
  47968. {primeDer, sizeof(primeDer), 0}
  47969. };
  47970. static const size_t NUM_TEST_VECTORS =
  47971. sizeof(testVectors)/sizeof(testVectors[0]);
  47972. /* Check d2i error conditions */
  47973. /* NULL pointer to input. */
  47974. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  47975. ExpectNull(b);
  47976. /* NULL input. */
  47977. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  47978. ExpectNull(b);
  47979. /* 0 length. */
  47980. p = testVectors[0].der;
  47981. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  47982. ExpectNull(b);
  47983. /* Negative length. */
  47984. p = testVectors[0].der;
  47985. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  47986. ExpectNull(b);
  47987. /* Garbage DER input. */
  47988. p = garbageDer;
  47989. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  47990. ExpectNull(b);
  47991. /* Check i2d error conditions */
  47992. /* NULL input. */
  47993. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  47994. /* 0 length input data buffer (a->length == 0). */
  47995. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  47996. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47997. if (a != NULL)
  47998. a->data = NULL;
  47999. /* NULL input data buffer. */
  48000. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  48001. if (a != NULL) {
  48002. /* Reset a->data. */
  48003. a->data = a->intData;
  48004. }
  48005. /* Set a to valid value. */
  48006. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  48007. /* NULL output buffer. */
  48008. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  48009. wolfSSL_ASN1_INTEGER_free(a);
  48010. a = NULL;
  48011. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  48012. p = testVectors[i].der;
  48013. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  48014. testVectors[i].derSz));
  48015. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48016. if (testVectors[i].derSz <= sizeof(long)) {
  48017. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  48018. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  48019. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  48020. wolfSSL_ASN1_INTEGER_free(c);
  48021. c = NULL;
  48022. }
  48023. /* Convert to DER without a pre-allocated output buffer. */
  48024. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  48025. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48026. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48027. /* Convert to DER with a pre-allocated output buffer. In this case, the
  48028. * output buffer pointer should be incremented just past the end of the
  48029. * encoded data. */
  48030. p2 = reEncoded;
  48031. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  48032. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48033. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  48034. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48035. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  48036. reEncoded = NULL;
  48037. wolfSSL_ASN1_INTEGER_free(a);
  48038. a = NULL;
  48039. }
  48040. #endif /* OPENSSL_EXTRA */
  48041. return EXPECT_RESULT();
  48042. }
  48043. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  48044. {
  48045. EXPECT_DECLS;
  48046. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  48047. BIO* bio = NULL;
  48048. BIO* out = NULL;
  48049. BIO* fixed = NULL;
  48050. ASN1_INTEGER* ai = NULL;
  48051. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  48052. char tmp[1024];
  48053. int tmpSz;
  48054. const char expected1[] = "123456";
  48055. const char expected2[] = "112345678912345678901234567890";
  48056. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  48057. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  48058. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  48059. ExpectNotNull(ai = ASN1_INTEGER_new());
  48060. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  48061. /* Invalid parameter testing. */
  48062. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  48063. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  48064. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  48065. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  48066. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  48067. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  48068. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  48069. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  48070. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  48071. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  48072. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  48073. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  48074. /* No data to read from BIO. */
  48075. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  48076. /* read first line */
  48077. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48078. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  48079. XMEMSET(tmp, 0, 1024);
  48080. tmpSz = BIO_read(out, tmp, 1024);
  48081. ExpectIntEQ(tmpSz, 6);
  48082. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  48083. /* fail on second line (not % 2) */
  48084. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48085. /* read 3rd long line */
  48086. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48087. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  48088. XMEMSET(tmp, 0, 1024);
  48089. tmpSz = BIO_read(out, tmp, 1024);
  48090. ExpectIntEQ(tmpSz, 30);
  48091. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  48092. /* fail on empty line */
  48093. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48094. BIO_free(bio);
  48095. bio = NULL;
  48096. /* Make long integer, requiring dynamic memory, even longer. */
  48097. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  48098. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48099. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  48100. XMEMSET(tmp, 0, 1024);
  48101. tmpSz = BIO_read(out, tmp, 1024);
  48102. ExpectIntEQ(tmpSz, 48);
  48103. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48104. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  48105. XMEMSET(tmp, 0, 1024);
  48106. tmpSz = BIO_read(out, tmp, 1024);
  48107. ExpectIntEQ(tmpSz, 56);
  48108. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  48109. BIO_free(bio);
  48110. BIO_free(out);
  48111. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48112. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48113. /* Ensure there is 0 bytes available to write into. */
  48114. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  48115. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48116. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48117. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48118. BIO_free(fixed);
  48119. ASN1_INTEGER_free(ai);
  48120. #endif
  48121. return EXPECT_RESULT();
  48122. }
  48123. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  48124. {
  48125. EXPECT_DECLS;
  48126. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48127. ASN1_INTEGER *a = NULL;
  48128. unsigned char *pp = NULL,*tpp = NULL;
  48129. int ret = 0;
  48130. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  48131. /* Invalid parameter testing. */
  48132. /* Set pp to an invalid value. */
  48133. pp = NULL;
  48134. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  48135. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  48136. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  48137. /* 40 */
  48138. if (a != NULL) {
  48139. a->intData[0] = ASN_INTEGER;
  48140. a->intData[1] = 1;
  48141. a->intData[2] = 40;
  48142. }
  48143. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48144. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48145. DYNAMIC_TYPE_TMP_BUFFER));
  48146. tpp = pp;
  48147. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48148. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48149. tpp--;
  48150. ExpectIntEQ(*tpp, 40);
  48151. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48152. pp = NULL;
  48153. /* 128 */
  48154. if (a != NULL) {
  48155. a->intData[0] = ASN_INTEGER;
  48156. a->intData[1] = 1;
  48157. a->intData[2] = 128;
  48158. }
  48159. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48160. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48161. DYNAMIC_TYPE_TMP_BUFFER));
  48162. tpp = pp;
  48163. if (tpp != NULL) {
  48164. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48165. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48166. tpp--;
  48167. ExpectIntEQ(*(tpp--), 128);
  48168. ExpectIntEQ(*tpp, 0);
  48169. }
  48170. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48171. pp = NULL;
  48172. /* -40 */
  48173. if (a != NULL) {
  48174. a->intData[0] = ASN_INTEGER;
  48175. a->intData[1] = 1;
  48176. a->intData[2] = 40;
  48177. a->negative = 1;
  48178. }
  48179. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48180. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48181. DYNAMIC_TYPE_TMP_BUFFER));
  48182. tpp = pp;
  48183. if (tpp != NULL) {
  48184. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48185. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48186. tpp--;
  48187. ExpectIntEQ(*tpp, 216);
  48188. }
  48189. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48190. pp = NULL;
  48191. /* -128 */
  48192. if (a != NULL) {
  48193. a->intData[0] = ASN_INTEGER;
  48194. a->intData[1] = 1;
  48195. a->intData[2] = 128;
  48196. a->negative = 1;
  48197. }
  48198. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48199. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48200. DYNAMIC_TYPE_TMP_BUFFER));
  48201. tpp = pp;
  48202. if (tpp != NULL) {
  48203. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48204. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48205. tpp--;
  48206. ExpectIntEQ(*tpp, 128);
  48207. }
  48208. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48209. pp = NULL;
  48210. /* -200 */
  48211. if (a != NULL) {
  48212. a->intData[0] = ASN_INTEGER;
  48213. a->intData[1] = 1;
  48214. a->intData[2] = 200;
  48215. a->negative = 1;
  48216. }
  48217. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48218. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48219. DYNAMIC_TYPE_TMP_BUFFER));
  48220. tpp = pp;
  48221. if (tpp != NULL) {
  48222. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48223. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48224. tpp--;
  48225. ExpectIntEQ(*(tpp--), 56);
  48226. ExpectIntEQ(*tpp, 255);
  48227. }
  48228. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48229. pp = NULL;
  48230. /* Empty */
  48231. if (a != NULL) {
  48232. a->intData[0] = ASN_INTEGER;
  48233. a->intData[1] = 0;
  48234. a->negative = 0;
  48235. }
  48236. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48237. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48238. DYNAMIC_TYPE_TMP_BUFFER));
  48239. tpp = pp;
  48240. if (tpp != NULL) {
  48241. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48242. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48243. tpp--;
  48244. ExpectIntEQ(*tpp, 0);
  48245. }
  48246. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48247. pp = NULL;
  48248. /* 0 */
  48249. if (a != NULL) {
  48250. a->intData[0] = ASN_INTEGER;
  48251. a->intData[1] = 1;
  48252. a->intData[2] = 0;
  48253. a->negative = 1;
  48254. }
  48255. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48256. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48257. DYNAMIC_TYPE_TMP_BUFFER));
  48258. if (tpp != NULL) {
  48259. tpp = pp;
  48260. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48261. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48262. tpp--;
  48263. ExpectIntEQ(*tpp, 0);
  48264. }
  48265. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48266. pp = NULL;
  48267. /* 0x100 */
  48268. if (a != NULL) {
  48269. a->intData[0] = ASN_INTEGER;
  48270. a->intData[1] = 2;
  48271. a->intData[2] = 0x01;
  48272. a->intData[3] = 0x00;
  48273. a->negative = 0;
  48274. }
  48275. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48276. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48277. DYNAMIC_TYPE_TMP_BUFFER));
  48278. if (tpp != NULL) {
  48279. tpp = pp;
  48280. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48281. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48282. tpp -= 2;
  48283. ExpectIntEQ(tpp[0], 0x01);
  48284. ExpectIntEQ(tpp[1], 0x00);
  48285. }
  48286. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48287. pp = NULL;
  48288. /* -0x8000 => 0x8000 */
  48289. if (a != NULL) {
  48290. a->intData[0] = ASN_INTEGER;
  48291. a->intData[1] = 2;
  48292. a->intData[2] = 0x80;
  48293. a->intData[3] = 0x00;
  48294. a->negative = 1;
  48295. }
  48296. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48297. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48298. DYNAMIC_TYPE_TMP_BUFFER));
  48299. tpp = pp;
  48300. if (tpp != NULL) {
  48301. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48302. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48303. tpp -= 2;
  48304. ExpectIntEQ(tpp[0], 0x80);
  48305. ExpectIntEQ(tpp[1], 0x00);
  48306. }
  48307. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48308. pp = NULL;
  48309. /* -0x8001 => 0xFF7FFF */
  48310. if (a != NULL) {
  48311. a->intData[0] = ASN_INTEGER;
  48312. a->intData[1] = 2;
  48313. a->intData[2] = 0x80;
  48314. a->intData[3] = 0x01;
  48315. a->negative = 1;
  48316. }
  48317. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  48318. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48319. DYNAMIC_TYPE_TMP_BUFFER));
  48320. tpp = pp;
  48321. if (tpp != NULL) {
  48322. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48323. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  48324. tpp -= 3;
  48325. ExpectIntEQ(tpp[0], 0xFF);
  48326. ExpectIntEQ(tpp[1], 0x7F);
  48327. ExpectIntEQ(tpp[2], 0xFF);
  48328. }
  48329. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48330. wolfSSL_ASN1_INTEGER_free(a);
  48331. #endif /* OPENSSL_EXTRA && !NO_ASN */
  48332. return EXPECT_RESULT();
  48333. }
  48334. static int test_wolfSSL_ASN1_OBJECT(void)
  48335. {
  48336. EXPECT_DECLS;
  48337. #if defined(OPENSSL_EXTRA)
  48338. ASN1_OBJECT* a = NULL;
  48339. ASN1_OBJECT s;
  48340. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  48341. /* Invalid parameter testing. */
  48342. ASN1_OBJECT_free(NULL);
  48343. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  48344. /* Test that a static ASN1_OBJECT can be freed. */
  48345. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48346. ASN1_OBJECT_free(&s);
  48347. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48348. ASN1_OBJECT_free(a);
  48349. a = NULL;
  48350. s.obj = der;
  48351. s.objSz = sizeof(der);
  48352. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48353. ASN1_OBJECT_free(a);
  48354. ASN1_OBJECT_free(&s);
  48355. #endif /* OPENSSL_EXTRA */
  48356. return EXPECT_RESULT();
  48357. }
  48358. static int test_wolfSSL_ASN1_get_object(void)
  48359. {
  48360. EXPECT_DECLS;
  48361. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  48362. const unsigned char* derBuf = cliecc_cert_der_256;
  48363. const unsigned char* nullPtr = NULL;
  48364. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  48365. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  48366. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  48367. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  48368. const unsigned char* p;
  48369. unsigned char objDer[10];
  48370. unsigned char* der;
  48371. unsigned char* derPtr;
  48372. int len = sizeof_cliecc_cert_der_256;
  48373. long asnLen = 0;
  48374. int tag = 0;
  48375. int cls = 0;
  48376. ASN1_OBJECT* a = NULL;
  48377. ASN1_OBJECT s;
  48378. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48379. /* Invalid encoding at length. */
  48380. p = objDerInvalidLen;
  48381. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48382. 0x80);
  48383. p = objDerBadLen;
  48384. /* Error = 0x80, Constructed = 0x20 */
  48385. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48386. 0x80 | 0x20);
  48387. /* Read a couple TLV triplets and make sure they match the expected values
  48388. */
  48389. /* SEQUENCE */
  48390. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  48391. ExpectIntEQ(asnLen, 861);
  48392. ExpectIntEQ(tag, 0x10);
  48393. ExpectIntEQ(cls, 0);
  48394. /* SEQUENCE */
  48395. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48396. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48397. ExpectIntEQ(asnLen, 772);
  48398. ExpectIntEQ(tag, 0x10);
  48399. ExpectIntEQ(cls, 0);
  48400. /* [0] */
  48401. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48402. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48403. ExpectIntEQ(asnLen, 3);
  48404. ExpectIntEQ(tag, 0);
  48405. ExpectIntEQ(cls, 0x80);
  48406. /* INTEGER */
  48407. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48408. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48409. ExpectIntEQ(asnLen, 1);
  48410. ExpectIntEQ(tag, 0x2);
  48411. ExpectIntEQ(cls, 0);
  48412. derBuf += asnLen;
  48413. /* INTEGER */
  48414. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48415. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48416. ExpectIntEQ(asnLen, 20);
  48417. ExpectIntEQ(tag, 0x2);
  48418. ExpectIntEQ(cls, 0);
  48419. derBuf += asnLen;
  48420. /* SEQUENCE */
  48421. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48422. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48423. ExpectIntEQ(asnLen, 10);
  48424. ExpectIntEQ(tag, 0x10);
  48425. ExpectIntEQ(cls, 0);
  48426. /* Found OBJECT_ID. */
  48427. /* Invalid parameter testing. */
  48428. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  48429. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  48430. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  48431. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  48432. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  48433. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  48434. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  48435. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  48436. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  48437. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  48438. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48439. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48440. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  48441. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  48442. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  48443. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  48444. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  48445. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48446. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48447. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  48448. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  48449. /* Invalid encoding at length. */
  48450. p = objDerInvalidLen;
  48451. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  48452. p = objDerBadLen;
  48453. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  48454. p = objDerNotObj;
  48455. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  48456. p = objDerNoData;
  48457. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  48458. /* Create an ASN OBJECT from content */
  48459. p = derBuf + 2;
  48460. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  48461. ASN1_OBJECT_free(a);
  48462. a = NULL;
  48463. /* Create an ASN OBJECT from DER */
  48464. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  48465. /* Invalid parameter testing. */
  48466. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  48467. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  48468. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  48469. der = NULL;
  48470. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  48471. derPtr = objDer;
  48472. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  48473. ExpectPtrNE(derPtr, objDer);
  48474. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  48475. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  48476. ASN1_OBJECT_free(a);
  48477. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  48478. return EXPECT_RESULT();
  48479. }
  48480. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  48481. {
  48482. EXPECT_DECLS;
  48483. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48484. ASN1_OBJECT* obj = NULL;
  48485. ASN1_OBJECT* a = NULL;
  48486. BIO *bio = NULL;
  48487. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  48488. const unsigned char* p;
  48489. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  48490. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  48491. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  48492. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  48493. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  48494. /* No DER encoding in ASN1_OBJECT. */
  48495. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  48496. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  48497. ASN1_OBJECT_free(a);
  48498. a = NULL;
  48499. /* DER encoding */
  48500. p = notObjDer;
  48501. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  48502. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  48503. ASN1_OBJECT_free(a);
  48504. BIO_free(bio);
  48505. ASN1_OBJECT_free(obj);
  48506. #endif
  48507. return EXPECT_RESULT();
  48508. }
  48509. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  48510. {
  48511. EXPECT_DECLS;
  48512. #if defined(OPENSSL_EXTRA) && \
  48513. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  48514. char buf[50] = {0};
  48515. ASN1_OBJECT* obj;
  48516. const char* oid = "2.5.29.19";
  48517. const char* ln = "X509v3 Basic Constraints";
  48518. obj = NULL;
  48519. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  48520. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  48521. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  48522. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  48523. XMEMSET(buf, 0, sizeof(buf));
  48524. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  48525. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  48526. ASN1_OBJECT_free(obj);
  48527. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  48528. return EXPECT_RESULT();
  48529. }
  48530. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  48531. {
  48532. EXPECT_DECLS;
  48533. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  48534. WOLFSSL_STACK* sk = NULL;
  48535. WOLFSSL_ASN1_OBJECT* obj;
  48536. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48537. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48538. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48539. sk = NULL;
  48540. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48541. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  48542. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  48543. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  48544. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48545. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  48546. sk = NULL;
  48547. /* obj freed in pop_free call. */
  48548. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48549. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48550. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48551. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  48552. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48553. wolfSSL_ASN1_OBJECT_free(obj);
  48554. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  48555. return EXPECT_RESULT();
  48556. }
  48557. static int test_wolfSSL_ASN1_STRING(void)
  48558. {
  48559. EXPECT_DECLS;
  48560. #if defined(OPENSSL_EXTRA)
  48561. ASN1_STRING* str = NULL;
  48562. ASN1_STRING* c = NULL;
  48563. const char data[] = "hello wolfSSL";
  48564. const char data2[] = "Same len data";
  48565. const char longData[] =
  48566. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48567. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48568. ASN1_STRING_free(str);
  48569. str = NULL;
  48570. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48571. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  48572. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  48573. /* Check setting to NULL works. */
  48574. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  48575. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  48576. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48577. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  48578. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  48579. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  48580. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  48581. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  48582. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  48583. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  48584. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  48585. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  48586. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  48587. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48588. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  48589. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  48590. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  48591. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  48592. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48593. /* Check setting back to smaller size frees dynamic data. */
  48594. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48595. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  48596. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  48597. ExpectNull(ASN1_STRING_get0_data(NULL));
  48598. ExpectNotNull(ASN1_STRING_get0_data(str));
  48599. ExpectNull(ASN1_STRING_data(NULL));
  48600. ExpectNotNull(ASN1_STRING_data(str));
  48601. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  48602. ExpectIntGT(ASN1_STRING_length(str), 0);
  48603. ASN1_STRING_free(c);
  48604. ASN1_STRING_free(str);
  48605. ASN1_STRING_free(NULL);
  48606. #ifndef NO_WOLFSSL_STUB
  48607. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  48608. #endif
  48609. #endif
  48610. return EXPECT_RESULT();
  48611. }
  48612. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  48613. {
  48614. EXPECT_DECLS;
  48615. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  48616. !defined(NO_FILESYSTEM)
  48617. WOLFSSL_X509* x509 = NULL;
  48618. WOLFSSL_X509_NAME* subject = NULL;
  48619. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  48620. WOLFSSL_ASN1_STRING* a = NULL;
  48621. FILE* file = XBADFILE;
  48622. int idx = 0;
  48623. char targetOutput[16] = "www.wolfssl.com";
  48624. unsigned char* actual_output = NULL;
  48625. int len = 0;
  48626. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  48627. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  48628. if (file != XBADFILE)
  48629. fclose(file);
  48630. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  48631. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  48632. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  48633. NID_commonName, -1)), 5);
  48634. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  48635. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  48636. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  48637. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  48638. a = NULL;
  48639. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  48640. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  48641. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  48642. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  48643. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  48644. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  48645. wolfSSL_X509_free(x509);
  48646. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48647. ExpectNotNull(a = ASN1_STRING_new());
  48648. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  48649. ASN1_STRING_free(a);
  48650. #endif
  48651. return EXPECT_RESULT();
  48652. }
  48653. static int test_wolfSSL_i2s_ASN1_STRING(void)
  48654. {
  48655. EXPECT_DECLS;
  48656. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48657. WOLFSSL_ASN1_STRING* str = NULL;
  48658. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  48659. char* ret = NULL;
  48660. ExpectNotNull(str = ASN1_STRING_new());
  48661. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  48662. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48663. ret = NULL;
  48664. /* No data. */
  48665. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48666. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48667. ret = NULL;
  48668. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  48669. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48670. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48671. ret = NULL;
  48672. ExpectIntEQ(ASN1_STRING_set(str, data, -1), 1);
  48673. /* No type. */
  48674. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48675. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48676. ASN1_STRING_free(str);
  48677. #endif
  48678. return EXPECT_RESULT();
  48679. }
  48680. static int test_wolfSSL_ASN1_STRING_canon(void)
  48681. {
  48682. EXPECT_DECLS;
  48683. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  48684. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  48685. defined(OPENSSL_EXTRA_X509_SMALL))
  48686. WOLFSSL_ASN1_STRING* orig = NULL;
  48687. WOLFSSL_ASN1_STRING* canon = NULL;
  48688. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  48689. const char* whitespaceOnly = "\t\r\n";
  48690. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  48691. const char* canonData = "\x01 \x02 \xff tt";
  48692. const char longData[] =
  48693. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48694. ExpectNotNull(orig = ASN1_STRING_new());
  48695. ExpectNotNull(canon = ASN1_STRING_new());
  48696. /* Invalid parameter testing. */
  48697. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48698. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48699. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48700. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48701. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48702. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  48703. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48704. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48705. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  48706. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48707. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48708. ASN1_STRING_free(orig);
  48709. orig = NULL;
  48710. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48711. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  48712. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48713. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  48714. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48715. ASN1_STRING_free(orig);
  48716. orig = NULL;
  48717. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48718. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  48719. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48720. ASN1_STRING_free(orig);
  48721. orig = NULL;
  48722. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48723. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48724. ASN1_STRING_free(orig);
  48725. ASN1_STRING_free(canon);
  48726. #endif
  48727. #endif
  48728. return EXPECT_RESULT();
  48729. }
  48730. static int test_wolfSSL_ASN1_STRING_print(void)
  48731. {
  48732. EXPECT_DECLS;
  48733. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  48734. !defined(NO_BIO)
  48735. ASN1_STRING* asnStr = NULL;
  48736. const char HELLO_DATA[]= \
  48737. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  48738. #define MAX_UNPRINTABLE_CHAR 32
  48739. #define MAX_BUF 255
  48740. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  48741. unsigned char expected[sizeof(unprintableData)+1];
  48742. unsigned char rbuf[MAX_BUF];
  48743. BIO *bio = NULL;
  48744. int p_len;
  48745. int i;
  48746. /* setup */
  48747. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  48748. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  48749. expected[i] = (unsigned char)HELLO_DATA[i];
  48750. }
  48751. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  48752. unprintableData[sizeof(HELLO_DATA)+i] = i;
  48753. if (i == (int)'\n' || i == (int)'\r')
  48754. expected[sizeof(HELLO_DATA)+i] = i;
  48755. else
  48756. expected[sizeof(HELLO_DATA)+i] = '.';
  48757. }
  48758. unprintableData[sizeof(unprintableData)-1] = '\0';
  48759. expected[sizeof(expected)-1] = '\0';
  48760. XMEMSET(rbuf, 0, MAX_BUF);
  48761. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48762. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  48763. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48764. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  48765. (int)sizeof(unprintableData)), 1);
  48766. /* test */
  48767. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  48768. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  48769. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  48770. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  48771. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  48772. ExpectStrEQ((char*)rbuf, (const char*)expected);
  48773. BIO_free(bio);
  48774. bio = NULL;
  48775. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48776. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48777. /* Ensure there is 0 bytes available to write into. */
  48778. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  48779. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48780. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48781. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48782. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  48783. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48784. BIO_free(bio);
  48785. ASN1_STRING_free(asnStr);
  48786. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  48787. return EXPECT_RESULT();
  48788. }
  48789. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  48790. {
  48791. EXPECT_DECLS;
  48792. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48793. ASN1_STRING* asn_str = NULL;
  48794. const char data[] = "Hello wolfSSL!";
  48795. ASN1_STRING* esc_str = NULL;
  48796. const char esc_data[] = "a+;<>";
  48797. ASN1_STRING* neg_int = NULL;
  48798. const char neg_int_data[] = "\xff";
  48799. ASN1_STRING* neg_enum = NULL;
  48800. const char neg_enum_data[] = "\xff";
  48801. BIO *bio = NULL;
  48802. BIO *fixed = NULL;
  48803. unsigned long flags;
  48804. int p_len;
  48805. unsigned char rbuf[255];
  48806. /* setup */
  48807. XMEMSET(rbuf, 0, 255);
  48808. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48809. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  48810. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48811. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48812. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  48813. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48814. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  48815. sizeof(esc_data)), 1);
  48816. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  48817. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  48818. sizeof(neg_int_data) - 1), 1);
  48819. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  48820. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  48821. sizeof(neg_enum_data) - 1), 1);
  48822. /* Invalid parameter testing. */
  48823. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  48824. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  48825. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  48826. /* no flags */
  48827. XMEMSET(rbuf, 0, 255);
  48828. flags = 0;
  48829. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  48830. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  48831. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  48832. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48833. /* Ensure there is 0 bytes available to write into. */
  48834. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48835. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48836. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48837. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48838. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  48839. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48840. /* RFC2253 Escape */
  48841. XMEMSET(rbuf, 0, 255);
  48842. flags = ASN1_STRFLGS_ESC_2253;
  48843. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  48844. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  48845. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  48846. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48847. /* Ensure there is 0 bytes available to write into. */
  48848. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48849. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48850. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48851. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48852. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  48853. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48854. /* Show type */
  48855. XMEMSET(rbuf, 0, 255);
  48856. flags = ASN1_STRFLGS_SHOW_TYPE;
  48857. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  48858. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  48859. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  48860. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48861. /* Ensure there is 0 bytes available to write into. */
  48862. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48863. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48864. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48865. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48866. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  48867. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48868. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  48869. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48870. /* Dump All */
  48871. XMEMSET(rbuf, 0, 255);
  48872. flags = ASN1_STRFLGS_DUMP_ALL;
  48873. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  48874. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  48875. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  48876. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48877. /* Ensure there is 0 bytes available to write into. */
  48878. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48879. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48880. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48881. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48882. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48883. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48884. /* Dump Der */
  48885. XMEMSET(rbuf, 0, 255);
  48886. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  48887. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  48888. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  48889. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  48890. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48891. /* Ensure there is 0 bytes available to write into. */
  48892. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48893. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48894. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48895. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48896. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  48897. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48898. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48899. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48900. /* Dump All + Show type */
  48901. XMEMSET(rbuf, 0, 255);
  48902. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48903. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  48904. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  48905. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  48906. /* Dump All + Show type - Negative Integer. */
  48907. XMEMSET(rbuf, 0, 255);
  48908. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48909. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  48910. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  48911. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  48912. /* Dump All + Show type - Negative Enumerated. */
  48913. XMEMSET(rbuf, 0, 255);
  48914. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48915. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  48916. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  48917. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  48918. BIO_free(fixed);
  48919. BIO_free(bio);
  48920. ASN1_STRING_free(asn_str);
  48921. ASN1_STRING_free(esc_str);
  48922. ASN1_STRING_free(neg_int);
  48923. ASN1_STRING_free(neg_enum);
  48924. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  48925. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  48926. #endif
  48927. return EXPECT_RESULT();
  48928. }
  48929. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  48930. {
  48931. EXPECT_DECLS;
  48932. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  48933. ASN1_STRING* asn1str_test = NULL;
  48934. ASN1_STRING* asn1str_answer = NULL;
  48935. /* Each character is encoded using 4 bytes */
  48936. char input[] = {
  48937. 0, 0, 0, 'T',
  48938. 0, 0, 0, 'e',
  48939. 0, 0, 0, 's',
  48940. 0, 0, 0, 't',
  48941. };
  48942. char output[] = "Test";
  48943. char badInput[] = {
  48944. 1, 0, 0, 'T',
  48945. 0, 1, 0, 'e',
  48946. 0, 0, 1, 's',
  48947. };
  48948. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  48949. /* Test wrong type. */
  48950. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48951. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48952. ASN1_STRING_free(asn1str_test);
  48953. asn1str_test = NULL;
  48954. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  48955. /* Test bad length. */
  48956. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  48957. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48958. /* Test bad input. */
  48959. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  48960. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48961. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  48962. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48963. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  48964. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48965. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  48966. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  48967. ExpectNotNull(
  48968. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48969. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  48970. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  48971. ASN1_STRING_free(asn1str_test);
  48972. ASN1_STRING_free(asn1str_answer);
  48973. #endif /* OPENSSL_ALL && !NO_ASN */
  48974. return EXPECT_RESULT();
  48975. }
  48976. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  48977. {
  48978. EXPECT_DECLS;
  48979. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48980. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  48981. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  48982. if (asn1_gtime != NULL)
  48983. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  48984. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  48985. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  48986. return EXPECT_RESULT();
  48987. }
  48988. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  48989. {
  48990. EXPECT_DECLS;
  48991. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  48992. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  48993. BIO* bio = NULL;
  48994. unsigned char buf[24];
  48995. int i;
  48996. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48997. BIO_set_write_buf_size(bio, 24);
  48998. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  48999. /* Type not set. */
  49000. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49001. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  49002. /* Invalid parameters testing. */
  49003. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49004. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49005. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49006. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  49007. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  49008. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  49009. BIO_free(bio);
  49010. bio = NULL;
  49011. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49012. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49013. /* Ensure there is 0 bytes available to write into. */
  49014. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  49015. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49016. for (i = 1; i < 20; i++) {
  49017. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  49018. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49019. }
  49020. BIO_free(bio);
  49021. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  49022. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49023. return EXPECT_RESULT();
  49024. }
  49025. static int test_wolfSSL_ASN1_TIME(void)
  49026. {
  49027. EXPECT_DECLS;
  49028. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49029. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49030. unsigned char *data = NULL;
  49031. ExpectNotNull(asn_time = ASN1_TIME_new());
  49032. #ifndef NO_WOLFSSL_STUB
  49033. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  49034. #endif
  49035. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  49036. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  49037. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  49038. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  49039. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  49040. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  49041. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  49042. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  49043. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  49044. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  49045. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  49046. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  49047. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  49048. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  49049. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  49050. ASN1_TIME_free(asn_time);
  49051. ASN1_TIME_free(NULL);
  49052. #endif
  49053. return EXPECT_RESULT();
  49054. }
  49055. static int test_wolfSSL_ASN1_TIME_to_string(void)
  49056. {
  49057. EXPECT_DECLS;
  49058. #ifndef NO_ASN_TIME
  49059. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49060. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  49061. WOLFSSL_ASN1_TIME* t = NULL;
  49062. char buf[ASN_GENERALIZED_TIME_SIZE];
  49063. ExpectNotNull((t = ASN1_TIME_new()));
  49064. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  49065. /* Invalid parameter testing. */
  49066. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  49067. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  49068. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  49069. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  49070. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  49071. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  49072. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  49073. /* Buffer needs to be longer than minimum of 5 characters. */
  49074. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  49075. ASN1_TIME_free(t);
  49076. #endif
  49077. #endif /* NO_ASN_TIME */
  49078. return EXPECT_RESULT();
  49079. }
  49080. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  49081. {
  49082. EXPECT_DECLS;
  49083. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49084. ASN1_TIME* fromTime = NULL;
  49085. ASN1_TIME* closeToTime = NULL;
  49086. ASN1_TIME* toTime = NULL;
  49087. ASN1_TIME* invalidTime = NULL;
  49088. int daysDiff = 0;
  49089. int secsDiff = 0;
  49090. ExpectNotNull((fromTime = ASN1_TIME_new()));
  49091. /* Feb 22, 2003, 21:15:15 */
  49092. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  49093. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  49094. /* Feb 22, 2003, 21:16:15 */
  49095. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  49096. ExpectNotNull((toTime = ASN1_TIME_new()));
  49097. /* Dec 19, 2010, 18:10:11 */
  49098. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  49099. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  49100. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  49101. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  49102. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  49103. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  49104. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49105. /* Error conditions. */
  49106. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  49107. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  49108. /* If both times are NULL, difference is 0. */
  49109. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  49110. ExpectIntEQ(daysDiff, 0);
  49111. ExpectIntEQ(secsDiff, 0);
  49112. /* If one time is NULL, it defaults to the current time. */
  49113. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  49114. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  49115. /* Normal operation. Both times non-NULL. */
  49116. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49117. ExpectIntEQ(daysDiff, 2856);
  49118. ExpectIntEQ(secsDiff, 75296);
  49119. /* Swapping the times should return negative values. */
  49120. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  49121. ExpectIntEQ(daysDiff, -2856);
  49122. ExpectIntEQ(secsDiff, -75296);
  49123. /* Compare with invalid time string. */
  49124. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  49125. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  49126. /* Compare with days difference of 0. */
  49127. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  49128. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  49129. /* Days and seconds differences not 0. */
  49130. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49131. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49132. /* Same time. */
  49133. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49134. /* Compare regression test: No seconds difference, just difference in days.
  49135. */
  49136. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  49137. ASN1_TIME_set_string(toTime, "19800101000000Z");
  49138. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49139. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49140. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49141. /* Edge case with Unix epoch. */
  49142. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  49143. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  49144. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49145. ExpectIntEQ(daysDiff, 3652);
  49146. ExpectIntEQ(secsDiff, 0);
  49147. /* Edge case with year > 2038 (year 2038 problem). */
  49148. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  49149. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49150. ExpectIntEQ(daysDiff, 2932896);
  49151. ExpectIntEQ(secsDiff, 86399);
  49152. ASN1_TIME_free(fromTime);
  49153. ASN1_TIME_free(closeToTime);
  49154. ASN1_TIME_free(toTime);
  49155. ASN1_TIME_free(invalidTime);
  49156. #endif
  49157. return EXPECT_RESULT();
  49158. }
  49159. static int test_wolfSSL_ASN1_TIME_adj(void)
  49160. {
  49161. EXPECT_DECLS;
  49162. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  49163. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  49164. const int year = 365*24*60*60;
  49165. const int day = 24*60*60;
  49166. const int hour = 60*60;
  49167. const int mini = 60;
  49168. const byte asn_utc_time = ASN_UTC_TIME;
  49169. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  49170. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  49171. #endif
  49172. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49173. WOLFSSL_ASN1_TIME* s = NULL;
  49174. int offset_day;
  49175. long offset_sec;
  49176. char date_str[CTC_DATE_SIZE + 1];
  49177. time_t t;
  49178. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  49179. /* UTC notation test */
  49180. /* 2000/2/15 20:30:00 */
  49181. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  49182. offset_day = 7;
  49183. offset_sec = 45 * mini;
  49184. /* offset_sec = -45 * min;*/
  49185. ExpectNotNull(asn_time =
  49186. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  49187. ExpectTrue(asn_time->type == asn_utc_time);
  49188. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49189. CTC_DATE_SIZE));
  49190. date_str[CTC_DATE_SIZE] = '\0';
  49191. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  49192. /* negative offset */
  49193. offset_sec = -45 * mini;
  49194. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  49195. ExpectNotNull(asn_time);
  49196. ExpectTrue(asn_time->type == asn_utc_time);
  49197. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49198. CTC_DATE_SIZE));
  49199. date_str[CTC_DATE_SIZE] = '\0';
  49200. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  49201. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  49202. s = NULL;
  49203. XMEMSET(date_str, 0, sizeof(date_str));
  49204. /* Generalized time will overflow time_t if not long */
  49205. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  49206. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  49207. DYNAMIC_TYPE_OPENSSL);
  49208. /* GeneralizedTime notation test */
  49209. /* 2055/03/01 09:00:00 */
  49210. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  49211. offset_day = 12;
  49212. offset_sec = 10 * mini;
  49213. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  49214. offset_sec));
  49215. ExpectTrue(asn_time->type == asn_gen_time);
  49216. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49217. CTC_DATE_SIZE));
  49218. date_str[CTC_DATE_SIZE] = '\0';
  49219. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  49220. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  49221. s = NULL;
  49222. XMEMSET(date_str, 0, sizeof(date_str));
  49223. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  49224. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  49225. s = NULL;
  49226. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  49227. offset_day = 7;
  49228. offset_sec = 45 * mini;
  49229. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  49230. offset_sec));
  49231. ExpectTrue(asn_time->type == asn_utc_time);
  49232. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49233. CTC_DATE_SIZE));
  49234. date_str[CTC_DATE_SIZE] = '\0';
  49235. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  49236. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  49237. asn_time = NULL;
  49238. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  49239. offset_sec));
  49240. ExpectTrue(asn_time->type == asn_utc_time);
  49241. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49242. CTC_DATE_SIZE));
  49243. date_str[CTC_DATE_SIZE] = '\0';
  49244. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  49245. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  49246. #endif
  49247. return EXPECT_RESULT();
  49248. }
  49249. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  49250. {
  49251. EXPECT_DECLS;
  49252. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49253. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  49254. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  49255. ASN1_TIME asnTime;
  49256. struct tm tm;
  49257. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  49258. XMEMSET(&tm, 0, sizeof(struct tm));
  49259. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49260. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  49261. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  49262. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49263. ExpectIntEQ(tm.tm_sec, 15);
  49264. ExpectIntEQ(tm.tm_min, 15);
  49265. ExpectIntEQ(tm.tm_hour, 21);
  49266. ExpectIntEQ(tm.tm_mday, 22);
  49267. ExpectIntEQ(tm.tm_mon, 1);
  49268. ExpectIntEQ(tm.tm_year, 100);
  49269. ExpectIntEQ(tm.tm_isdst, 0);
  49270. #ifdef XMKTIME
  49271. ExpectIntEQ(tm.tm_wday, 2);
  49272. ExpectIntEQ(tm.tm_yday, 52);
  49273. #endif
  49274. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  49275. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49276. ExpectIntEQ(tm.tm_year, 50);
  49277. /* Get current time. */
  49278. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  49279. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  49280. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49281. /* 0 length. */
  49282. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49283. /* No type. */
  49284. asnTime.length = 1;
  49285. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49286. /* Not UTCTIME length. */
  49287. asnTime.type = V_ASN1_UTCTIME;
  49288. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49289. /* Not GENERALIZEDTIME length. */
  49290. asnTime.type = V_ASN1_GENERALIZEDTIME;
  49291. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49292. /* Not Zulu timezone. */
  49293. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  49294. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49295. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  49296. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49297. #ifdef XMKTIME
  49298. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  49299. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49300. ExpectIntEQ(tm.tm_sec, 47);
  49301. ExpectIntEQ(tm.tm_min, 22);
  49302. ExpectIntEQ(tm.tm_hour, 21);
  49303. ExpectIntEQ(tm.tm_mday, 12);
  49304. ExpectIntEQ(tm.tm_mon, 4);
  49305. ExpectIntEQ(tm.tm_year, 123);
  49306. ExpectIntEQ(tm.tm_wday, 5);
  49307. ExpectIntEQ(tm.tm_yday, 131);
  49308. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  49309. fields are zeroed out as expected. */
  49310. ExpectIntEQ(tm.tm_isdst, 0);
  49311. #endif
  49312. #endif
  49313. return EXPECT_RESULT();
  49314. }
  49315. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  49316. {
  49317. EXPECT_DECLS;
  49318. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49319. WOLFSSL_ASN1_TIME *t = NULL;
  49320. WOLFSSL_ASN1_TIME *out = NULL;
  49321. WOLFSSL_ASN1_TIME *gtime = NULL;
  49322. int tlen = 0;
  49323. unsigned char *data = NULL;
  49324. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49325. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  49326. /* type not set. */
  49327. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49328. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49329. t = NULL;
  49330. /* UTC Time test */
  49331. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49332. if (t != NULL) {
  49333. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  49334. t->type = ASN_UTC_TIME;
  49335. t->length = ASN_UTC_TIME_SIZE;
  49336. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49337. }
  49338. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  49339. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  49340. out = NULL;
  49341. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49342. wolfSSL_ASN1_TIME_free(gtime);
  49343. gtime = NULL;
  49344. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  49345. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49346. ExpectPtrEq(gtime, out);
  49347. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49348. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49349. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49350. /* Generalized Time test */
  49351. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49352. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49353. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49354. if (t != NULL) {
  49355. t->type = ASN_GENERALIZED_TIME;
  49356. t->length = ASN_GENERALIZED_TIME_SIZE;
  49357. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  49358. }
  49359. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  49360. ASN_GENERALIZED_TIME_SIZE);
  49361. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  49362. "20050727123456Z");
  49363. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49364. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49365. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49366. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49367. /* UTC Time to Generalized Time 1900's test */
  49368. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49369. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49370. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49371. if (t != NULL) {
  49372. t->type = ASN_UTC_TIME;
  49373. t->length = ASN_UTC_TIME_SIZE;
  49374. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  49375. }
  49376. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49377. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49378. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49379. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  49380. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49381. /* Null parameter test */
  49382. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49383. gtime = NULL;
  49384. out = NULL;
  49385. if (t != NULL) {
  49386. t->type = ASN_UTC_TIME;
  49387. t->length = ASN_UTC_TIME_SIZE;
  49388. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49389. }
  49390. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  49391. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49392. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49393. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49394. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49395. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49396. #endif
  49397. return EXPECT_RESULT();
  49398. }
  49399. static int test_wolfSSL_ASN1_TIME_print(void)
  49400. {
  49401. EXPECT_DECLS;
  49402. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  49403. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49404. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  49405. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  49406. !defined(NO_ASN_TIME)
  49407. BIO* bio = NULL;
  49408. BIO* fixed = NULL;
  49409. X509* x509 = NULL;
  49410. const unsigned char* der = client_cert_der_2048;
  49411. ASN1_TIME* notAfter = NULL;
  49412. ASN1_TIME* notBefore = NULL;
  49413. unsigned char buf[25];
  49414. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49415. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49416. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  49417. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  49418. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  49419. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  49420. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  49421. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  49422. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  49423. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49424. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  49425. /* Test BIO_write fails. */
  49426. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49427. /* Ensure there is 0 bytes available to write into. */
  49428. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  49429. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49430. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49431. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49432. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  49433. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49434. /* create a bad time and test results */
  49435. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  49436. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  49437. if (EXPECT_SUCCESS()) {
  49438. notAfter->data[8] = 0;
  49439. notAfter->data[3] = 0;
  49440. }
  49441. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  49442. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49443. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49444. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  49445. BIO_free(bio);
  49446. BIO_free(fixed);
  49447. X509_free(x509);
  49448. #endif
  49449. return EXPECT_RESULT();
  49450. }
  49451. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  49452. {
  49453. EXPECT_DECLS;
  49454. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  49455. BIO* bio = NULL;
  49456. ASN1_UTCTIME* utc = NULL;
  49457. unsigned char buf[25];
  49458. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  49459. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  49460. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  49461. /* Valid date */
  49462. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49463. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  49464. DYNAMIC_TYPE_ASN1));
  49465. if (utc != NULL) {
  49466. utc->type = ASN_UTC_TIME;
  49467. utc->length = ASN_UTC_TIME_SIZE;
  49468. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  49469. }
  49470. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  49471. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  49472. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  49473. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  49474. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49475. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  49476. XMEMSET(buf, 0, sizeof(buf));
  49477. BIO_free(bio);
  49478. bio = NULL;
  49479. /* Invalid format */
  49480. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49481. if (utc != NULL) {
  49482. utc->type = ASN_UTC_TIME;
  49483. utc->length = ASN_UTC_TIME_SIZE;
  49484. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  49485. }
  49486. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49487. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49488. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49489. /* Invalid type */
  49490. if (utc != NULL) {
  49491. utc->type = ASN_GENERALIZED_TIME;
  49492. utc->length = ASN_GENERALIZED_TIME_SIZE;
  49493. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  49494. }
  49495. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49496. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  49497. BIO_free(bio);
  49498. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49499. return EXPECT_RESULT();
  49500. }
  49501. static int test_wolfSSL_ASN1_TYPE(void)
  49502. {
  49503. EXPECT_DECLS;
  49504. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  49505. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  49506. WOLFSSL_ASN1_TYPE* t = NULL;
  49507. WOLFSSL_ASN1_OBJECT* obj = NULL;
  49508. #ifndef NO_ASN_TIME
  49509. WOLFSSL_ASN1_TIME* time = NULL;
  49510. #endif
  49511. WOLFSSL_ASN1_STRING* str = NULL;
  49512. unsigned char data[] = { 0x00 };
  49513. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  49514. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49515. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  49516. wolfSSL_ASN1_TYPE_free(t);
  49517. t = NULL;
  49518. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49519. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  49520. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  49521. wolfSSL_ASN1_TYPE_free(t);
  49522. t = NULL;
  49523. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49524. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49525. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  49526. wolfSSL_ASN1_TYPE_free(t);
  49527. t = NULL;
  49528. #ifndef NO_ASN_TIME
  49529. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49530. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49531. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  49532. wolfSSL_ASN1_TYPE_free(t);
  49533. t = NULL;
  49534. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49535. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49536. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  49537. wolfSSL_ASN1_TYPE_free(t);
  49538. t = NULL;
  49539. #endif
  49540. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49541. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49542. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  49543. wolfSSL_ASN1_TYPE_free(t);
  49544. t = NULL;
  49545. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49546. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49547. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  49548. wolfSSL_ASN1_TYPE_free(t);
  49549. t = NULL;
  49550. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49551. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49552. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  49553. wolfSSL_ASN1_TYPE_free(t);
  49554. t = NULL;
  49555. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49556. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49557. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  49558. wolfSSL_ASN1_TYPE_free(t);
  49559. t = NULL;
  49560. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49561. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49562. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  49563. wolfSSL_ASN1_TYPE_free(t);
  49564. t = NULL;
  49565. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49566. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49567. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  49568. wolfSSL_ASN1_TYPE_free(t);
  49569. t = NULL;
  49570. #endif
  49571. return EXPECT_RESULT();
  49572. }
  49573. /* Testing code used in old dpp.c in hostap */
  49574. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49575. typedef struct {
  49576. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  49577. * as an OID identifying the curve */
  49578. X509_ALGOR *alg;
  49579. /* Compressed format public key per ANSI X9.63 */
  49580. ASN1_BIT_STRING *pub_key;
  49581. } DPP_BOOTSTRAPPING_KEY;
  49582. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  49583. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  49584. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  49585. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  49586. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  49587. typedef struct {
  49588. int type;
  49589. union {
  49590. ASN1_BIT_STRING *str1;
  49591. ASN1_BIT_STRING *str2;
  49592. ASN1_BIT_STRING *str3;
  49593. } d;
  49594. } ASN1_CHOICE_TEST;
  49595. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  49596. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  49597. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  49598. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  49599. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  49600. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  49601. /* Test nested objects */
  49602. typedef struct {
  49603. DPP_BOOTSTRAPPING_KEY* key;
  49604. ASN1_INTEGER* asnNum;
  49605. ASN1_INTEGER* expNum;
  49606. STACK_OF(ASN1_GENERALSTRING) *strList;
  49607. ASN1_CHOICE_TEST* str;
  49608. } TEST_ASN1_NEST1;
  49609. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  49610. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  49611. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  49612. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  49613. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  49614. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  49615. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  49616. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  49617. typedef struct {
  49618. ASN1_INTEGER* num;
  49619. DPP_BOOTSTRAPPING_KEY* key;
  49620. TEST_ASN1_NEST1* asn1_obj;
  49621. } TEST_ASN1_NEST2;
  49622. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  49623. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  49624. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  49625. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  49626. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  49627. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  49628. /* End nested objects */
  49629. typedef struct {
  49630. ASN1_INTEGER *integer;
  49631. } TEST_ASN1;
  49632. ASN1_SEQUENCE(TEST_ASN1) = {
  49633. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  49634. } ASN1_SEQUENCE_END(TEST_ASN1)
  49635. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  49636. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  49637. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  49638. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  49639. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  49640. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  49641. #endif
  49642. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  49643. {
  49644. EXPECT_DECLS;
  49645. /* Testing code used in dpp.c in hostap */
  49646. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49647. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  49648. EC_KEY *eckey = NULL;
  49649. EVP_PKEY *key = NULL;
  49650. size_t len = 0;
  49651. unsigned char *der = NULL;
  49652. unsigned char *der2 = NULL;
  49653. const unsigned char *tmp = NULL;
  49654. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  49655. const unsigned char *in = ecc_clikey_der_256;
  49656. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  49657. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  49658. const EC_GROUP *group = NULL;
  49659. const EC_POINT *point = NULL;
  49660. int nid;
  49661. TEST_ASN1 *test_asn1 = NULL;
  49662. TEST_ASN1 *test_asn1_2 = NULL;
  49663. const unsigned char badObjDer[] = { 0x06, 0x00 };
  49664. const unsigned char goodObjDer[] = {
  49665. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  49666. };
  49667. WOLFSSL_ASN1_ITEM emptyTemplate;
  49668. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  49669. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49670. der = NULL;
  49671. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  49672. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  49673. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49674. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  49675. (long)sizeof_ecc_clikey_der_256));
  49676. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  49677. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  49678. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  49679. nid = EC_GROUP_get_curve_name(group);
  49680. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49681. group_obj = OBJ_nid2obj(nid);
  49682. if ((ec_obj != NULL) && (group_obj != NULL)) {
  49683. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  49684. group_obj), 1);
  49685. if (EXPECT_SUCCESS()) {
  49686. ec_obj = NULL;
  49687. group_obj = NULL;
  49688. }
  49689. }
  49690. wolfSSL_ASN1_OBJECT_free(group_obj);
  49691. wolfSSL_ASN1_OBJECT_free(ec_obj);
  49692. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  49693. #ifdef HAVE_COMP_KEY
  49694. ExpectIntGT((len = EC_POINT_point2oct(
  49695. group, point, POINT_CONVERSION_COMPRESSED,
  49696. NULL, 0, NULL)), 0);
  49697. #else
  49698. ExpectIntGT((len = EC_POINT_point2oct(
  49699. group, point, POINT_CONVERSION_UNCOMPRESSED,
  49700. NULL, 0, NULL)), 0);
  49701. #endif
  49702. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  49703. #ifdef HAVE_COMP_KEY
  49704. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49705. der, len-1, NULL), 0);
  49706. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49707. der, len, NULL), len);
  49708. #else
  49709. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49710. der, len-1, NULL), 0);
  49711. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49712. der, len, NULL), len);
  49713. #endif
  49714. if (EXPECT_SUCCESS()) {
  49715. bootstrap->pub_key->data = der;
  49716. bootstrap->pub_key->length = (int)len;
  49717. /* Not actually used */
  49718. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49719. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49720. }
  49721. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  49722. der = NULL;
  49723. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  49724. der2 = NULL;
  49725. #ifdef WOLFSSL_ASN_TEMPLATE
  49726. tmp = der;
  49727. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  49728. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  49729. ExpectBufEQ(der, der2, 49);
  49730. #endif
  49731. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49732. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49733. EVP_PKEY_free(key);
  49734. EC_KEY_free(eckey);
  49735. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49736. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  49737. bootstrap = NULL;
  49738. DPP_BOOTSTRAPPING_KEY_free(NULL);
  49739. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  49740. * a NULL and an empty BIT_STRING. */
  49741. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49742. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  49743. if (EXPECT_SUCCESS()) {
  49744. bootstrap->alg->algorithm->obj = badObjDer;
  49745. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  49746. }
  49747. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  49748. if (EXPECT_SUCCESS()) {
  49749. bootstrap->alg->parameter->type = V_ASN1_NULL;
  49750. bootstrap->alg->parameter->value.ptr = NULL;
  49751. bootstrap->pub_key->data = NULL;
  49752. bootstrap->pub_key->length = 0;
  49753. /* Not actually used */
  49754. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49755. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49756. }
  49757. /* Encode with bad OBJECT_ID. */
  49758. der = NULL;
  49759. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49760. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  49761. if (EXPECT_SUCCESS()) {
  49762. bootstrap->alg->algorithm->obj = goodObjDer;
  49763. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  49764. bootstrap->alg->algorithm->grp = 2;
  49765. }
  49766. der = NULL;
  49767. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  49768. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  49769. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49770. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49771. /* Test integer */
  49772. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  49773. der = NULL;
  49774. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  49775. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  49776. tmp = der;
  49777. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  49778. der2 = NULL;
  49779. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  49780. ExpectBufEQ(der, der2, 5);
  49781. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49782. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49783. TEST_ASN1_free(test_asn1);
  49784. TEST_ASN1_free(test_asn1_2);
  49785. /* Test integer cases. */
  49786. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  49787. TEST_ASN1_free(NULL);
  49788. /* Test nested asn1 objects */
  49789. {
  49790. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  49791. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  49792. int i;
  49793. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  49794. /* Populate nested_asn1 with some random data */
  49795. /* nested_asn1->num */
  49796. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  49797. /* nested_asn1->key */
  49798. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49799. group_obj = OBJ_nid2obj(NID_secp256k1);
  49800. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  49801. V_ASN1_OBJECT, group_obj), 1);
  49802. ec_obj = NULL;
  49803. group_obj = NULL;
  49804. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  49805. 1);
  49806. /* nested_asn1->asn1_obj->key */
  49807. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49808. group_obj = OBJ_nid2obj(NID_secp256k1);
  49809. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  49810. V_ASN1_OBJECT, group_obj), 1);
  49811. ec_obj = NULL;
  49812. group_obj = NULL;
  49813. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  49814. 500, 1), 1);
  49815. /* nested_asn1->asn1_obj->asnNum */
  49816. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  49817. /* nested_asn1->asn1_obj->expNum */
  49818. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  49819. /* nested_asn1->asn1_obj->strList */
  49820. for (i = 10; i >= 0; i--) {
  49821. ASN1_GENERALSTRING* genStr = NULL;
  49822. char fmtStr[20];
  49823. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  49824. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  49825. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  49826. ExpectIntGT(
  49827. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  49828. genStr), 0);
  49829. }
  49830. /* nested_asn1->asn1_obj->str */
  49831. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  49832. = ASN1_BIT_STRING_new());
  49833. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  49834. 150, 1), 1);
  49835. nested_asn1->asn1_obj->str->type = 2;
  49836. der = NULL;
  49837. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  49838. #ifdef WOLFSSL_ASN_TEMPLATE
  49839. tmp = der;
  49840. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  49841. der2 = NULL;
  49842. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  49843. ExpectBufEQ(der, der2, 285);
  49844. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49845. #endif
  49846. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49847. TEST_ASN1_NEST2_free(nested_asn1);
  49848. TEST_ASN1_NEST2_free(nested_asn1_2);
  49849. }
  49850. /* Test ASN1_ITEM_TEMPLATE */
  49851. {
  49852. TEST_ASN1_ITEM* asn1_item = NULL;
  49853. TEST_ASN1_ITEM* asn1_item2 = NULL;
  49854. int i;
  49855. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  49856. for (i = 0; i < 11; i++) {
  49857. ASN1_INTEGER* asn1_num = NULL;
  49858. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  49859. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  49860. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  49861. }
  49862. der = NULL;
  49863. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  49864. tmp = der;
  49865. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  49866. der2 = NULL;
  49867. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  49868. ExpectBufEQ(der, der2, 35);
  49869. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49870. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49871. TEST_ASN1_ITEM_free(asn1_item);
  49872. TEST_ASN1_ITEM_free(asn1_item2);
  49873. }
  49874. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  49875. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49876. return EXPECT_RESULT();
  49877. }
  49878. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  49879. {
  49880. EXPECT_DECLS;
  49881. #if defined(OPENSSL_EXTRA)
  49882. /* Taken from one of sssd's certs othernames */
  49883. unsigned char str_bin[] = {
  49884. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49885. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49886. };
  49887. ASN1_TYPE* asn1type = NULL;
  49888. unsigned char* der = NULL;
  49889. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  49890. {
  49891. ASN1_STRING* str = NULL;
  49892. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49893. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49894. ExpectNotNull(asn1type = ASN1_TYPE_new());
  49895. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  49896. }
  49897. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  49898. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  49899. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  49900. ASN1_TYPE_free(asn1type);
  49901. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49902. #endif
  49903. return EXPECT_RESULT();
  49904. }
  49905. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  49906. {
  49907. EXPECT_DECLS;
  49908. #if defined(OPENSSL_EXTRA)
  49909. /* Taken from one of sssd's certs othernames */
  49910. unsigned char str_bin[] = {
  49911. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49912. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49913. };
  49914. ASN1_STRING* str = NULL;
  49915. unsigned char* der = NULL;
  49916. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49917. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49918. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  49919. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  49920. ASN1_STRING_free(str);
  49921. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49922. #endif
  49923. return EXPECT_RESULT();
  49924. }
  49925. static int test_ASN1_strings(void)
  49926. {
  49927. EXPECT_DECLS;
  49928. #if defined(OPENSSL_EXTRA)
  49929. char text[] = "\0\0test string";
  49930. unsigned char* der = NULL;
  49931. ASN1_STRING* str = NULL;
  49932. /* Set the length byte */
  49933. text[1] = XSTRLEN(text + 2);
  49934. /* GENERALSTRING */
  49935. {
  49936. const unsigned char* p = (const unsigned char*)text;
  49937. text[0] = ASN_GENERALSTRING;
  49938. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  49939. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  49940. ASN1_STRING_free(str);
  49941. str = NULL;
  49942. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49943. der = NULL;
  49944. }
  49945. /* OCTET_STRING */
  49946. {
  49947. const unsigned char* p = (const unsigned char*)text;
  49948. text[0] = ASN_OCTET_STRING;
  49949. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  49950. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  49951. ASN1_STRING_free(str);
  49952. str = NULL;
  49953. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49954. der = NULL;
  49955. }
  49956. /* UTF8STRING */
  49957. {
  49958. const unsigned char* p = (const unsigned char*)text;
  49959. text[0] = ASN_UTF8STRING;
  49960. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  49961. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  49962. ASN1_STRING_free(str);
  49963. str = NULL;
  49964. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49965. der = NULL;
  49966. }
  49967. #endif
  49968. return EXPECT_RESULT();
  49969. }
  49970. static int test_wolfSSL_lhash(void)
  49971. {
  49972. EXPECT_DECLS;
  49973. #ifdef OPENSSL_ALL
  49974. const char testStr[] = "Like a true nature's child\n"
  49975. "We were born\n"
  49976. "Born to be wild";
  49977. #ifdef NO_SHA
  49978. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  49979. #else
  49980. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  49981. #endif
  49982. #endif
  49983. return EXPECT_RESULT();
  49984. }
  49985. static int test_wolfSSL_X509_NAME(void)
  49986. {
  49987. EXPECT_DECLS;
  49988. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  49989. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  49990. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  49991. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  49992. defined(OPENSSL_EXTRA))
  49993. X509* x509 = NULL;
  49994. const unsigned char* c = NULL;
  49995. unsigned char buf[4096];
  49996. int bytes = 0;
  49997. XFILE f = XBADFILE;
  49998. const X509_NAME* a = NULL;
  49999. const X509_NAME* b = NULL;
  50000. X509_NAME* d2i_name = NULL;
  50001. int sz = 0;
  50002. unsigned char* tmp = NULL;
  50003. char file[] = "./certs/ca-cert.der";
  50004. #ifndef OPENSSL_EXTRA_X509_SMALL
  50005. byte empty[] = { /* CN=empty emailAddress= */
  50006. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  50007. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  50008. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  50009. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  50010. 0x01, 0x16, 0x00
  50011. };
  50012. #endif
  50013. #ifndef OPENSSL_EXTRA_X509_SMALL
  50014. /* test compile of deprecated function, returns 0 */
  50015. ExpectIntEQ(CRYPTO_thread_id(), 0);
  50016. #endif
  50017. ExpectNotNull(a = X509_NAME_new());
  50018. X509_NAME_free((X509_NAME*)a);
  50019. a = NULL;
  50020. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  50021. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  50022. if (f != XBADFILE)
  50023. XFCLOSE(f);
  50024. c = buf;
  50025. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  50026. /* test cmp function */
  50027. ExpectNotNull(a = X509_get_issuer_name(x509));
  50028. ExpectNotNull(b = X509_get_subject_name(x509));
  50029. #ifndef OPENSSL_EXTRA_X509_SMALL
  50030. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  50031. #endif
  50032. tmp = buf;
  50033. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  50034. if (sz > 0 && tmp == buf) {
  50035. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  50036. __LINE__);
  50037. fprintf(stderr, " Expected pointer to be incremented\n");
  50038. abort();
  50039. }
  50040. #ifndef OPENSSL_EXTRA_X509_SMALL
  50041. tmp = buf;
  50042. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50043. #endif
  50044. /* if output parameter is NULL, should still return required size. */
  50045. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  50046. /* retry but with the function creating a buffer */
  50047. tmp = NULL;
  50048. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50049. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50050. tmp = NULL;
  50051. #ifdef WOLFSSL_CERT_NAME_ALL
  50052. /* test for givenName and name */
  50053. {
  50054. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  50055. const byte gName[] = "test-given-name";
  50056. const byte name[] = "test-name";
  50057. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50058. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  50059. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50060. 1);
  50061. wolfSSL_X509_NAME_ENTRY_free(entry);
  50062. entry = NULL;
  50063. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50064. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  50065. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50066. 1);
  50067. wolfSSL_X509_NAME_ENTRY_free(entry);
  50068. tmp = NULL;
  50069. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50070. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50071. }
  50072. #endif
  50073. b = NULL;
  50074. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  50075. #ifndef OPENSSL_EXTRA_X509_SMALL
  50076. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  50077. #endif
  50078. X509_NAME_free((X509_NAME*)b);
  50079. X509_NAME_free(d2i_name);
  50080. d2i_name = NULL;
  50081. X509_free(x509);
  50082. #ifndef OPENSSL_EXTRA_X509_SMALL
  50083. /* test with an empty domain component */
  50084. tmp = empty;
  50085. sz = sizeof(empty);
  50086. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50087. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  50088. /* size of empty emailAddress will be 0 */
  50089. tmp = buf;
  50090. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  50091. (char*)tmp, sizeof(buf)), 0);
  50092. /* should contain no organization name */
  50093. tmp = buf;
  50094. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  50095. (char*)tmp, sizeof(buf)), -1);
  50096. X509_NAME_free(d2i_name);
  50097. #endif
  50098. #endif
  50099. return EXPECT_RESULT();
  50100. }
  50101. static int test_wolfSSL_X509_NAME_hash(void)
  50102. {
  50103. EXPECT_DECLS;
  50104. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  50105. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  50106. BIO* bio = NULL;
  50107. X509* x509 = NULL;
  50108. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50109. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50110. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50111. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  50112. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  50113. X509_free(x509);
  50114. BIO_free(bio);
  50115. #endif
  50116. return EXPECT_RESULT();
  50117. }
  50118. static int test_wolfSSL_X509_NAME_print_ex(void)
  50119. {
  50120. EXPECT_DECLS;
  50121. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  50122. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  50123. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  50124. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  50125. !defined(NO_BIO) && !defined(NO_RSA)
  50126. int memSz = 0;
  50127. byte* mem = NULL;
  50128. BIO* bio = NULL;
  50129. BIO* membio = NULL;
  50130. X509* x509 = NULL;
  50131. X509_NAME* name = NULL;
  50132. const char* expNormal = "C=US, CN=wolfssl.com";
  50133. const char* expEqSpace = "C = US, CN = wolfssl.com";
  50134. const char* expReverse = "CN=wolfssl.com, C=US";
  50135. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  50136. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  50137. const char* expRFC5523 =
  50138. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  50139. /* Test with real cert (svrCertFile) first */
  50140. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50141. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50142. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50143. ExpectNotNull(name = X509_get_subject_name(x509));
  50144. /* Test without flags */
  50145. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50146. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50147. BIO_free(membio);
  50148. membio = NULL;
  50149. /* Test flag: XN_FLAG_RFC2253 */
  50150. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50151. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50152. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50153. BIO_free(membio);
  50154. membio = NULL;
  50155. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  50156. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50157. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50158. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50159. BIO_free(membio);
  50160. membio = NULL;
  50161. X509_free(x509);
  50162. BIO_free(bio);
  50163. name = NULL;
  50164. /* Test normal case without escaped characters */
  50165. {
  50166. /* Create name: "/C=US/CN=wolfssl.com" */
  50167. ExpectNotNull(name = X509_NAME_new());
  50168. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  50169. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  50170. WOLFSSL_SUCCESS);
  50171. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  50172. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  50173. WOLFSSL_SUCCESS);
  50174. /* Test without flags */
  50175. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50176. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50177. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50178. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  50179. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  50180. BIO_free(membio);
  50181. membio = NULL;
  50182. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  50183. spaces aroun '=' */
  50184. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50185. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  50186. WOLFSSL_SUCCESS);
  50187. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50188. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  50189. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  50190. BIO_free(membio);
  50191. membio = NULL;
  50192. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  50193. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50194. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50195. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50196. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50197. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  50198. BIO_free(membio);
  50199. membio = NULL;
  50200. /* Test flags: XN_FLAG_DN_REV - reversed */
  50201. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50202. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50203. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50204. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50205. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  50206. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  50207. BIO_free(membio);
  50208. membio = NULL;
  50209. X509_NAME_free(name);
  50210. name = NULL;
  50211. }
  50212. /* Test RFC2253 characters are escaped with backslashes */
  50213. {
  50214. ExpectNotNull(name = X509_NAME_new());
  50215. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  50216. /* space at beginning and end, and: ,+"\ */
  50217. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  50218. WOLFSSL_SUCCESS);
  50219. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  50220. /* # at beginning, and: <>;*/
  50221. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  50222. WOLFSSL_SUCCESS);
  50223. /* Test without flags */
  50224. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50225. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50226. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50227. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  50228. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  50229. XSTRLEN(expNotEscaped)), 0);
  50230. BIO_free(membio);
  50231. membio = NULL;
  50232. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  50233. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50234. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50235. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50236. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50237. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  50238. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  50239. BIO_free(membio);
  50240. membio = NULL;
  50241. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  50242. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50243. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50244. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50245. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50246. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  50247. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  50248. XSTRLEN(expNotEscapedRev)), 0);
  50249. BIO_free(membio);
  50250. X509_NAME_free(name);
  50251. }
  50252. #endif
  50253. return EXPECT_RESULT();
  50254. }
  50255. #ifndef NO_BIO
  50256. static int test_wolfSSL_X509_INFO_multiple_info(void)
  50257. {
  50258. EXPECT_DECLS;
  50259. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50260. STACK_OF(X509_INFO) *info_stack = NULL;
  50261. X509_INFO *info = NULL;
  50262. int len;
  50263. int i;
  50264. const char* files[] = {
  50265. cliCertFile,
  50266. cliKeyFile,
  50267. /* This needs to be the order as svrCertFile contains the
  50268. * intermediate cert as well. */
  50269. svrKeyFile,
  50270. svrCertFile,
  50271. NULL,
  50272. };
  50273. const char** curFile;
  50274. BIO *fileBIO = NULL;
  50275. BIO *concatBIO = NULL;
  50276. byte tmp[FOURK_BUF];
  50277. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  50278. * to group objects together. */
  50279. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  50280. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  50281. int fileLen = 0;
  50282. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  50283. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  50284. if (EXPECT_SUCCESS()) {
  50285. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  50286. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  50287. fileLen -= len;
  50288. if (EXPECT_FAIL())
  50289. break;
  50290. }
  50291. /* Make sure we read the entire file */
  50292. ExpectIntEQ(fileLen, 0);
  50293. }
  50294. BIO_free(fileBIO);
  50295. fileBIO = NULL;
  50296. }
  50297. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  50298. NULL));
  50299. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  50300. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50301. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50302. ExpectNotNull(info->x509);
  50303. ExpectNull(info->crl);
  50304. if (i != 0) {
  50305. ExpectNotNull(info->x_pkey);
  50306. ExpectIntEQ(X509_check_private_key(info->x509,
  50307. info->x_pkey->dec_pkey), 1);
  50308. }
  50309. else {
  50310. ExpectNull(info->x_pkey);
  50311. }
  50312. }
  50313. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50314. BIO_free(concatBIO);
  50315. #endif
  50316. return EXPECT_RESULT();
  50317. }
  50318. #endif
  50319. #ifndef NO_BIO
  50320. static int test_wolfSSL_X509_INFO(void)
  50321. {
  50322. EXPECT_DECLS;
  50323. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50324. STACK_OF(X509_INFO) *info_stack = NULL;
  50325. X509_INFO *info = NULL;
  50326. BIO *cert = NULL;
  50327. int i;
  50328. /* PEM in hex format to avoid null terminator */
  50329. byte data[] = {
  50330. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  50331. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  50332. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  50333. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  50334. 0x2d, 0x2d, 0x2d
  50335. };
  50336. /* PEM in hex format to avoid null terminator */
  50337. byte data2[] = {
  50338. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  50339. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  50340. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  50341. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  50342. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  50343. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  50344. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  50345. };
  50346. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50347. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50348. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50349. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50350. ExpectNotNull(info->x509);
  50351. ExpectNull(info->crl);
  50352. ExpectNull(info->x_pkey);
  50353. }
  50354. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50355. info_stack = NULL;
  50356. BIO_free(cert);
  50357. cert = NULL;
  50358. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50359. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50360. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50361. info_stack = NULL;
  50362. BIO_free(cert);
  50363. cert = NULL;
  50364. /* This case should fail due to invalid input. */
  50365. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50366. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  50367. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50368. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50369. info_stack = NULL;
  50370. BIO_free(cert);
  50371. cert = NULL;
  50372. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50373. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  50374. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50375. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50376. BIO_free(cert);
  50377. #endif
  50378. return EXPECT_RESULT();
  50379. }
  50380. #endif
  50381. static int test_wolfSSL_X509_subject_name_hash(void)
  50382. {
  50383. EXPECT_DECLS;
  50384. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50385. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50386. X509* x509 = NULL;
  50387. X509_NAME* subjectName = NULL;
  50388. unsigned long ret1 = 0;
  50389. unsigned long ret2 = 0;
  50390. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50391. SSL_FILETYPE_PEM));
  50392. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  50393. /* These two
  50394. * - X509_subject_name_hash(x509)
  50395. * - X509_NAME_hash(X509_get_subject_name(x509))
  50396. * should give the same hash, if !defined(NO_SHA) is true. */
  50397. ret1 = X509_subject_name_hash(x509);
  50398. ExpectIntNE(ret1, 0);
  50399. #if !defined(NO_SHA)
  50400. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  50401. ExpectIntNE(ret2, 0);
  50402. ExpectIntEQ(ret1, ret2);
  50403. #else
  50404. (void) ret2;
  50405. #endif
  50406. X509_free(x509);
  50407. #endif
  50408. return EXPECT_RESULT();
  50409. }
  50410. static int test_wolfSSL_X509_issuer_name_hash(void)
  50411. {
  50412. EXPECT_DECLS;
  50413. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50414. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50415. X509* x509 = NULL;
  50416. X509_NAME* issuertName = NULL;
  50417. unsigned long ret1 = 0;
  50418. unsigned long ret2 = 0;
  50419. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50420. SSL_FILETYPE_PEM));
  50421. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  50422. /* These two
  50423. * - X509_issuer_name_hash(x509)
  50424. * - X509_NAME_hash(X509_get_issuer_name(x509))
  50425. * should give the same hash, if !defined(NO_SHA) is true. */
  50426. ret1 = X509_issuer_name_hash(x509);
  50427. ExpectIntNE(ret1, 0);
  50428. #if !defined(NO_SHA)
  50429. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  50430. ExpectIntNE(ret2, 0);
  50431. ExpectIntEQ(ret1, ret2);
  50432. #else
  50433. (void) ret2;
  50434. #endif
  50435. X509_free(x509);
  50436. #endif
  50437. return EXPECT_RESULT();
  50438. }
  50439. static int test_wolfSSL_X509_check_host(void)
  50440. {
  50441. EXPECT_DECLS;
  50442. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50443. && !defined(NO_SHA) && !defined(NO_RSA)
  50444. X509* x509 = NULL;
  50445. const char altName[] = "example.com";
  50446. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50447. SSL_FILETYPE_PEM));
  50448. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  50449. WOLFSSL_SUCCESS);
  50450. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  50451. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50452. X509_free(x509);
  50453. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  50454. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50455. #endif
  50456. return EXPECT_RESULT();
  50457. }
  50458. static int test_wolfSSL_X509_check_email(void)
  50459. {
  50460. EXPECT_DECLS;
  50461. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  50462. X509* x509 = NULL;
  50463. const char goodEmail[] = "info@wolfssl.com";
  50464. const char badEmail[] = "disinfo@wolfssl.com";
  50465. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50466. SSL_FILETYPE_PEM));
  50467. /* Should fail on non-matching email address */
  50468. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  50469. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50470. /* Should succeed on matching email address */
  50471. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  50472. WOLFSSL_SUCCESS);
  50473. /* Should compute length internally when not provided */
  50474. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  50475. WOLFSSL_SUCCESS);
  50476. /* Should fail when email address is NULL */
  50477. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  50478. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50479. X509_free(x509);
  50480. /* Should fail when x509 is NULL */
  50481. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  50482. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50483. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  50484. return EXPECT_RESULT();
  50485. }
  50486. static int test_wc_PemToDer(void)
  50487. {
  50488. EXPECT_DECLS;
  50489. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50490. int ret;
  50491. DerBuffer* pDer = NULL;
  50492. const char* ca_cert = "./certs/server-cert.pem";
  50493. byte* cert_buf = NULL;
  50494. size_t cert_sz = 0;
  50495. int eccKey = 0;
  50496. EncryptedInfo info;
  50497. XMEMSET(&info, 0, sizeof(info));
  50498. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50499. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  50500. &info, &eccKey), 0);
  50501. wc_FreeDer(&pDer);
  50502. pDer = NULL;
  50503. if (cert_buf != NULL) {
  50504. free(cert_buf);
  50505. cert_buf = NULL;
  50506. }
  50507. #ifdef HAVE_ECC
  50508. {
  50509. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  50510. byte key_buf[256] = {0};
  50511. /* Test fail of loading a key with cert type */
  50512. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  50513. key_buf[0] = '\n';
  50514. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  50515. ExpectIntNE((ret = wc_PemToDer(key_buf, cert_sz + 1, CERT_TYPE,
  50516. &pDer, NULL, &info, &eccKey)), 0);
  50517. #ifdef OPENSSL_EXTRA
  50518. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  50519. &pDer, NULL, &info, &eccKey)), 0);
  50520. #endif
  50521. wc_FreeDer(&pDer);
  50522. if (cert_buf != NULL)
  50523. free(cert_buf);
  50524. }
  50525. #endif
  50526. #endif
  50527. return EXPECT_RESULT();
  50528. }
  50529. static int test_wc_AllocDer(void)
  50530. {
  50531. EXPECT_DECLS;
  50532. #if !defined(NO_CERTS)
  50533. DerBuffer* pDer = NULL;
  50534. word32 testSize = 1024;
  50535. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  50536. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50537. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  50538. ExpectNotNull(pDer);
  50539. wc_FreeDer(&pDer);
  50540. #endif
  50541. return EXPECT_RESULT();
  50542. }
  50543. static int test_wc_CertPemToDer(void)
  50544. {
  50545. EXPECT_DECLS;
  50546. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50547. const char* ca_cert = "./certs/ca-cert.pem";
  50548. byte* cert_buf = NULL;
  50549. size_t cert_sz = 0;
  50550. size_t cert_dersz = 0;
  50551. byte* cert_der = NULL;
  50552. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50553. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50554. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50555. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50556. (int)cert_dersz, CERT_TYPE), 0);
  50557. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  50558. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50559. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  50560. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50561. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  50562. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50563. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  50564. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50565. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  50566. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50567. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  50568. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50569. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  50570. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50571. if (cert_der != NULL)
  50572. free(cert_der);
  50573. if (cert_buf != NULL)
  50574. free(cert_buf);
  50575. #endif
  50576. return EXPECT_RESULT();
  50577. }
  50578. static int test_wc_KeyPemToDer(void)
  50579. {
  50580. EXPECT_DECLS;
  50581. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  50582. int ret = 0;
  50583. const byte cert_buf[] = \
  50584. "-----BEGIN PRIVATE KEY-----\n"
  50585. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  50586. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  50587. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  50588. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  50589. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  50590. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  50591. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  50592. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  50593. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  50594. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  50595. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  50596. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  50597. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  50598. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  50599. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  50600. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  50601. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  50602. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  50603. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  50604. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  50605. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  50606. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  50607. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  50608. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  50609. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  50610. "AQue5o6oVfhgLiJzMdo/77gw\n"
  50611. "-----END PRIVATE KEY-----\n";
  50612. const int cert_sz = sizeof(cert_buf);
  50613. const char cert_pw[] = "password";
  50614. int cert_dersz = 0;
  50615. byte* cert_der = NULL;
  50616. /* Bad arg: Cert buffer is NULL */
  50617. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  50618. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50619. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  50620. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  50621. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50622. /* Test normal operation */
  50623. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50624. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50625. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50626. cert_pw), 0);
  50627. ExpectIntLE(ret, cert_sz);
  50628. if (cert_der != NULL) {
  50629. free(cert_der);
  50630. cert_der = NULL;
  50631. }
  50632. /* Test NULL for DER buffer to return needed DER buffer size */
  50633. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  50634. ExpectIntLE(ret, cert_sz);
  50635. if (EXPECT_SUCCESS())
  50636. cert_dersz = ret;
  50637. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50638. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50639. cert_pw), 0);
  50640. ExpectIntLE(ret, cert_sz);
  50641. if (cert_der != NULL)
  50642. free(cert_der);
  50643. #endif
  50644. return EXPECT_RESULT();
  50645. }
  50646. static int test_wc_PubKeyPemToDer(void)
  50647. {
  50648. EXPECT_DECLS;
  50649. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  50650. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50651. int ret = 0;
  50652. const char* key = "./certs/ecc-client-keyPub.pem";
  50653. byte* cert_buf = NULL;
  50654. size_t cert_sz = 0, cert_dersz = 0;
  50655. byte* cert_der = NULL;
  50656. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  50657. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50658. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  50659. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50660. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50661. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50662. (int)cert_dersz), 0);
  50663. if (cert_der != NULL) {
  50664. free(cert_der);
  50665. cert_der = NULL;
  50666. }
  50667. /* Test NULL for DER buffer to return needed DER buffer size */
  50668. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  50669. ExpectIntLE(ret, cert_sz);
  50670. cert_dersz = (size_t)ret;
  50671. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50672. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50673. (int)cert_dersz), 0);
  50674. if (cert_der != NULL) {
  50675. free(cert_der);
  50676. }
  50677. if (cert_buf != NULL) {
  50678. free(cert_buf);
  50679. }
  50680. #endif
  50681. return EXPECT_RESULT();
  50682. }
  50683. static int test_wc_PemPubKeyToDer(void)
  50684. {
  50685. EXPECT_DECLS;
  50686. #if !defined(NO_FILESYSTEM) && \
  50687. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50688. const char* key = "./certs/ecc-client-keyPub.pem";
  50689. size_t cert_dersz = 1024;
  50690. byte* cert_der = NULL;
  50691. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  50692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50693. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50694. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  50695. if (cert_der != NULL) {
  50696. free(cert_der);
  50697. }
  50698. #endif
  50699. return EXPECT_RESULT();
  50700. }
  50701. static int test_wc_GetPubKeyDerFromCert(void)
  50702. {
  50703. EXPECT_DECLS;
  50704. #if !defined(NO_RSA) || defined(HAVE_ECC)
  50705. int ret;
  50706. word32 idx = 0;
  50707. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50708. word32 keyDerSz = (word32)sizeof(keyDer);
  50709. DecodedCert decoded;
  50710. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50711. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  50712. word32 certBufSz = sizeof(certBuf);
  50713. #endif
  50714. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  50715. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  50716. XFILE fp = XBADFILE;
  50717. #endif
  50718. #ifndef NO_RSA
  50719. RsaKey rsaKey;
  50720. #if defined(USE_CERT_BUFFERS_2048)
  50721. byte* rsaCertDer = (byte*)client_cert_der_2048;
  50722. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  50723. #elif defined(USE_CERT_BUFFERS_1024)
  50724. byte* rsaCertDer = (byte*)client_cert_der_1024;
  50725. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  50726. #else
  50727. unsigned char rsaCertDer[TWOK_BUF];
  50728. word32 rsaCertDerSz;
  50729. #endif
  50730. #endif
  50731. #ifdef HAVE_ECC
  50732. ecc_key eccKey;
  50733. #if defined(USE_CERT_BUFFERS_256)
  50734. byte* eccCert = (byte*)cliecc_cert_der_256;
  50735. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  50736. #else
  50737. unsigned char eccCert[ONEK_BUF];
  50738. word32 eccCertSz;
  50739. XFILE fp2 = XBADFILE;
  50740. #endif
  50741. #endif
  50742. #ifndef NO_RSA
  50743. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  50744. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  50745. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  50746. fp), 0);
  50747. if (fp != XBADFILE) {
  50748. XFCLOSE(fp);
  50749. fp = XBADFILE;
  50750. }
  50751. #endif
  50752. /* good test case - RSA DER cert */
  50753. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  50754. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50755. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50756. ExpectIntGT(keyDerSz, 0);
  50757. /* sanity check, verify we can import DER public key */
  50758. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50759. ExpectIntEQ(ret, 0);
  50760. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50761. if (ret == 0) {
  50762. wc_FreeRsaKey(&rsaKey);
  50763. }
  50764. /* test LENGTH_ONLY_E case */
  50765. keyDerSz = 0;
  50766. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50767. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50768. ExpectIntGT(keyDerSz, 0);
  50769. /* bad args: DecodedCert NULL */
  50770. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50771. /* bad args: output key buff size */
  50772. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50773. /* bad args: zero size output key buffer */
  50774. keyDerSz = 0;
  50775. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50777. wc_FreeDecodedCert(&decoded);
  50778. /* Certificate Request Tests */
  50779. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50780. {
  50781. XMEMSET(certBuf, 0, sizeof(certBuf));
  50782. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  50783. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  50784. if (fp != XBADFILE) {
  50785. XFCLOSE(fp);
  50786. }
  50787. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  50788. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  50789. /* good test case - RSA DER certificate request */
  50790. keyDerSz = sizeof(keyDer);
  50791. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50792. 0);
  50793. ExpectIntGT(keyDerSz, 0);
  50794. /* sanity check, verify we can import DER public key */
  50795. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50796. ExpectIntEQ(ret, 0);
  50797. idx = 0;
  50798. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50799. if (ret == 0) {
  50800. wc_FreeRsaKey(&rsaKey);
  50801. }
  50802. wc_FreeDecodedCert(&decoded);
  50803. }
  50804. #endif /* WOLFSSL_CERT_REQ */
  50805. #endif /* NO_RSA */
  50806. #ifdef HAVE_ECC
  50807. #ifndef USE_CERT_BUFFERS_256
  50808. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  50809. XBADFILE);
  50810. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  50811. if (fp2 != XBADFILE) {
  50812. XFCLOSE(fp2);
  50813. }
  50814. #endif
  50815. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  50816. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50817. /* good test case - ECC */
  50818. XMEMSET(keyDer, 0, sizeof(keyDer));
  50819. keyDerSz = sizeof(keyDer);
  50820. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50821. ExpectIntGT(keyDerSz, 0);
  50822. /* sanity check, verify we can import DER public key */
  50823. ret = wc_ecc_init(&eccKey);
  50824. ExpectIntEQ(ret, 0);
  50825. idx = 0; /* reset idx to 0, used above in RSA case */
  50826. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  50827. if (ret == 0) {
  50828. wc_ecc_free(&eccKey);
  50829. }
  50830. /* test LENGTH_ONLY_E case */
  50831. keyDerSz = 0;
  50832. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50833. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50834. ExpectIntGT(keyDerSz, 0);
  50835. wc_FreeDecodedCert(&decoded);
  50836. #endif
  50837. #endif /* !NO_RSA || HAVE_ECC */
  50838. return EXPECT_RESULT();
  50839. }
  50840. static int test_wc_CheckCertSigPubKey(void)
  50841. {
  50842. EXPECT_DECLS;
  50843. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50844. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  50845. int ret = 0;
  50846. const char* ca_cert = "./certs/ca-cert.pem";
  50847. byte* cert_buf = NULL;
  50848. size_t cert_sz = 0;
  50849. byte* cert_der = NULL;
  50850. word32 cert_dersz = 0;
  50851. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50852. word32 keyDerSz = (word32)sizeof(keyDer);
  50853. DecodedCert decoded;
  50854. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50855. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  50856. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50857. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50858. (int)cert_dersz, CERT_TYPE), 0);
  50859. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  50860. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50861. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50862. ExpectIntGT(keyDerSz, 0);
  50863. /* Good test case. */
  50864. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50865. keyDerSz, RSAk), 0);
  50866. /* No certificate. */
  50867. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  50868. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50869. /* Bad cert size. */
  50870. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  50871. RSAk), 0);
  50872. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  50873. /* No public key. */
  50874. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  50875. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  50876. /* Bad public key size. */
  50877. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  50878. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50879. /* Wrong aglo. */
  50880. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50881. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  50882. wc_FreeDecodedCert(&decoded);
  50883. if (cert_der != NULL)
  50884. free(cert_der);
  50885. if (cert_buf != NULL)
  50886. free(cert_buf);
  50887. #endif
  50888. return EXPECT_RESULT();
  50889. }
  50890. static int test_wolfSSL_certs(void)
  50891. {
  50892. EXPECT_DECLS;
  50893. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50894. !defined(NO_RSA)
  50895. X509* x509ext = NULL;
  50896. X509* x509 = NULL;
  50897. #ifdef OPENSSL_ALL
  50898. WOLFSSL_X509_EXTENSION* ext = NULL;
  50899. ASN1_OBJECT* obj = NULL;
  50900. #endif
  50901. WOLFSSL* ssl = NULL;
  50902. WOLFSSL_CTX* ctx = NULL;
  50903. STACK_OF(ASN1_OBJECT)* sk = NULL;
  50904. ASN1_STRING* asn1_str = NULL;
  50905. AUTHORITY_KEYID* akey = NULL;
  50906. BASIC_CONSTRAINTS* bc = NULL;
  50907. int crit = 0;
  50908. #ifndef NO_WOLFSSL_SERVER
  50909. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  50910. #else
  50911. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  50912. #endif
  50913. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  50914. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50915. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  50916. #if !defined(NO_CHECK_PRIVATE_KEY)
  50917. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50918. #endif
  50919. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50920. #if !defined(NO_CHECK_PRIVATE_KEY)
  50921. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  50922. #endif
  50923. ExpectNotNull(ssl = SSL_new(ctx));
  50924. /* Invalid parameters. */
  50925. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50927. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50928. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50929. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  50930. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50931. #if !defined(NO_CHECK_PRIVATE_KEY)
  50932. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50933. #endif
  50934. #ifdef HAVE_PK_CALLBACKS
  50935. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  50936. #endif /* HAVE_PK_CALLBACKS */
  50937. /* Invalid parameters. */
  50938. ExpectNotNull(x509 = wolfSSL_X509_new());
  50939. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50940. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50941. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50942. /* No data in certificate. */
  50943. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50944. wolfSSL_X509_free(x509);
  50945. x509 = NULL;
  50946. /* create and use x509 */
  50947. #ifdef OPENSSL_ALL
  50948. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50949. WOLFSSL_FILETYPE_PEM));
  50950. #endif
  50951. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  50952. WOLFSSL_FILETYPE_PEM));
  50953. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  50954. #if !defined(NO_CHECK_PRIVATE_KEY)
  50955. /* with loading in a new cert the check on private key should now fail */
  50956. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50957. #endif
  50958. #if defined(USE_CERT_BUFFERS_2048)
  50959. /* Invalid parameters. */
  50960. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50961. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50962. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  50963. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50964. /* No data. */
  50965. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50966. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50967. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50968. (unsigned char*)server_cert_der_2048,
  50969. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  50970. #endif
  50971. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  50972. /************* Get Digest of Certificate ******************/
  50973. {
  50974. byte digest[64]; /* max digest size */
  50975. word32 digestSz;
  50976. XMEMSET(digest, 0, sizeof(digest));
  50977. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  50978. WOLFSSL_SUCCESS);
  50979. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  50980. WOLFSSL_SUCCESS);
  50981. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  50982. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50983. }
  50984. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  50985. /* test and checkout X509 extensions */
  50986. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  50987. NID_basic_constraints, &crit, NULL));
  50988. ExpectIntEQ(crit, 0);
  50989. #ifdef OPENSSL_ALL
  50990. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  50991. X509_EXTENSION_free(ext);
  50992. ext = NULL;
  50993. ExpectNotNull(ext = X509_EXTENSION_new());
  50994. X509_EXTENSION_set_critical(ext, 1);
  50995. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  50996. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  50997. ASN1_OBJECT_free(obj);
  50998. obj = NULL;
  50999. X509_EXTENSION_free(ext);
  51000. ext = NULL;
  51001. ExpectNotNull(ext = X509_EXTENSION_new());
  51002. X509_EXTENSION_set_critical(ext, 0);
  51003. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51004. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  51005. NULL);
  51006. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  51007. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  51008. * and X509_get_ext_d2i has created new */
  51009. asn1_str = NULL;
  51010. X509_EXTENSION_free(ext);
  51011. ext = NULL;
  51012. #endif
  51013. BASIC_CONSTRAINTS_free(bc);
  51014. bc = NULL;
  51015. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  51016. NID_key_usage, &crit, NULL));
  51017. ExpectIntEQ(crit, 1);
  51018. ExpectIntEQ(asn1_str->type, NID_key_usage);
  51019. #ifdef OPENSSL_ALL
  51020. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  51021. X509_EXTENSION_free(ext);
  51022. ext = NULL;
  51023. #endif
  51024. ASN1_STRING_free(asn1_str);
  51025. asn1_str = NULL;
  51026. #ifdef OPENSSL_ALL
  51027. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  51028. NID_ext_key_usage, &crit, NULL));
  51029. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  51030. X509_EXTENSION_free(ext);
  51031. ext = NULL;
  51032. EXTENDED_KEY_USAGE_free(sk);
  51033. sk = NULL;
  51034. #else
  51035. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  51036. &crit, NULL);
  51037. ExpectNull(sk);
  51038. #endif
  51039. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  51040. NID_authority_key_identifier, &crit, NULL));
  51041. #ifdef OPENSSL_ALL
  51042. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  51043. akey));
  51044. X509_EXTENSION_free(ext);
  51045. ext = NULL;
  51046. #endif
  51047. wolfSSL_AUTHORITY_KEYID_free(akey);
  51048. akey = NULL;
  51049. /* NID not yet supported */
  51050. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51051. NID_private_key_usage_period, &crit, NULL));
  51052. ExpectIntEQ(crit, -1);
  51053. sk_ASN1_OBJECT_free(sk);
  51054. sk = NULL;
  51055. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  51056. NID_subject_alt_name, &crit, NULL));
  51057. {
  51058. int i;
  51059. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  51060. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  51061. ExpectIntEQ(gen->type, GEN_DNS);
  51062. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  51063. }
  51064. }
  51065. sk_GENERAL_NAME_free(sk);
  51066. sk = NULL;
  51067. /* NID not yet supported */
  51068. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51069. NID_issuer_alt_name, &crit, NULL));
  51070. ExpectIntEQ(crit, -1);
  51071. sk_ASN1_OBJECT_free(sk);
  51072. sk = NULL;
  51073. /* NID not yet supported */
  51074. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51075. NID_info_access, &crit, NULL));
  51076. sk_ASN1_OBJECT_free(sk);
  51077. sk = NULL;
  51078. /* NID not yet supported */
  51079. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51080. NID_sinfo_access, &crit, NULL));
  51081. ExpectIntEQ(crit, -1);
  51082. sk_ASN1_OBJECT_free(sk);
  51083. sk = NULL;
  51084. /* NID not yet supported */
  51085. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51086. NID_name_constraints, &crit, NULL));
  51087. ExpectIntEQ(crit, -1);
  51088. sk_ASN1_OBJECT_free(sk);
  51089. sk = NULL;
  51090. /* no cert policy set */
  51091. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51092. NID_certificate_policies, &crit, NULL));
  51093. sk_ASN1_OBJECT_free(sk);
  51094. sk = NULL;
  51095. /* NID not yet supported */
  51096. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51097. NID_policy_mappings, &crit, NULL));
  51098. ExpectIntEQ(crit, -1);
  51099. sk_ASN1_OBJECT_free(sk);
  51100. sk = NULL;
  51101. /* NID not yet supported */
  51102. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51103. NID_policy_constraints, &crit, NULL));
  51104. ExpectIntEQ(crit, -1);
  51105. sk_ASN1_OBJECT_free(sk);
  51106. sk = NULL;
  51107. /* NID not yet supported */
  51108. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51109. NID_inhibit_any_policy, &crit, NULL));
  51110. ExpectIntEQ(crit, -1);
  51111. sk_ASN1_OBJECT_free(sk);
  51112. sk = NULL;
  51113. /* NID not yet supported */
  51114. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51115. NID_tlsfeature, &crit, NULL));
  51116. ExpectIntEQ(crit, -1);
  51117. sk_ASN1_OBJECT_free(sk);
  51118. sk = NULL;
  51119. /* test invalid cases */
  51120. crit = 0;
  51121. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  51122. NULL));
  51123. ExpectIntEQ(crit, -1);
  51124. /* NULL passed for criticality. */
  51125. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  51126. NID_tlsfeature, NULL, NULL));
  51127. ExpectIntEQ(SSL_get_hit(ssl), 0);
  51128. #ifdef OPENSSL_ALL
  51129. X509_free(x509);
  51130. #endif
  51131. X509_free(x509ext);
  51132. SSL_free(ssl);
  51133. SSL_CTX_free(ctx);
  51134. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  51135. return EXPECT_RESULT();
  51136. }
  51137. static int test_wolfSSL_X509_check_private_key(void)
  51138. {
  51139. EXPECT_DECLS;
  51140. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51141. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  51142. X509* x509 = NULL;
  51143. EVP_PKEY* pkey = NULL;
  51144. const byte* key;
  51145. /* Check with correct key */
  51146. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  51147. SSL_FILETYPE_PEM)));
  51148. key = client_key_der_2048;
  51149. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51150. (long)sizeof_client_key_der_2048));
  51151. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  51152. EVP_PKEY_free(pkey);
  51153. pkey = NULL;
  51154. /* Check with wrong key */
  51155. key = server_key_der_2048;
  51156. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51157. (long)sizeof_server_key_der_2048));
  51158. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  51159. /* test for incorrect parameter */
  51160. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  51161. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  51162. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  51163. EVP_PKEY_free(pkey);
  51164. X509_free(x509);
  51165. #endif
  51166. return EXPECT_RESULT();
  51167. }
  51168. static int test_wolfSSL_private_keys(void)
  51169. {
  51170. EXPECT_DECLS;
  51171. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51172. !defined(NO_FILESYSTEM)
  51173. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  51174. WOLFSSL* ssl = NULL;
  51175. WOLFSSL_CTX* ctx = NULL;
  51176. EVP_PKEY* pkey = NULL;
  51177. OpenSSL_add_all_digests();
  51178. OpenSSL_add_all_algorithms();
  51179. #ifndef NO_RSA
  51180. #ifndef NO_WOLFSSL_SERVER
  51181. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51182. #else
  51183. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51184. #endif
  51185. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  51186. WOLFSSL_FILETYPE_PEM));
  51187. /* Have to load a cert before you can check the private key against that
  51188. * certificates public key! */
  51189. #if !defined(NO_CHECK_PRIVATE_KEY)
  51190. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51191. #endif
  51192. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  51193. WOLFSSL_FILETYPE_PEM));
  51194. #if !defined(NO_CHECK_PRIVATE_KEY)
  51195. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51196. #endif
  51197. ExpectNotNull(ssl = SSL_new(ctx));
  51198. #if !defined(NO_CHECK_PRIVATE_KEY)
  51199. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51200. #endif
  51201. /* Invalid parameters. */
  51202. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  51203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51204. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  51205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51206. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  51207. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51208. #ifdef USE_CERT_BUFFERS_2048
  51209. {
  51210. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51211. unsigned char buf[FOURK_BUF];
  51212. word32 bufSz;
  51213. /* Invalid parameters. */
  51214. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51215. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51216. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  51217. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51218. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51219. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51220. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  51221. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51222. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51223. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51224. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  51225. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51226. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  51227. (unsigned char*)client_key_der_2048,
  51228. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  51229. #if !defined(NO_CHECK_PRIVATE_KEY)
  51230. /* Should mismatch now that a different private key loaded */
  51231. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51232. #endif
  51233. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  51234. (unsigned char*)server_key,
  51235. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  51236. #if !defined(NO_CHECK_PRIVATE_KEY)
  51237. /* After loading back in DER format of original key, should match */
  51238. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51239. #endif
  51240. /* test loading private key to the WOLFSSL_CTX */
  51241. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  51242. (unsigned char*)client_key_der_2048,
  51243. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  51244. #if !defined(NO_CHECK_PRIVATE_KEY)
  51245. /* Should mismatch now that a different private key loaded */
  51246. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51247. #endif
  51248. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  51249. (unsigned char*)server_key,
  51250. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  51251. #if !defined(NO_CHECK_PRIVATE_KEY)
  51252. /* After loading back in DER format of original key, should match */
  51253. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51254. #endif
  51255. /* Invalid parameters. */
  51256. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  51257. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51258. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51259. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51260. /* pkey is empty - no key data to use. */
  51261. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  51262. wolfSSL_EVP_PKEY_free(pkey);
  51263. pkey = NULL;
  51264. /* set PKEY and test again */
  51265. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51266. &server_key, (long)sizeof_server_key_der_2048));
  51267. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51268. /* reuse PKEY structure and test
  51269. * this should be checked with a memory management sanity checker */
  51270. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  51271. server_key = (const unsigned char*)server_key_der_2048;
  51272. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51273. &server_key, (long)sizeof_server_key_der_2048));
  51274. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51275. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  51276. bufSz = FOURK_BUF;
  51277. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  51278. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  51279. RSAk, NULL, 0)), 0);
  51280. server_key = (const unsigned char*)buf;
  51281. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51282. (long)bufSz));
  51283. }
  51284. #endif
  51285. EVP_PKEY_free(pkey);
  51286. pkey = NULL;
  51287. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  51288. ssl = NULL;
  51289. SSL_CTX_free(ctx);
  51290. ctx = NULL;
  51291. #endif /* end of RSA private key match tests */
  51292. #ifdef HAVE_ECC
  51293. #ifndef NO_WOLFSSL_SERVER
  51294. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51295. #else
  51296. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51297. #endif
  51298. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  51299. WOLFSSL_FILETYPE_PEM));
  51300. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  51301. WOLFSSL_FILETYPE_PEM));
  51302. ExpectNotNull(ssl = SSL_new(ctx));
  51303. #if !defined(NO_CHECK_PRIVATE_KEY)
  51304. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51305. #endif
  51306. SSL_free(ssl);
  51307. ssl = NULL;
  51308. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  51309. WOLFSSL_FILETYPE_PEM));
  51310. ExpectNotNull(ssl = SSL_new(ctx));
  51311. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  51312. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51313. #endif
  51314. SSL_free(ssl);
  51315. ssl = NULL;
  51316. SSL_CTX_free(ctx);
  51317. ctx = NULL;
  51318. #endif /* end of ECC private key match tests */
  51319. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  51320. #ifndef NO_WOLFSSL_SERVER
  51321. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51322. #else
  51323. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51324. #endif
  51325. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  51326. WOLFSSL_FILETYPE_PEM));
  51327. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  51328. WOLFSSL_FILETYPE_PEM));
  51329. ExpectNotNull(ssl = SSL_new(ctx));
  51330. #if !defined(NO_CHECK_PRIVATE_KEY)
  51331. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51332. #endif
  51333. SSL_free(ssl);
  51334. ssl = NULL;
  51335. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  51336. WOLFSSL_FILETYPE_PEM));
  51337. ExpectNotNull(ssl = SSL_new(ctx));
  51338. #if !defined(NO_CHECK_PRIVATE_KEY)
  51339. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51340. #endif
  51341. SSL_free(ssl);
  51342. ssl = NULL;
  51343. SSL_CTX_free(ctx);
  51344. ctx = NULL;
  51345. #endif /* end of Ed25519 private key match tests */
  51346. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  51347. #ifndef NO_WOLFSSL_SERVER
  51348. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51349. #else
  51350. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51351. #endif
  51352. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  51353. WOLFSSL_FILETYPE_PEM));
  51354. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  51355. WOLFSSL_FILETYPE_PEM));
  51356. ExpectNotNull(ssl = SSL_new(ctx));
  51357. #if !defined(NO_CHECK_PRIVATE_KEY)
  51358. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51359. #endif
  51360. SSL_free(ssl);
  51361. ssl = NULL;
  51362. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  51363. WOLFSSL_FILETYPE_PEM));
  51364. ExpectNotNull(ssl = SSL_new(ctx));
  51365. #if !defined(NO_CHECK_PRIVATE_KEY)
  51366. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51367. #endif
  51368. SSL_free(ssl);
  51369. ssl = NULL;
  51370. SSL_CTX_free(ctx);
  51371. ctx = NULL;
  51372. #endif /* end of Ed448 private key match tests */
  51373. EVP_cleanup();
  51374. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  51375. CONF_modules_free();
  51376. ENGINE_cleanup();
  51377. CONF_modules_unload();
  51378. (void)ssl;
  51379. (void)ctx;
  51380. (void)pkey;
  51381. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  51382. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51383. return EXPECT_RESULT();
  51384. }
  51385. static int test_wolfSSL_PEM_def_callback(void)
  51386. {
  51387. EXPECT_DECLS;
  51388. #ifdef OPENSSL_EXTRA
  51389. char buf[10];
  51390. const char* defpwd = "DEF PWD";
  51391. int defpwdLen = (int)XSTRLEN(defpwd);
  51392. int smallLen = 1;
  51393. /* Bad parameters. */
  51394. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  51395. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  51396. 0);
  51397. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  51398. XMEMSET(buf, 0, sizeof(buf));
  51399. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  51400. defpwdLen);
  51401. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  51402. ExpectIntEQ(buf[defpwdLen], 0);
  51403. /* Size of buffer is smaller than default password. */
  51404. XMEMSET(buf, 0, sizeof(buf));
  51405. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  51406. smallLen);
  51407. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  51408. ExpectIntEQ(buf[smallLen], 0);
  51409. #endif /* OPENSSL_EXTRA */
  51410. return EXPECT_RESULT();
  51411. }
  51412. static int test_wolfSSL_PEM_read_PrivateKey(void)
  51413. {
  51414. EXPECT_DECLS;
  51415. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  51416. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  51417. XFILE file = XBADFILE;
  51418. #if !defined(NO_RSA)
  51419. const char* fname_rsa = "./certs/server-key.pem";
  51420. RSA* rsa = NULL;
  51421. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  51422. unsigned char* sig = NULL;
  51423. size_t sigLen = 0;
  51424. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  51425. size_t tbsLen = sizeof(tbs);
  51426. #endif
  51427. #if !defined(NO_DSA)
  51428. const char* fname_dsa = "./certs/dsa2048.pem";
  51429. #endif
  51430. #if defined(HAVE_ECC)
  51431. const char* fname_ec = "./certs/ecc-key.pem";
  51432. #endif
  51433. #if !defined(NO_DH)
  51434. const char* fname_dh = "./certs/dh-priv-2048.pem";
  51435. #endif
  51436. EVP_PKEY* pkey = NULL;
  51437. /* Check error case. */
  51438. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  51439. /* not a PEM key. */
  51440. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51441. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51442. if (file != XBADFILE)
  51443. XFCLOSE(file);
  51444. file = XBADFILE;
  51445. #ifndef NO_RSA
  51446. /* Read in an RSA key. */
  51447. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  51448. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51449. if (file != XBADFILE)
  51450. XFCLOSE(file);
  51451. file = XBADFILE;
  51452. /* Make sure the key is usable by signing some data with it. */
  51453. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  51454. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  51455. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  51456. DYNAMIC_TYPE_TMP_BUFFER));
  51457. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  51458. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  51459. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  51460. WOLFSSL_SUCCESS);
  51461. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51462. EVP_PKEY_CTX_free(ctx);
  51463. EVP_PKEY_free(pkey);
  51464. pkey = NULL;
  51465. #endif
  51466. #ifndef NO_DSA
  51467. /* Read in a DSA key. */
  51468. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  51469. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  51470. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51471. EVP_PKEY_free(pkey);
  51472. pkey = NULL;
  51473. #else
  51474. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51475. #endif
  51476. if (file != XBADFILE)
  51477. XFCLOSE(file);
  51478. file = XBADFILE;
  51479. #endif
  51480. #ifdef HAVE_ECC
  51481. /* Read in an EC key. */
  51482. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  51483. ExpectNotNull(pkey = EVP_PKEY_new());
  51484. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  51485. if (file != XBADFILE)
  51486. XFCLOSE(file);
  51487. file = XBADFILE;
  51488. EVP_PKEY_free(pkey);
  51489. pkey = NULL;
  51490. #endif
  51491. #ifndef NO_DH
  51492. /* Read in a DH key. */
  51493. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  51494. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51495. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51496. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51497. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51498. EVP_PKEY_free(pkey);
  51499. pkey = NULL;
  51500. #else
  51501. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51502. #endif
  51503. if (file != XBADFILE)
  51504. XFCLOSE(file);
  51505. file = XBADFILE;
  51506. #endif
  51507. #endif
  51508. return EXPECT_RESULT();
  51509. }
  51510. static int test_wolfSSL_PEM_read_PUBKEY(void)
  51511. {
  51512. EXPECT_DECLS;
  51513. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  51514. && !defined(NO_FILESYSTEM)
  51515. XFILE file = XBADFILE;
  51516. const char* fname = "./certs/client-keyPub.pem";
  51517. EVP_PKEY* pkey = NULL;
  51518. /* Check error case. */
  51519. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  51520. /* Read in an RSA key. */
  51521. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51522. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  51523. EVP_PKEY_free(pkey);
  51524. pkey = NULL;
  51525. if (file != XBADFILE)
  51526. XFCLOSE(file);
  51527. file = XBADFILE;
  51528. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51529. ExpectNotNull(pkey = EVP_PKEY_new());
  51530. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  51531. EVP_PKEY_free(pkey);
  51532. if (file != XBADFILE)
  51533. XFCLOSE(file);
  51534. #endif
  51535. return EXPECT_RESULT();
  51536. }
  51537. /* test loading RSA key using BIO */
  51538. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  51539. {
  51540. EXPECT_DECLS;
  51541. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51542. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  51543. !defined(NO_BIO)
  51544. BIO* bio = NULL;
  51545. XFILE file = XBADFILE;
  51546. const char* fname = "./certs/server-key.pem";
  51547. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  51548. EVP_PKEY* pkey = NULL;
  51549. size_t sz = 0;
  51550. byte* buf = NULL;
  51551. EVP_PKEY* pkey2 = NULL;
  51552. EVP_PKEY* pkey3 = NULL;
  51553. RSA* rsa_key = NULL;
  51554. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51555. unsigned char extra[10];
  51556. int i;
  51557. BIO* pub_bio = NULL;
  51558. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51559. #endif
  51560. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51561. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51562. ExpectIntGT(sz = XFTELL(file), 0);
  51563. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51564. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51565. if (buf != NULL) {
  51566. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51567. }
  51568. if (file != XBADFILE) {
  51569. XFCLOSE(file);
  51570. file = XBADFILE;
  51571. }
  51572. /* Test using BIO new mem and loading PEM private key */
  51573. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51574. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51575. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51576. buf = NULL;
  51577. BIO_free(bio);
  51578. bio = NULL;
  51579. /* New empty EVP_PKEY */
  51580. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51581. if (pkey2 != NULL) {
  51582. pkey2->type = EVP_PKEY_RSA;
  51583. }
  51584. /* Test parameter copy */
  51585. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  51586. EVP_PKEY_free(pkey2);
  51587. EVP_PKEY_free(pkey);
  51588. pkey = NULL;
  51589. /* Qt unit test case : rsa pkcs8 key */
  51590. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  51591. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51592. ExpectIntGT(sz = XFTELL(file), 0);
  51593. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51594. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51595. if (buf) {
  51596. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51597. }
  51598. if (file != XBADFILE) {
  51599. XFCLOSE(file);
  51600. file = XBADFILE;
  51601. }
  51602. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51603. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51604. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51605. buf = NULL;
  51606. BIO_free(bio);
  51607. bio = NULL;
  51608. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51609. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  51610. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  51611. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51612. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51613. #else
  51614. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51615. #endif
  51616. RSA_free(rsa_key);
  51617. EVP_PKEY_free(pkey3);
  51618. EVP_PKEY_free(pkey);
  51619. pkey = NULL;
  51620. pkey2 = NULL;
  51621. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51622. #define BIO_PEM_TEST_CHAR 'a'
  51623. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  51624. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51625. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51626. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51627. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51628. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  51629. (long)sizeof_server_key_der_2048));
  51630. ExpectNull(pkey);
  51631. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51632. (long)sizeof_server_key_der_2048));
  51633. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  51634. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51635. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  51636. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51637. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51638. WOLFSSL_SUCCESS);
  51639. ExpectIntGT(BIO_pending(bio), 0);
  51640. ExpectIntEQ(BIO_pending(bio), 1679);
  51641. /* Check if the pubkey API writes only the public key */
  51642. #ifdef WOLFSSL_KEY_GEN
  51643. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51644. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51645. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51646. ExpectIntGT(BIO_pending(pub_bio), 0);
  51647. /* Previously both the private key and the pubkey calls would write
  51648. * out the private key and the PEM header was the only difference.
  51649. * The public PEM should be significantly shorter than the
  51650. * private key versison. */
  51651. ExpectIntEQ(BIO_pending(pub_bio), 451);
  51652. #else
  51653. /* Not supported. */
  51654. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  51655. #endif
  51656. /* test creating new EVP_PKEY with good args */
  51657. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51658. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51659. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51660. pkey->pkey_sz), 0);
  51661. }
  51662. /* test of reuse of EVP_PKEY */
  51663. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51664. ExpectIntEQ(BIO_pending(bio), 0);
  51665. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51666. SSL_SUCCESS);
  51667. /* add 10 extra bytes after PEM */
  51668. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  51669. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51670. ExpectNotNull(pkey);
  51671. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51672. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51673. pkey->pkey_sz), 0);
  51674. }
  51675. /* check 10 extra bytes still there */
  51676. ExpectIntEQ(BIO_pending(bio), 10);
  51677. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  51678. for (i = 0; i < 10; i++) {
  51679. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  51680. }
  51681. BIO_free(pub_bio);
  51682. BIO_free(bio);
  51683. bio = NULL;
  51684. EVP_PKEY_free(pkey);
  51685. pkey = NULL;
  51686. EVP_PKEY_free(pkey2);
  51687. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  51688. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  51689. * !NO_FILESYSTEM && !NO_BIO */
  51690. return EXPECT_RESULT();
  51691. }
  51692. /* test loading ECC key using BIO */
  51693. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  51694. {
  51695. EXPECT_DECLS;
  51696. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  51697. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51698. BIO* bio = NULL;
  51699. EVP_PKEY* pkey = NULL;
  51700. XFILE file = XBADFILE;
  51701. const char* fname = "./certs/ecc-key.pem";
  51702. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  51703. size_t sz = 0;
  51704. byte* buf = NULL;
  51705. EVP_PKEY* pkey2 = NULL;
  51706. EVP_PKEY* pkey3 = NULL;
  51707. EC_KEY* ec_key = NULL;
  51708. int nid = 0;
  51709. BIO* pub_bio = NULL;
  51710. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51711. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51712. ExpectIntGT(sz = XFTELL(file), 0);
  51713. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51714. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51715. if (buf) {
  51716. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51717. }
  51718. if (file != XBADFILE) {
  51719. XFCLOSE(file);
  51720. file = XBADFILE;
  51721. }
  51722. /* Test using BIO new mem and loading PEM private key */
  51723. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51724. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51725. BIO_free(bio);
  51726. bio = NULL;
  51727. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51728. buf = NULL;
  51729. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51730. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51731. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51732. WOLFSSL_SUCCESS);
  51733. ExpectIntGT(BIO_pending(bio), 0);
  51734. /* No parameters. */
  51735. ExpectIntEQ(BIO_pending(bio), 227);
  51736. /* Check if the pubkey API writes only the public key */
  51737. #ifdef WOLFSSL_KEY_GEN
  51738. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51739. ExpectIntGT(BIO_pending(pub_bio), 0);
  51740. /* Previously both the private key and the pubkey calls would write
  51741. * out the private key and the PEM header was the only difference.
  51742. * The public PEM should be significantly shorter than the
  51743. * private key versison. */
  51744. ExpectIntEQ(BIO_pending(pub_bio), 178);
  51745. #endif
  51746. BIO_free(pub_bio);
  51747. BIO_free(bio);
  51748. bio = NULL;
  51749. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51750. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51751. if (pkey2 != NULL) {
  51752. pkey2->type = EVP_PKEY_EC;
  51753. }
  51754. /* Test parameter copy */
  51755. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  51756. /* Qt unit test case 1*/
  51757. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51758. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51759. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51760. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51761. #else
  51762. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51763. #endif
  51764. /* Test default digest */
  51765. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  51766. ExpectIntEQ(nid, NID_sha256);
  51767. EC_KEY_free(ec_key);
  51768. ec_key = NULL;
  51769. EVP_PKEY_free(pkey3);
  51770. pkey3 = NULL;
  51771. EVP_PKEY_free(pkey2);
  51772. pkey2 = NULL;
  51773. EVP_PKEY_free(pkey);
  51774. pkey = NULL;
  51775. /* Qt unit test case ec pkcs8 key */
  51776. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  51777. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51778. ExpectIntGT(sz = XFTELL(file), 0);
  51779. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51780. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51781. if (buf) {
  51782. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51783. }
  51784. if (file != XBADFILE) {
  51785. XFCLOSE(file);
  51786. file = XBADFILE;
  51787. }
  51788. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51789. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51790. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51791. buf = NULL;
  51792. BIO_free(bio);
  51793. bio = NULL;
  51794. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51795. /* Qt unit test case */
  51796. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51797. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51798. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51799. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51800. #else
  51801. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51802. #endif
  51803. EC_KEY_free(ec_key);
  51804. EVP_PKEY_free(pkey3);
  51805. EVP_PKEY_free(pkey);
  51806. pkey = NULL;
  51807. #endif
  51808. return EXPECT_RESULT();
  51809. }
  51810. /* test loading DSA key using BIO */
  51811. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  51812. {
  51813. EXPECT_DECLS;
  51814. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  51815. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51816. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  51817. BIO* bio = NULL;
  51818. EVP_PKEY* pkey = NULL;
  51819. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  51820. /* Private DSA EVP_PKEY */
  51821. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51822. NULL));
  51823. BIO_free(bio);
  51824. bio = NULL;
  51825. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51826. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51827. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51828. NULL), 0);
  51829. #endif
  51830. #ifdef WOLFSSL_KEY_GEN
  51831. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  51832. ExpectIntEQ(BIO_pending(bio), 1178);
  51833. BIO_reset(bio);
  51834. #endif
  51835. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51836. 1);
  51837. ExpectIntEQ(BIO_pending(bio), 1196);
  51838. BIO_free(bio);
  51839. bio = NULL;
  51840. EVP_PKEY_free(pkey);
  51841. pkey = NULL;
  51842. #endif
  51843. #endif
  51844. return EXPECT_RESULT();
  51845. }
  51846. /* test loading DH key using BIO */
  51847. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  51848. {
  51849. EXPECT_DECLS;
  51850. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  51851. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51852. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51853. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51854. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51855. BIO* bio = NULL;
  51856. EVP_PKEY* pkey = NULL;
  51857. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  51858. /* Private DH EVP_PKEY */
  51859. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51860. NULL));
  51861. BIO_free(bio);
  51862. bio = NULL;
  51863. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51864. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51865. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51866. NULL), 0);
  51867. #endif
  51868. #ifdef WOLFSSL_KEY_GEN
  51869. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  51870. #endif
  51871. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51872. 1);
  51873. ExpectIntEQ(BIO_pending(bio), 806);
  51874. BIO_free(bio);
  51875. bio = NULL;
  51876. EVP_PKEY_free(pkey);
  51877. pkey = NULL;
  51878. #endif
  51879. #endif
  51880. return EXPECT_RESULT();
  51881. }
  51882. static int test_wolfSSL_PEM_PrivateKey(void)
  51883. {
  51884. EXPECT_DECLS;
  51885. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51886. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  51887. #ifndef NO_BIO
  51888. BIO* bio = NULL;
  51889. #endif
  51890. EVP_PKEY* pkey = NULL;
  51891. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51892. #ifndef NO_BIO
  51893. /* test creating new EVP_PKEY with bad arg */
  51894. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  51895. /* Test bad EVP_PKEY type. */
  51896. /* New HMAC EVP_PKEY */
  51897. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  51898. ExpectNotNull(pkey = EVP_PKEY_new());
  51899. if (pkey != NULL) {
  51900. pkey->type = EVP_PKEY_HMAC;
  51901. }
  51902. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51903. 0);
  51904. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51905. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51906. NULL), 0);
  51907. #endif
  51908. #ifdef WOLFSSL_KEY_GEN
  51909. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51910. #endif
  51911. EVP_PKEY_free(pkey);
  51912. pkey = NULL;
  51913. BIO_free(bio);
  51914. bio = NULL;
  51915. /* key is DES encrypted */
  51916. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  51917. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  51918. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51919. {
  51920. XFILE f = XBADFILE;
  51921. wc_pem_password_cb* passwd_cb = NULL;
  51922. void* passwd_cb_userdata;
  51923. SSL_CTX* ctx = NULL;
  51924. char passwd[] = "bad password";
  51925. #ifndef WOLFSSL_NO_TLS12
  51926. #ifndef NO_WOLFSSL_SERVER
  51927. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51928. #else
  51929. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51930. #endif
  51931. #else
  51932. #ifndef NO_WOLFSSL_SERVER
  51933. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51934. #else
  51935. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51936. #endif
  51937. #endif
  51938. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51939. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  51940. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  51941. ExpectNull(passwd_cb_userdata =
  51942. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  51943. /* fail case with password call back */
  51944. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51945. (void*)passwd));
  51946. BIO_free(bio);
  51947. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51948. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51949. (void*)passwd));
  51950. BIO_free(bio);
  51951. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  51952. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  51953. if ((bio == NULL) && (f != XBADFILE)) {
  51954. XFCLOSE(f);
  51955. }
  51956. /* use callback that works */
  51957. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51958. (void*)"yassl123"));
  51959. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51960. EVP_PKEY_free(pkey);
  51961. pkey = NULL;
  51962. BIO_free(bio);
  51963. bio = NULL;
  51964. SSL_CTX_free(ctx);
  51965. }
  51966. #endif /* !defined(NO_DES3) */
  51967. #endif /* !NO_BIO */
  51968. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  51969. {
  51970. unsigned char buf[2048];
  51971. size_t bytes = 0;
  51972. XFILE f = XBADFILE;
  51973. SSL_CTX* ctx = NULL;
  51974. #ifndef WOLFSSL_NO_TLS12
  51975. #ifndef NO_WOLFSSL_SERVER
  51976. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51977. #else
  51978. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51979. #endif
  51980. #else
  51981. #ifndef NO_WOLFSSL_SERVER
  51982. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51983. #else
  51984. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51985. #endif
  51986. #endif
  51987. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51988. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  51989. if (f != XBADFILE)
  51990. XFCLOSE(f);
  51991. server_key = buf;
  51992. pkey = NULL;
  51993. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  51994. ExpectNull(pkey);
  51995. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  51996. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51997. EVP_PKEY_free(pkey);
  51998. pkey = NULL;
  51999. SSL_CTX_free(ctx);
  52000. server_key = NULL;
  52001. }
  52002. #endif
  52003. #ifndef NO_BIO
  52004. (void)bio;
  52005. #endif
  52006. (void)pkey;
  52007. (void)server_key;
  52008. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  52009. return EXPECT_RESULT();
  52010. }
  52011. static int test_wolfSSL_PEM_file_RSAKey(void)
  52012. {
  52013. EXPECT_DECLS;
  52014. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52015. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52016. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52017. RSA* rsa = NULL;
  52018. XFILE fp = XBADFILE;
  52019. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  52020. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  52021. if (fp != XBADFILE)
  52022. XFCLOSE(fp);
  52023. ExpectIntEQ(RSA_size(rsa), 256);
  52024. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52025. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52026. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  52027. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52028. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52029. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  52030. RSA_free(rsa);
  52031. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52032. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52033. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52034. return EXPECT_RESULT();
  52035. }
  52036. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  52037. {
  52038. EXPECT_DECLS;
  52039. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  52040. !defined(NO_FILESYSTEM) && \
  52041. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  52042. RSA* rsa = NULL;
  52043. XFILE f = NULL;
  52044. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  52045. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52046. ExpectIntEQ(RSA_size(rsa), 256);
  52047. if (f != XBADFILE) {
  52048. XFCLOSE(f);
  52049. f = XBADFILE;
  52050. }
  52051. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  52052. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52053. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  52054. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52055. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  52056. WOLFSSL_SUCCESS);
  52057. RSA_free(rsa);
  52058. #ifdef HAVE_ECC
  52059. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  52060. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52061. if (f != XBADFILE)
  52062. XFCLOSE(f);
  52063. #endif /* HAVE_ECC */
  52064. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52065. return EXPECT_RESULT();
  52066. }
  52067. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  52068. {
  52069. EXPECT_DECLS;
  52070. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52071. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52072. XFILE file = XBADFILE;
  52073. const char* fname = "./certs/client-keyPub.pem";
  52074. RSA *rsa = NULL;
  52075. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  52076. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52077. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  52078. ExpectIntEQ(RSA_size(rsa), 256);
  52079. RSA_free(rsa);
  52080. if (file != XBADFILE)
  52081. XFCLOSE(file);
  52082. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52083. return EXPECT_RESULT();
  52084. }
  52085. #ifndef NO_BIO
  52086. static int test_wolfSSL_PEM_bio_RSAKey(void)
  52087. {
  52088. EXPECT_DECLS;
  52089. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52090. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52091. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52092. RSA* rsa = NULL;
  52093. BIO* bio = NULL;
  52094. /* PrivateKey */
  52095. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52096. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  52097. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  52098. ExpectNotNull(rsa);
  52099. ExpectIntEQ(RSA_size(rsa), 256);
  52100. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  52101. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52102. BIO_free(bio);
  52103. bio = NULL;
  52104. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52105. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  52106. NULL), WOLFSSL_SUCCESS);
  52107. BIO_free(bio);
  52108. bio = NULL;
  52109. RSA_free(rsa);
  52110. rsa = NULL;
  52111. /* PUBKEY */
  52112. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  52113. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  52114. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52115. ExpectIntEQ(RSA_size(rsa), 256);
  52116. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52117. BIO_free(bio);
  52118. bio = NULL;
  52119. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52120. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  52121. BIO_free(bio);
  52122. bio = NULL;
  52123. RSA_free(rsa);
  52124. rsa = NULL;
  52125. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  52126. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  52127. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52128. BIO_free(bio);
  52129. bio = NULL;
  52130. RSA_free(rsa);
  52131. rsa = NULL;
  52132. #ifdef HAVE_ECC
  52133. /* ensure that non-rsa keys do not work */
  52134. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  52135. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52136. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52137. BIO_free(bio);
  52138. bio = NULL;
  52139. RSA_free(rsa);
  52140. rsa = NULL;
  52141. #endif /* HAVE_ECC */
  52142. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52143. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52144. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52145. return EXPECT_RESULT();
  52146. }
  52147. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  52148. {
  52149. EXPECT_DECLS;
  52150. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52151. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52152. RSA* rsa = NULL;
  52153. RSA* rsa_dup = NULL;
  52154. BIO* bio = NULL;
  52155. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52156. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52157. ExpectIntEQ(RSA_size(rsa), 256);
  52158. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  52159. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  52160. /* Test duplicating empty key. */
  52161. ExpectNotNull(rsa_dup = RSA_new());
  52162. ExpectNull(RSAPublicKey_dup(rsa_dup));
  52163. RSA_free(rsa_dup);
  52164. rsa_dup = NULL;
  52165. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  52166. ExpectPtrNE(rsa_dup, rsa);
  52167. #endif
  52168. /* test if valgrind complains about unreleased memory */
  52169. RSA_up_ref(rsa);
  52170. RSA_free(rsa);
  52171. BIO_free(bio);
  52172. bio = NULL;
  52173. RSA_free(rsa);
  52174. rsa = NULL;
  52175. RSA_free(rsa_dup);
  52176. rsa_dup = NULL;
  52177. #ifdef HAVE_ECC
  52178. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  52179. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52180. BIO_free(bio);
  52181. #endif /* HAVE_ECC */
  52182. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52183. return EXPECT_RESULT();
  52184. }
  52185. static int test_wolfSSL_PEM_bio_DSAKey(void)
  52186. {
  52187. EXPECT_DECLS;
  52188. #ifndef HAVE_SELFTEST
  52189. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  52190. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  52191. DSA* dsa = NULL;
  52192. BIO* bio = NULL;
  52193. /* PrivateKey */
  52194. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  52195. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  52196. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  52197. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  52198. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  52199. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52200. BIO_free(bio);
  52201. bio = NULL;
  52202. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52203. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  52204. NULL), WOLFSSL_SUCCESS);
  52205. BIO_free(bio);
  52206. bio = NULL;
  52207. DSA_free(dsa);
  52208. dsa = NULL;
  52209. /* PUBKEY */
  52210. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  52211. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  52212. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  52213. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  52214. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52215. BIO_free(bio);
  52216. bio = NULL;
  52217. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52218. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  52219. BIO_free(bio);
  52220. bio = NULL;
  52221. DSA_free(dsa);
  52222. dsa = NULL;
  52223. #ifdef HAVE_ECC
  52224. /* ensure that non-dsa keys do not work */
  52225. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  52226. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  52227. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  52228. BIO_free(bio);
  52229. bio = NULL;
  52230. DSA_free(dsa);
  52231. dsa = NULL;
  52232. #endif /* HAVE_ECC */
  52233. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  52234. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  52235. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  52236. #endif /* HAVE_SELFTEST */
  52237. return EXPECT_RESULT();
  52238. }
  52239. static int test_wolfSSL_PEM_bio_ECKey(void)
  52240. {
  52241. EXPECT_DECLS;
  52242. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52243. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  52244. EC_KEY* ec = NULL;
  52245. EC_KEY* ec2;
  52246. BIO* bio = NULL;
  52247. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  52248. unsigned char* pem = NULL;
  52249. int pLen;
  52250. #endif
  52251. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  52252. "MAA=\n"
  52253. "-----END PUBLIC KEY-----";
  52254. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  52255. "MAA=\n"
  52256. "-----END EC PRIVATE KEY-----";
  52257. /* PrivateKey */
  52258. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  52259. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  52260. ec2 = NULL;
  52261. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  52262. ExpectIntEQ(ec == ec2, 1);
  52263. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52264. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  52265. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52266. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  52267. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52268. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  52269. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52270. BIO_free(bio);
  52271. bio = NULL;
  52272. /* Public key data - fail. */
  52273. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52274. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52275. BIO_free(bio);
  52276. bio = NULL;
  52277. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52278. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  52279. NULL), WOLFSSL_SUCCESS);
  52280. BIO_free(bio);
  52281. bio = NULL;
  52282. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  52283. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52284. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  52285. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52286. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  52287. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52288. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  52289. WOLFSSL_SUCCESS);
  52290. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52291. NULL), 0);
  52292. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  52293. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52294. NULL), 0);
  52295. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52296. NULL), 0);
  52297. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52298. &pLen), 0);
  52299. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52300. &pLen), 0);
  52301. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52302. &pLen), 0);
  52303. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52304. NULL), 0);
  52305. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52306. &pLen), 1);
  52307. ExpectIntGT(pLen, 0);
  52308. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  52309. #endif
  52310. EC_KEY_free(ec);
  52311. ec = NULL;
  52312. /* PUBKEY */
  52313. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52314. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  52315. ec2 = NULL;
  52316. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  52317. ExpectIntEQ(ec == ec2, 1);
  52318. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52319. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52320. BIO_free(bio);
  52321. bio = NULL;
  52322. /* Test 0x30, 0x00 fails. */
  52323. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  52324. sizeof(ec_key_bad_1)));
  52325. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52326. BIO_free(bio);
  52327. bio = NULL;
  52328. /* Private key data - fail. */
  52329. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  52330. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52331. BIO_free(bio);
  52332. bio = NULL;
  52333. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52334. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  52335. BIO_free(bio);
  52336. bio = NULL;
  52337. /* Same test as above, but with a file pointer rather than a BIO. */
  52338. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52339. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52340. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52341. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  52342. EC_KEY_free(ec);
  52343. ec = NULL;
  52344. #ifndef NO_RSA
  52345. /* ensure that non-ec keys do not work */
  52346. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  52347. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  52348. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  52349. BIO_free(bio);
  52350. bio = NULL;
  52351. EC_KEY_free(ec);
  52352. ec = NULL;
  52353. #endif /* !NO_RSA */
  52354. /* Test 0x30, 0x00 fails. */
  52355. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  52356. sizeof(ec_priv_key_bad_1)));
  52357. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52358. BIO_free(bio);
  52359. bio = NULL;
  52360. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52361. return EXPECT_RESULT();
  52362. }
  52363. static int test_wolfSSL_PEM_PUBKEY(void)
  52364. {
  52365. EXPECT_DECLS;
  52366. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  52367. BIO* bio = NULL;
  52368. EVP_PKEY* pkey = NULL;
  52369. /* test creating new EVP_PKEY with bad arg */
  52370. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  52371. /* test loading ECC key using BIO */
  52372. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  52373. {
  52374. XFILE file = XBADFILE;
  52375. const char* fname = "./certs/ecc-client-keyPub.pem";
  52376. size_t sz = 0;
  52377. byte* buf = NULL;
  52378. EVP_PKEY* pkey2 = NULL;
  52379. EC_KEY* ec_key = NULL;
  52380. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52381. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  52382. ExpectIntGT(sz = XFTELL(file), 0);
  52383. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  52384. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52385. if (buf != NULL) {
  52386. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52387. }
  52388. if (file != XBADFILE) {
  52389. XFCLOSE(file);
  52390. }
  52391. /* Test using BIO new mem and loading PEM private key */
  52392. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52393. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  52394. BIO_free(bio);
  52395. bio = NULL;
  52396. EVP_PKEY_free(pkey);
  52397. pkey = NULL;
  52398. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52399. ExpectNotNull(pkey = EVP_PKEY_new());
  52400. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  52401. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52402. BIO_free(bio);
  52403. bio = NULL;
  52404. /* Qt unit test case*/
  52405. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52406. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52407. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  52408. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52409. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  52410. #else
  52411. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  52412. #endif
  52413. EC_KEY_free(ec_key);
  52414. EVP_PKEY_free(pkey2);
  52415. EVP_PKEY_free(pkey);
  52416. pkey = NULL;
  52417. }
  52418. #endif
  52419. (void)bio;
  52420. (void)pkey;
  52421. #endif
  52422. return EXPECT_RESULT();
  52423. }
  52424. #endif /* !NO_BIO */
  52425. static int test_DSA_do_sign_verify(void)
  52426. {
  52427. EXPECT_DECLS;
  52428. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  52429. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  52430. !defined(NO_DSA)
  52431. unsigned char digest[WC_SHA_DIGEST_SIZE];
  52432. DSA_SIG* sig = NULL;
  52433. DSA* dsa = NULL;
  52434. word32 bytes;
  52435. byte sigBin[DSA_SIG_SIZE];
  52436. int dsacheck;
  52437. #ifdef USE_CERT_BUFFERS_1024
  52438. byte tmp[ONEK_BUF];
  52439. XMEMSET(tmp, 0, sizeof(tmp));
  52440. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  52441. bytes = sizeof_dsa_key_der_1024;
  52442. #elif defined(USE_CERT_BUFFERS_2048)
  52443. byte tmp[TWOK_BUF];
  52444. XMEMSET(tmp, 0, sizeof(tmp));
  52445. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  52446. bytes = sizeof_dsa_key_der_2048;
  52447. #else
  52448. byte tmp[TWOK_BUF];
  52449. XFILE fp = XBADFILE;
  52450. XMEMSET(tmp, 0, sizeof(tmp));
  52451. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  52452. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  52453. if (fp != XBADFILE)
  52454. XFCLOSE(fp);
  52455. #endif /* END USE_CERT_BUFFERS_1024 */
  52456. XMEMSET(digest, 202, sizeof(digest));
  52457. ExpectNotNull(dsa = DSA_new());
  52458. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  52459. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  52460. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  52461. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  52462. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  52463. DSA_SIG_free(sig);
  52464. DSA_free(dsa);
  52465. #endif
  52466. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  52467. return EXPECT_RESULT();
  52468. }
  52469. static int test_wolfSSL_tmp_dh(void)
  52470. {
  52471. EXPECT_DECLS;
  52472. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  52473. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  52474. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  52475. byte buff[6000];
  52476. static const unsigned char p[] = {
  52477. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52478. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52479. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52480. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52481. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52482. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52483. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52484. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52485. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52486. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52487. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52488. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52489. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52490. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52491. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52492. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52493. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52494. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52495. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52496. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52497. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52498. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52499. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52500. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52501. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52502. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52503. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52504. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52505. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52506. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52507. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52508. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  52509. };
  52510. int pSz = (int)sizeof(p);
  52511. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52512. !defined(HAVE_SELFTEST)
  52513. static const unsigned char bad_p[] = {
  52514. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52515. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52516. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52517. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52518. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52519. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52520. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52521. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52522. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52523. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52524. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52525. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52526. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52527. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52528. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52529. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52530. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52531. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52532. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52533. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52534. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52535. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52536. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52537. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52538. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52539. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52540. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52541. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52542. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52543. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52544. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52545. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  52546. };
  52547. #endif
  52548. static const unsigned char g[] = { 0x02 };
  52549. int gSz = (int)sizeof(g);
  52550. #if !defined(NO_DSA)
  52551. char file[] = "./certs/dsaparams.pem";
  52552. DSA* dsa = NULL;
  52553. #else
  52554. char file[] = "./certs/dh2048.pem";
  52555. #endif
  52556. XFILE f = XBADFILE;
  52557. int bytes = 0;
  52558. DH* dh = NULL;
  52559. DH* dh2 = NULL;
  52560. BIO* bio = NULL;
  52561. SSL* ssl = NULL;
  52562. SSL_CTX* ctx = NULL;
  52563. #ifndef NO_WOLFSSL_CLIENT
  52564. SSL* ssl_c = NULL;
  52565. SSL_CTX* ctx_c = NULL;
  52566. #endif
  52567. #ifndef NO_WOLFSSL_SERVER
  52568. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52569. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  52570. WOLFSSL_FILETYPE_PEM));
  52571. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  52572. WOLFSSL_FILETYPE_PEM));
  52573. ExpectNotNull(ssl = SSL_new(ctx));
  52574. #endif
  52575. #ifndef NO_WOLFSSL_CLIENT
  52576. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  52577. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  52578. WOLFSSL_FILETYPE_PEM));
  52579. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  52580. WOLFSSL_FILETYPE_PEM));
  52581. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  52582. #ifdef NO_WOLFSSL_SERVER
  52583. ctx = ctx_c;
  52584. ssl = ssl_c;
  52585. #endif
  52586. #endif
  52587. XMEMSET(buff, 0, sizeof(buff));
  52588. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  52589. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  52590. if (f != XBADFILE)
  52591. XFCLOSE(f);
  52592. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52593. #if !defined(NO_DSA)
  52594. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  52595. ExpectNotNull(dsa);
  52596. dh = wolfSSL_DSA_dup_DH(dsa);
  52597. #else
  52598. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  52599. #endif
  52600. ExpectNotNull(dh);
  52601. #if defined(WOLFSSL_DH_EXTRA) && \
  52602. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  52603. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  52604. DH_free(dh2);
  52605. dh2 = NULL;
  52606. #endif
  52607. /* Failure cases */
  52608. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52609. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52610. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  52611. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52612. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  52613. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52614. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  52615. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52616. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  52617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52618. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  52619. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52620. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  52621. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52622. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  52623. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52624. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  52625. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52626. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52627. !defined(HAVE_SELFTEST)
  52628. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  52629. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  52630. #endif
  52631. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52632. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52633. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  52634. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52635. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  52636. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52637. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  52638. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52639. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  52640. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52641. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  52642. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52643. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  52644. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52645. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  52646. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52647. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  52648. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52649. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52650. !defined(HAVE_SELFTEST)
  52651. #ifndef NO_WOLFSSL_SERVER
  52652. /* Parameters will be tested later so it passes now. */
  52653. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  52654. WOLFSSL_SUCCESS);
  52655. #endif
  52656. #endif
  52657. #ifndef NO_WOLFSSL_CLIENT
  52658. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  52659. WC_NO_ERR_TRACE(SIDE_ERROR));
  52660. #endif
  52661. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52662. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52663. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52664. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52665. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52666. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52667. /* No p/g to use. */
  52668. dh2 = wolfSSL_DH_new();
  52669. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52670. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52671. DH_free(dh2);
  52672. dh2 = NULL;
  52673. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  52674. WOLFSSL_SUCCESS);
  52675. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  52676. #ifndef NO_WOLFSSL_SERVER
  52677. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  52678. #else
  52679. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  52680. #endif
  52681. BIO_free(bio);
  52682. #if !defined(NO_DSA)
  52683. DSA_free(dsa);
  52684. #endif
  52685. DH_free(dh);
  52686. dh = NULL;
  52687. #ifndef NO_WOLFSSL_CLIENT
  52688. if (ssl != ssl_c) {
  52689. SSL_free(ssl_c);
  52690. }
  52691. #endif
  52692. SSL_free(ssl);
  52693. #ifndef NO_WOLFSSL_CLIENT
  52694. if (ctx != ctx_c) {
  52695. SSL_CTX_free(ctx_c);
  52696. }
  52697. #endif
  52698. SSL_CTX_free(ctx);
  52699. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52700. #endif
  52701. return EXPECT_RESULT();
  52702. }
  52703. static int test_wolfSSL_ctrl(void)
  52704. {
  52705. EXPECT_DECLS;
  52706. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  52707. byte buff[6000];
  52708. BIO* bio = NULL;
  52709. int bytes;
  52710. BUF_MEM* ptr = NULL;
  52711. XMEMSET(buff, 0, sizeof(buff));
  52712. bytes = sizeof(buff);
  52713. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52714. ExpectNotNull(BIO_s_socket());
  52715. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  52716. /* needs tested after stubs filled out @TODO
  52717. SSL_ctrl
  52718. SSL_CTX_ctrl
  52719. */
  52720. BIO_free(bio);
  52721. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  52722. return EXPECT_RESULT();
  52723. }
  52724. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  52725. {
  52726. EXPECT_DECLS;
  52727. #ifdef OPENSSL_EXTRA
  52728. static const unsigned char pw[] = "password";
  52729. static const int pwSz = sizeof(pw) - 1;
  52730. size_t checkPwSz = 0;
  52731. const unsigned char* checkPw = NULL;
  52732. WOLFSSL_EVP_PKEY* key = NULL;
  52733. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  52734. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  52735. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52736. pwSz));
  52737. if (key != NULL) {
  52738. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  52739. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  52740. ExpectIntEQ(key->pkey_sz, pwSz);
  52741. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  52742. }
  52743. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  52744. ExpectIntEQ((int)checkPwSz, pwSz);
  52745. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  52746. wolfSSL_EVP_PKEY_free(key);
  52747. key = NULL;
  52748. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52749. 0));
  52750. ExpectIntEQ(key->pkey_sz, 0);
  52751. if (EXPECT_SUCCESS()) {
  52752. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52753. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52754. }
  52755. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52756. ExpectIntEQ((int)checkPwSz, 0);
  52757. wolfSSL_EVP_PKEY_free(key);
  52758. key = NULL;
  52759. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  52760. 0));
  52761. ExpectIntEQ(key->pkey_sz, 0);
  52762. if (EXPECT_SUCCESS()) {
  52763. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52764. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52765. }
  52766. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52767. ExpectIntEQ((int)checkPwSz, 0);
  52768. wolfSSL_EVP_PKEY_free(key);
  52769. key = NULL;
  52770. #endif /* OPENSSL_EXTRA */
  52771. return EXPECT_RESULT();
  52772. }
  52773. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  52774. {
  52775. EXPECT_DECLS;
  52776. #ifdef OPENSSL_EXTRA
  52777. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  52778. const char *priv = "ABCDEFGHIJKLMNOP";
  52779. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  52780. WOLFSSL_EVP_PKEY* key = NULL;
  52781. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52782. NULL, NULL, AES_128_KEY_SIZE, cipher));
  52783. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52784. NULL, (const unsigned char *)priv, 0, cipher));
  52785. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52786. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  52787. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52788. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  52789. wolfSSL_EVP_PKEY_free(key);
  52790. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  52791. #endif /* OPENSSL_EXTRA */
  52792. return EXPECT_RESULT();
  52793. }
  52794. static int test_wolfSSL_EVP_Digest(void)
  52795. {
  52796. EXPECT_DECLS;
  52797. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  52798. const char* in = "abc";
  52799. int inLen = (int)XSTRLEN(in);
  52800. byte out[WC_SHA256_DIGEST_SIZE];
  52801. unsigned int outLen;
  52802. const char* expOut =
  52803. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  52804. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  52805. "\x15\xAD";
  52806. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  52807. "SHA256", NULL), 1);
  52808. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  52809. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  52810. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  52811. return EXPECT_RESULT();
  52812. }
  52813. static int test_wolfSSL_EVP_Digest_all(void)
  52814. {
  52815. EXPECT_DECLS;
  52816. #ifdef OPENSSL_EXTRA
  52817. const char* digests[] = {
  52818. #ifndef NO_MD5
  52819. "MD5",
  52820. #endif
  52821. #ifndef NO_SHA
  52822. "SHA",
  52823. #endif
  52824. #ifdef WOLFSSL_SHA224
  52825. "SHA224",
  52826. #endif
  52827. #ifndef NO_SHA256
  52828. "SHA256",
  52829. #endif
  52830. #ifdef WOLFSSL_SHA384
  52831. "SHA384",
  52832. #endif
  52833. #ifdef WOLFSSL_SHA512
  52834. "SHA512",
  52835. #endif
  52836. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  52837. "SHA512_224",
  52838. #endif
  52839. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  52840. "SHA512_256",
  52841. #endif
  52842. #ifdef WOLFSSL_SHA3
  52843. #ifndef WOLFSSL_NOSHA3_224
  52844. "SHA3_224",
  52845. #endif
  52846. #ifndef WOLFSSL_NOSHA3_256
  52847. "SHA3_256",
  52848. #endif
  52849. "SHA3_384",
  52850. #ifndef WOLFSSL_NOSHA3_512
  52851. "SHA3_512",
  52852. #endif
  52853. #endif /* WOLFSSL_SHA3 */
  52854. NULL
  52855. };
  52856. const char** d;
  52857. const unsigned char in[] = "abc";
  52858. int inLen = XSTR_SIZEOF(in);
  52859. byte out[WC_MAX_DIGEST_SIZE];
  52860. unsigned int outLen;
  52861. for (d = digests; *d != NULL; d++) {
  52862. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  52863. ExpectIntGT(outLen, 0);
  52864. ExpectIntEQ(EVP_MD_size(*d), outLen);
  52865. }
  52866. #endif
  52867. return EXPECT_RESULT();
  52868. }
  52869. static int test_wolfSSL_EVP_MD_size(void)
  52870. {
  52871. EXPECT_DECLS;
  52872. #ifdef OPENSSL_EXTRA
  52873. WOLFSSL_EVP_MD_CTX mdCtx;
  52874. #ifdef WOLFSSL_SHA3
  52875. #ifndef WOLFSSL_NOSHA3_224
  52876. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52877. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  52878. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  52879. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  52880. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52881. #endif
  52882. #ifndef WOLFSSL_NOSHA3_256
  52883. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52884. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  52885. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  52886. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  52887. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52888. #endif
  52889. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52890. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  52891. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  52892. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  52893. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52894. #ifndef WOLFSSL_NOSHA3_512
  52895. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52896. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  52897. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  52898. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  52899. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52900. #endif
  52901. #endif /* WOLFSSL_SHA3 */
  52902. #ifndef NO_SHA256
  52903. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52904. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  52905. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52906. WC_SHA256_DIGEST_SIZE);
  52907. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52908. WC_SHA256_BLOCK_SIZE);
  52909. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  52910. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  52911. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52912. #endif
  52913. #ifndef NO_MD5
  52914. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52915. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  52916. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52917. WC_MD5_DIGEST_SIZE);
  52918. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52919. WC_MD5_BLOCK_SIZE);
  52920. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  52921. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  52922. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52923. #endif
  52924. #ifdef WOLFSSL_SHA224
  52925. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52926. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  52927. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52928. WC_SHA224_DIGEST_SIZE);
  52929. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52930. WC_SHA224_BLOCK_SIZE);
  52931. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  52932. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  52933. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52934. #endif
  52935. #ifdef WOLFSSL_SHA384
  52936. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52937. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  52938. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52939. WC_SHA384_DIGEST_SIZE);
  52940. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52941. WC_SHA384_BLOCK_SIZE);
  52942. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  52943. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  52944. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52945. #endif
  52946. #ifdef WOLFSSL_SHA512
  52947. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52948. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  52949. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52950. WC_SHA512_DIGEST_SIZE);
  52951. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52952. WC_SHA512_BLOCK_SIZE);
  52953. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  52954. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  52955. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52956. #endif
  52957. #ifndef NO_SHA
  52958. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52959. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  52960. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52961. WC_SHA_DIGEST_SIZE);
  52962. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52963. WC_SHA_BLOCK_SIZE);
  52964. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52965. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52966. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52967. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52968. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  52969. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52970. WC_SHA_DIGEST_SIZE);
  52971. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52972. WC_SHA_BLOCK_SIZE);
  52973. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52974. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52975. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52976. #endif
  52977. /* error case */
  52978. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52979. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  52980. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  52981. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  52982. /* Cleanup is valid on uninit'ed struct */
  52983. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52984. #endif /* OPENSSL_EXTRA */
  52985. return EXPECT_RESULT();
  52986. }
  52987. static int test_wolfSSL_EVP_MD_pkey_type(void)
  52988. {
  52989. EXPECT_DECLS;
  52990. #ifdef OPENSSL_EXTRA
  52991. const WOLFSSL_EVP_MD* md;
  52992. #ifndef NO_MD5
  52993. ExpectNotNull(md = EVP_md5());
  52994. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  52995. #endif
  52996. #ifndef NO_SHA
  52997. ExpectNotNull(md = EVP_sha1());
  52998. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  52999. #endif
  53000. #ifdef WOLFSSL_SHA224
  53001. ExpectNotNull(md = EVP_sha224());
  53002. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  53003. #endif
  53004. ExpectNotNull(md = EVP_sha256());
  53005. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  53006. #ifdef WOLFSSL_SHA384
  53007. ExpectNotNull(md = EVP_sha384());
  53008. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  53009. #endif
  53010. #ifdef WOLFSSL_SHA512
  53011. ExpectNotNull(md = EVP_sha512());
  53012. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  53013. #endif
  53014. #endif
  53015. return EXPECT_RESULT();
  53016. }
  53017. #ifdef OPENSSL_EXTRA
  53018. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  53019. size_t testKeySz, const char* testData, size_t testDataSz,
  53020. const byte* testResult, size_t testResultSz)
  53021. {
  53022. EXPECT_DECLS;
  53023. unsigned char check[WC_MAX_DIGEST_SIZE];
  53024. size_t checkSz = -1;
  53025. WOLFSSL_EVP_PKEY* key = NULL;
  53026. WOLFSSL_EVP_MD_CTX mdCtx;
  53027. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  53028. testKey, (int)testKeySz));
  53029. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53030. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53031. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53032. (unsigned int)testDataSz), 1);
  53033. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53034. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53035. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53036. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53037. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53038. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53039. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53040. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53041. (unsigned int)testDataSz), 1);
  53042. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53043. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53044. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53045. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53046. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53047. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53048. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53049. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53050. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53051. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53052. (unsigned int)testDataSz - 4), 1);
  53053. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53054. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53055. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53056. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53057. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53058. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53059. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53060. (unsigned int)testDataSz - 4), 1);
  53061. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53062. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53063. wolfSSL_EVP_PKEY_free(key);
  53064. return EXPECT_RESULT();
  53065. }
  53066. #endif
  53067. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  53068. {
  53069. EXPECT_DECLS;
  53070. #ifdef OPENSSL_EXTRA
  53071. static const unsigned char testKey[] =
  53072. {
  53073. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53074. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53075. 0x0b, 0x0b, 0x0b, 0x0b
  53076. };
  53077. static const char testData[] = "Hi There";
  53078. #ifdef WOLFSSL_SHA224
  53079. static const unsigned char testResultSha224[] =
  53080. {
  53081. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  53082. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  53083. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  53084. 0x53, 0x68, 0x4b, 0x22
  53085. };
  53086. #endif
  53087. #ifndef NO_SHA256
  53088. static const unsigned char testResultSha256[] =
  53089. {
  53090. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  53091. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  53092. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  53093. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  53094. };
  53095. #endif
  53096. #ifdef WOLFSSL_SHA384
  53097. static const unsigned char testResultSha384[] =
  53098. {
  53099. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  53100. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  53101. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  53102. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  53103. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  53104. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  53105. };
  53106. #endif
  53107. #ifdef WOLFSSL_SHA512
  53108. static const unsigned char testResultSha512[] =
  53109. {
  53110. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  53111. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  53112. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  53113. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  53114. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  53115. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  53116. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  53117. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  53118. };
  53119. #endif
  53120. #ifdef WOLFSSL_SHA3
  53121. #ifndef WOLFSSL_NOSHA3_224
  53122. static const unsigned char testResultSha3_224[] =
  53123. {
  53124. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  53125. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  53126. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  53127. 0xf3, 0xc8, 0x60, 0xf7
  53128. };
  53129. #endif
  53130. #ifndef WOLFSSL_NOSHA3_256
  53131. static const unsigned char testResultSha3_256[] =
  53132. {
  53133. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  53134. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  53135. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  53136. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  53137. };
  53138. #endif
  53139. #ifndef WOLFSSL_NOSHA3_384
  53140. static const unsigned char testResultSha3_384[] =
  53141. {
  53142. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  53143. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  53144. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  53145. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  53146. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  53147. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  53148. };
  53149. #endif
  53150. #ifndef WOLFSSL_NOSHA3_512
  53151. static const unsigned char testResultSha3_512[] =
  53152. {
  53153. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  53154. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  53155. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  53156. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  53157. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  53158. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  53159. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  53160. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  53161. };
  53162. #endif
  53163. #endif
  53164. #ifndef NO_SHA256
  53165. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  53166. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  53167. sizeof(testResultSha256)), TEST_SUCCESS);
  53168. #endif
  53169. #ifdef WOLFSSL_SHA224
  53170. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  53171. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  53172. sizeof(testResultSha224)), TEST_SUCCESS);
  53173. #endif
  53174. #ifdef WOLFSSL_SHA384
  53175. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  53176. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  53177. sizeof(testResultSha384)), TEST_SUCCESS);
  53178. #endif
  53179. #ifdef WOLFSSL_SHA512
  53180. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  53181. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  53182. sizeof(testResultSha512)), TEST_SUCCESS);
  53183. #endif
  53184. #ifdef WOLFSSL_SHA3
  53185. #ifndef WOLFSSL_NOSHA3_224
  53186. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  53187. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  53188. sizeof(testResultSha3_224)), TEST_SUCCESS);
  53189. #endif
  53190. #ifndef WOLFSSL_NOSHA3_256
  53191. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  53192. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  53193. sizeof(testResultSha3_256)), TEST_SUCCESS);
  53194. #endif
  53195. #ifndef WOLFSSL_NOSHA3_384
  53196. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  53197. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  53198. sizeof(testResultSha3_384)), TEST_SUCCESS);
  53199. #endif
  53200. #ifndef WOLFSSL_NOSHA3_512
  53201. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  53202. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  53203. sizeof(testResultSha3_512)), TEST_SUCCESS);
  53204. #endif
  53205. #endif
  53206. #endif /* OPENSSL_EXTRA */
  53207. return EXPECT_RESULT();
  53208. }
  53209. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  53210. {
  53211. EXPECT_DECLS;
  53212. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  53213. WOLFSSL_EVP_PKEY* privKey = NULL;
  53214. WOLFSSL_EVP_PKEY* pubKey = NULL;
  53215. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  53216. const char testData[] = "Hi There";
  53217. WOLFSSL_EVP_MD_CTX mdCtx;
  53218. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  53219. int ret;
  53220. size_t checkSz = -1;
  53221. int sz = 2048 / 8;
  53222. const unsigned char* cp;
  53223. const unsigned char* p;
  53224. unsigned char check[2048/8];
  53225. size_t i;
  53226. int paddings[] = {
  53227. RSA_PKCS1_PADDING,
  53228. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  53229. RSA_PKCS1_PSS_PADDING,
  53230. #endif
  53231. };
  53232. cp = client_key_der_2048;
  53233. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  53234. sizeof_client_key_der_2048)));
  53235. p = client_keypub_der_2048;
  53236. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  53237. sizeof_client_keypub_der_2048)));
  53238. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53239. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  53240. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53241. NULL, privKey), 1);
  53242. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53243. (unsigned int)XSTRLEN(testData)), 1);
  53244. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53245. ExpectIntEQ((int)checkSz, sz);
  53246. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53247. ExpectIntEQ((int)checkSz,sz);
  53248. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  53249. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  53250. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  53251. ExpectIntEQ(ret, 1);
  53252. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53253. ExpectIntEQ(ret, 1);
  53254. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53255. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53256. NULL, pubKey), 1);
  53257. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53258. (unsigned int)XSTRLEN(testData)),
  53259. 1);
  53260. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53261. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53262. ExpectIntEQ(ret, 1);
  53263. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53264. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53265. NULL, privKey), 1);
  53266. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53267. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53268. ExpectIntEQ((int)checkSz, sz);
  53269. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53270. ExpectIntEQ((int)checkSz, sz);
  53271. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53272. (unsigned int)XSTRLEN(testData) - 4), 1);
  53273. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53274. ExpectIntEQ((int)checkSz, sz);
  53275. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53276. ExpectIntEQ(ret, 1);
  53277. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53278. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53279. NULL, pubKey), 1);
  53280. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53281. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53282. (unsigned int)XSTRLEN(testData) - 4),
  53283. 1);
  53284. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53285. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53286. ExpectIntEQ(ret, 1);
  53287. /* Check all signing padding types */
  53288. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  53289. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53290. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  53291. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  53292. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53293. paddings[i]), 1);
  53294. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53295. (unsigned int)XSTRLEN(testData)), 1);
  53296. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53297. ExpectIntEQ((int)checkSz, sz);
  53298. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53299. ExpectIntEQ((int)checkSz,sz);
  53300. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53301. ExpectIntEQ(ret, 1);
  53302. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53303. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  53304. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  53305. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53306. paddings[i]), 1);
  53307. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53308. (unsigned int)XSTRLEN(testData)), 1);
  53309. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53310. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53311. ExpectIntEQ(ret, 1);
  53312. }
  53313. wolfSSL_EVP_PKEY_free(pubKey);
  53314. wolfSSL_EVP_PKEY_free(privKey);
  53315. #endif
  53316. return EXPECT_RESULT();
  53317. }
  53318. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  53319. {
  53320. EXPECT_DECLS;
  53321. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  53322. WOLFSSL_EVP_PKEY* privKey = NULL;
  53323. WOLFSSL_EVP_PKEY* pubKey = NULL;
  53324. const char testData[] = "Hi There";
  53325. WOLFSSL_EVP_MD_CTX mdCtx;
  53326. int ret;
  53327. size_t checkSz = -1;
  53328. const unsigned char* cp;
  53329. const unsigned char* p;
  53330. unsigned char check[2048/8];
  53331. cp = ecc_clikey_der_256;
  53332. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  53333. sizeof_ecc_clikey_der_256));
  53334. p = ecc_clikeypub_der_256;
  53335. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  53336. sizeof_ecc_clikeypub_der_256)));
  53337. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53338. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53339. NULL, privKey), 1);
  53340. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53341. (unsigned int)XSTRLEN(testData)), 1);
  53342. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53343. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53344. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53345. ExpectIntEQ(ret, 1);
  53346. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53347. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53348. NULL, pubKey), 1);
  53349. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53350. (unsigned int)XSTRLEN(testData)),
  53351. 1);
  53352. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53353. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53354. ExpectIntEQ(ret, 1);
  53355. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53356. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53357. NULL, privKey), 1);
  53358. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53359. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53360. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53361. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53362. (unsigned int)XSTRLEN(testData) - 4), 1);
  53363. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53364. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53365. ExpectIntEQ(ret, 1);
  53366. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53367. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53368. NULL, pubKey), 1);
  53369. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53370. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53371. (unsigned int)XSTRLEN(testData) - 4),
  53372. 1);
  53373. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53374. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53375. ExpectIntEQ(ret, 1);
  53376. wolfSSL_EVP_PKEY_free(pubKey);
  53377. wolfSSL_EVP_PKEY_free(privKey);
  53378. #endif
  53379. return EXPECT_RESULT();
  53380. }
  53381. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  53382. {
  53383. EXPECT_DECLS;
  53384. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53385. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  53386. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53387. char caFile[] = "./certs/client-ca.pem";
  53388. char clientFile[] = "./certs/client-cert.pem";
  53389. SSL_CTX* ctx = NULL;
  53390. X509* x509 = NULL;
  53391. BIO *bio = NULL;
  53392. X509 *cert = NULL;
  53393. X509 *ca = NULL;
  53394. STACK_OF(X509) *chain = NULL;
  53395. STACK_OF(X509) *chain2 = NULL;
  53396. #ifndef NO_WOLFSSL_SERVER
  53397. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53398. #else
  53399. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53400. #endif
  53401. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  53402. WOLFSSL_FILETYPE_PEM));
  53403. /* Negative tests. */
  53404. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53405. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53406. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53407. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  53408. ExpectNotNull(x509 = wolfSSL_X509_new());
  53409. /* Empty certificate. */
  53410. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53411. wolfSSL_X509_free(x509);
  53412. x509 = NULL;
  53413. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  53414. WOLFSSL_FILETYPE_PEM));
  53415. /* additional test of getting EVP_PKEY key size from X509
  53416. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  53417. * allowed with user RSA */
  53418. {
  53419. EVP_PKEY* pkey = NULL;
  53420. #if defined(HAVE_ECC)
  53421. X509* ecX509 = NULL;
  53422. #endif /* HAVE_ECC */
  53423. ExpectNotNull(pkey = X509_get_pubkey(x509));
  53424. /* current RSA key is 2048 bit (256 bytes) */
  53425. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  53426. EVP_PKEY_free(pkey);
  53427. pkey = NULL;
  53428. #if defined(HAVE_ECC)
  53429. #if defined(USE_CERT_BUFFERS_256)
  53430. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  53431. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  53432. SSL_FILETYPE_ASN1));
  53433. #else
  53434. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  53435. cliEccCertFile, SSL_FILETYPE_PEM));
  53436. #endif
  53437. pkey = X509_get_pubkey(ecX509);
  53438. ExpectNotNull(pkey);
  53439. /* current ECC key is 256 bit (32 bytes) */
  53440. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  53441. X509_free(ecX509);
  53442. ecX509 = NULL;
  53443. EVP_PKEY_free(pkey);
  53444. pkey = NULL;
  53445. #endif /* HAVE_ECC */
  53446. }
  53447. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  53448. if (EXPECT_SUCCESS()) {
  53449. x509 = NULL;
  53450. }
  53451. #ifdef WOLFSSL_ENCRYPTED_KEYS
  53452. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  53453. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  53454. #endif
  53455. SSL_CTX_free(ctx);
  53456. ctx = NULL;
  53457. #ifndef NO_WOLFSSL_SERVER
  53458. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53459. #else
  53460. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53461. #endif
  53462. /* Test haproxy use case */
  53463. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  53464. /* Read Certificate */
  53465. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  53466. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  53467. ExpectNotNull(chain = sk_X509_new_null());
  53468. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  53469. if (EXPECT_SUCCESS()) {
  53470. ca = NULL;
  53471. }
  53472. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  53473. ExpectNotNull(ca = sk_X509_shift(chain2));
  53474. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  53475. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  53476. if (EXPECT_SUCCESS()) {
  53477. ca = NULL;
  53478. }
  53479. BIO_free(bio);
  53480. X509_free(cert);
  53481. X509_free(ca);
  53482. X509_free(x509);
  53483. sk_X509_pop_free(chain, X509_free);
  53484. sk_X509_pop_free(chain2, X509_free);
  53485. SSL_CTX_free(ctx);
  53486. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53487. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53488. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  53489. return EXPECT_RESULT();
  53490. }
  53491. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  53492. static int test_wolfSSL_ERR_peek_last_error_line(void)
  53493. {
  53494. EXPECT_DECLS;
  53495. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53496. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  53497. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  53498. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  53499. callback_functions client_cb;
  53500. callback_functions server_cb;
  53501. int line = 0;
  53502. int flag = ERR_TXT_STRING;
  53503. const char* file = NULL;
  53504. const char* data = NULL;
  53505. /* create a failed connection and inspect the error */
  53506. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53507. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53508. client_cb.method = wolfTLSv1_1_client_method;
  53509. server_cb.method = wolfTLSv1_2_server_method;
  53510. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53511. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  53512. ExpectNotNull(data);
  53513. /* check clearing error state */
  53514. ERR_remove_state(0);
  53515. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53516. ERR_peek_last_error_line(NULL, &line);
  53517. ExpectIntEQ(line, 0);
  53518. ERR_peek_last_error_line(&file, NULL);
  53519. ExpectNull(file);
  53520. /* retry connection to fill error queue */
  53521. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53522. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53523. client_cb.method = wolfTLSv1_1_client_method;
  53524. server_cb.method = wolfTLSv1_2_server_method;
  53525. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53526. /* check that error code was stored */
  53527. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53528. ERR_peek_last_error_line(NULL, &line);
  53529. ExpectIntNE(line, 0);
  53530. ERR_peek_last_error_line(&file, NULL);
  53531. ExpectNotNull(file);
  53532. fprintf(stderr, "\nTesting error print out\n");
  53533. ERR_print_errors_fp(stderr);
  53534. fprintf(stderr, "Done testing print out\n\n");
  53535. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53536. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  53537. return EXPECT_RESULT();
  53538. }
  53539. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  53540. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53541. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53542. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  53543. {
  53544. (void) ok;
  53545. (void) ctx;
  53546. fprintf(stderr, "ENTER verify_cb\n");
  53547. return SSL_SUCCESS;
  53548. }
  53549. #endif
  53550. static int test_wolfSSL_X509_Name_canon(void)
  53551. {
  53552. EXPECT_DECLS;
  53553. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53554. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  53555. defined(WOLFSSL_CERT_GEN) && \
  53556. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  53557. const long ex_hash1 = 0x0fdb2da4;
  53558. const long ex_hash2 = 0x9f3e8c9e;
  53559. X509_NAME *name = NULL;
  53560. X509 *x509 = NULL;
  53561. XFILE file = XBADFILE;
  53562. unsigned long hash = 0;
  53563. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  53564. byte *pbuf = NULL;
  53565. word32 len = 0;
  53566. (void) ex_hash2;
  53567. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  53568. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53569. ExpectNotNull(name = X509_get_issuer_name(x509));
  53570. /* When output buffer is NULL, should return necessary output buffer
  53571. * length.*/
  53572. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  53573. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53574. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53575. hash = (((unsigned long)digest[3] << 24) |
  53576. ((unsigned long)digest[2] << 16) |
  53577. ((unsigned long)digest[1] << 8) |
  53578. ((unsigned long)digest[0]));
  53579. ExpectIntEQ(hash, ex_hash1);
  53580. if (file != XBADFILE) {
  53581. XFCLOSE(file);
  53582. file = XBADFILE;
  53583. }
  53584. X509_free(x509);
  53585. x509 = NULL;
  53586. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53587. pbuf = NULL;
  53588. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  53589. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53590. ExpectNotNull(name = X509_get_issuer_name(x509));
  53591. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53592. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53593. hash = (((unsigned long)digest[3] << 24) |
  53594. ((unsigned long)digest[2] << 16) |
  53595. ((unsigned long)digest[1] << 8) |
  53596. ((unsigned long)digest[0]));
  53597. ExpectIntEQ(hash, ex_hash2);
  53598. if (file != XBADFILE)
  53599. XFCLOSE(file);
  53600. X509_free(x509);
  53601. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53602. #endif
  53603. return EXPECT_RESULT();
  53604. }
  53605. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  53606. {
  53607. EXPECT_DECLS;
  53608. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  53609. const int MAX_DIR = 4;
  53610. const char paths[][32] = {
  53611. "./certs/ed25519",
  53612. "./certs/ecc",
  53613. "./certs/crl",
  53614. "./certs/",
  53615. };
  53616. char CertCrl_path[MAX_FILENAME_SZ];
  53617. char *p;
  53618. X509_STORE* str = NULL;
  53619. X509_LOOKUP* lookup = NULL;
  53620. WOLFSSL_STACK* sk = NULL;
  53621. int len, total_len, i;
  53622. (void)sk;
  53623. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  53624. /* illegal string */
  53625. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53626. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53627. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  53628. SSL_FILETYPE_PEM,NULL), 0);
  53629. /* free store */
  53630. X509_STORE_free(str);
  53631. str = NULL;
  53632. /* short folder string */
  53633. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53634. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53635. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  53636. SSL_FILETYPE_PEM,NULL), 1);
  53637. #if defined(WOLFSSL_INT_H)
  53638. /* only available when including internal.h */
  53639. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53640. #endif
  53641. /* free store */
  53642. X509_STORE_free(str);
  53643. str = NULL;
  53644. /* typical function check */
  53645. p = &CertCrl_path[0];
  53646. total_len = 0;
  53647. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  53648. len = (int)XSTRLEN((const char*)&paths[i]);
  53649. total_len += len;
  53650. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  53651. p += len;
  53652. if (i != 0) *(p++) = SEPARATOR_CHAR;
  53653. }
  53654. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53655. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53656. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  53657. SSL_FILETYPE_PEM,NULL), 1);
  53658. #if defined(WOLFSSL_INT_H)
  53659. /* only available when including internal.h */
  53660. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53661. #endif
  53662. X509_STORE_free(str);
  53663. #endif
  53664. return EXPECT_RESULT();
  53665. }
  53666. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  53667. {
  53668. EXPECT_DECLS;
  53669. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53670. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53671. defined(WOLFSSL_SIGNER_DER_CERT)
  53672. X509_STORE_CTX* ctx = NULL;
  53673. X509_STORE* str = NULL;
  53674. X509_LOOKUP* lookup = NULL;
  53675. X509* cert1 = NULL;
  53676. X509* x509Ca = NULL;
  53677. X509* x509Svr = NULL;
  53678. X509* issuer = NULL;
  53679. WOLFSSL_STACK* sk = NULL;
  53680. X509_NAME* caName = NULL;
  53681. X509_NAME* issuerName = NULL;
  53682. XFILE file1 = XBADFILE;
  53683. int i;
  53684. int cert_count = 0;
  53685. int cmp;
  53686. char der[] = "certs/ca-cert.der";
  53687. #ifdef HAVE_CRL
  53688. char pem[][100] = {
  53689. "./certs/crl/crl.pem",
  53690. "./certs/crl/crl2.pem",
  53691. "./certs/crl/caEccCrl.pem",
  53692. "./certs/crl/eccCliCRL.pem",
  53693. "./certs/crl/eccSrvCRL.pem",
  53694. ""
  53695. };
  53696. #endif
  53697. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  53698. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  53699. if (file1 != XBADFILE)
  53700. XFCLOSE(file1);
  53701. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53702. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53703. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53704. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53705. SSL_FILETYPE_PEM,NULL), 1);
  53706. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53707. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53708. /* check if CA cert is loaded into the store */
  53709. for (i = 0; i < cert_count; i++) {
  53710. x509Ca = sk_X509_value(sk, i);
  53711. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53712. }
  53713. ExpectNotNull((x509Svr =
  53714. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53715. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53716. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53717. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  53718. ExpectNotNull(issuer);
  53719. caName = X509_get_subject_name(x509Ca);
  53720. ExpectNotNull(caName);
  53721. issuerName = X509_get_subject_name(issuer);
  53722. ExpectNotNull(issuerName);
  53723. cmp = X509_NAME_cmp(caName, issuerName);
  53724. ExpectIntEQ(cmp, 0);
  53725. /* load der format */
  53726. X509_free(issuer);
  53727. issuer = NULL;
  53728. X509_STORE_CTX_free(ctx);
  53729. ctx = NULL;
  53730. X509_STORE_free(str);
  53731. str = NULL;
  53732. sk_X509_pop_free(sk, NULL);
  53733. sk = NULL;
  53734. X509_free(x509Svr);
  53735. x509Svr = NULL;
  53736. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53737. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53738. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  53739. SSL_FILETYPE_ASN1,NULL), 1);
  53740. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53741. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53742. /* check if CA cert is loaded into the store */
  53743. for (i = 0; i < cert_count; i++) {
  53744. x509Ca = sk_X509_value(sk, i);
  53745. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53746. }
  53747. X509_STORE_free(str);
  53748. str = NULL;
  53749. sk_X509_pop_free(sk, NULL);
  53750. sk = NULL;
  53751. X509_free(cert1);
  53752. cert1 = NULL;
  53753. #ifdef HAVE_CRL
  53754. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  53755. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53756. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53757. SSL_FILETYPE_PEM,NULL), 1);
  53758. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  53759. "certs/server-revoked-cert.pem",
  53760. SSL_FILETYPE_PEM,NULL), 1);
  53761. if (str) {
  53762. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  53763. WOLFSSL_FILETYPE_PEM), 1);
  53764. /* since store hasn't yet known the revoked cert*/
  53765. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53766. "certs/server-revoked-cert.pem",
  53767. WOLFSSL_FILETYPE_PEM), 1);
  53768. }
  53769. for (i = 0; pem[i][0] != '\0'; i++)
  53770. {
  53771. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  53772. SSL_FILETYPE_PEM, NULL), 1);
  53773. }
  53774. if (str) {
  53775. /* since store knows crl list */
  53776. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53777. "certs/server-revoked-cert.pem",
  53778. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  53779. }
  53780. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  53781. X509_STORE_free(str);
  53782. #endif
  53783. #endif
  53784. return EXPECT_RESULT();
  53785. }
  53786. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  53787. {
  53788. int res = TEST_SKIPPED;
  53789. #if defined(OPENSSL_EXTRA)
  53790. X509_STORE_CTX_cleanup(NULL);
  53791. X509_STORE_CTX_trusted_stack(NULL, NULL);
  53792. res = TEST_SUCCESS;
  53793. #endif
  53794. return res;
  53795. }
  53796. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  53797. {
  53798. EXPECT_DECLS;
  53799. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53800. X509_STORE_CTX* ctx = NULL;
  53801. X509_STORE* str = NULL;
  53802. X509* x509Ca = NULL;
  53803. X509* x509Svr = NULL;
  53804. X509* issuer = NULL;
  53805. X509_NAME* caName = NULL;
  53806. X509_NAME* issuerName = NULL;
  53807. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53808. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53809. ExpectNotNull((x509Ca =
  53810. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  53811. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  53812. ExpectNotNull((x509Svr =
  53813. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53814. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53815. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53816. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  53817. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  53818. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  53819. #ifdef WOLFSSL_SIGNER_DER_CERT
  53820. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  53821. #endif
  53822. X509_free(issuer);
  53823. X509_STORE_CTX_free(ctx);
  53824. X509_free(x509Svr);
  53825. X509_STORE_free(str);
  53826. X509_free(x509Ca);
  53827. #endif
  53828. return EXPECT_RESULT();
  53829. }
  53830. static int test_wolfSSL_PKCS7_certs(void)
  53831. {
  53832. EXPECT_DECLS;
  53833. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  53834. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  53835. STACK_OF(X509)* sk = NULL;
  53836. STACK_OF(X509_INFO)* info_sk = NULL;
  53837. PKCS7 *p7 = NULL;
  53838. BIO* bio = NULL;
  53839. const byte* p = NULL;
  53840. int buflen = 0;
  53841. int i;
  53842. /* Test twice. Once with d2i and once without to test
  53843. * that everything is free'd correctly. */
  53844. for (i = 0; i < 2; i++) {
  53845. ExpectNotNull(p7 = PKCS7_new());
  53846. if (p7 != NULL) {
  53847. p7->version = 1;
  53848. #ifdef NO_SHA
  53849. p7->hashOID = SHA256h;
  53850. #else
  53851. p7->hashOID = SHAh;
  53852. #endif
  53853. }
  53854. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  53855. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  53856. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  53857. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  53858. ExpectNotNull(sk = sk_X509_new_null());
  53859. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  53860. X509_INFO* info = NULL;
  53861. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  53862. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  53863. if (EXPECT_SUCCESS() && (info != NULL)) {
  53864. info->x509 = NULL;
  53865. }
  53866. X509_INFO_free(info);
  53867. }
  53868. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  53869. info_sk = NULL;
  53870. BIO_free(bio);
  53871. bio = NULL;
  53872. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  53873. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  53874. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  53875. sk_X509_pop_free(sk, X509_free);
  53876. }
  53877. sk = NULL;
  53878. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  53879. if (i == 0) {
  53880. PKCS7_free(p7);
  53881. p7 = NULL;
  53882. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  53883. if (p7 != NULL) {
  53884. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  53885. * them */
  53886. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  53887. }
  53888. /* PKCS7_free free's the certs */
  53889. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  53890. }
  53891. BIO_free(bio);
  53892. bio = NULL;
  53893. PKCS7_free(p7);
  53894. p7 = NULL;
  53895. }
  53896. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53897. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  53898. return EXPECT_RESULT();
  53899. }
  53900. static int test_wolfSSL_X509_STORE_CTX(void)
  53901. {
  53902. EXPECT_DECLS;
  53903. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53904. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53905. X509_STORE_CTX* ctx = NULL;
  53906. X509_STORE* str = NULL;
  53907. X509* x509 = NULL;
  53908. #ifdef OPENSSL_ALL
  53909. X509* x5092 = NULL;
  53910. STACK_OF(X509) *sk = NULL;
  53911. STACK_OF(X509) *sk2 = NULL;
  53912. STACK_OF(X509) *sk3 = NULL;
  53913. #endif
  53914. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53915. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53916. ExpectNotNull((x509 =
  53917. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53918. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  53919. #ifdef OPENSSL_ALL
  53920. /* sk_X509_new only in OPENSSL_ALL */
  53921. sk = sk_X509_new_null();
  53922. ExpectNotNull(sk);
  53923. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  53924. #else
  53925. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  53926. #endif
  53927. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  53928. X509_STORE_CTX_set_error(ctx, -5);
  53929. X509_STORE_CTX_set_error(NULL, -5);
  53930. X509_STORE_CTX_free(ctx);
  53931. ctx = NULL;
  53932. #ifdef OPENSSL_ALL
  53933. sk_X509_pop_free(sk, NULL);
  53934. sk = NULL;
  53935. #endif
  53936. X509_STORE_free(str);
  53937. str = NULL;
  53938. X509_free(x509);
  53939. x509 = NULL;
  53940. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53941. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  53942. X509_STORE_CTX_free(ctx);
  53943. ctx = NULL;
  53944. #ifdef OPENSSL_ALL
  53945. /* test X509_STORE_CTX_get(1)_chain */
  53946. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  53947. SSL_FILETYPE_PEM)));
  53948. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  53949. SSL_FILETYPE_PEM)));
  53950. ExpectNotNull((sk = sk_X509_new_null()));
  53951. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  53952. if (EXPECT_FAIL()) {
  53953. X509_free(x509);
  53954. x509 = NULL;
  53955. }
  53956. ExpectNotNull((str = X509_STORE_new()));
  53957. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  53958. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  53959. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  53960. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  53961. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  53962. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  53963. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  53964. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  53965. X509_STORE_CTX_free(ctx);
  53966. ctx = NULL;
  53967. X509_STORE_free(str);
  53968. str = NULL;
  53969. /* CTX certs not freed yet */
  53970. X509_free(x5092);
  53971. x5092 = NULL;
  53972. sk_X509_pop_free(sk, NULL);
  53973. sk = NULL;
  53974. /* sk3 is dup so free here */
  53975. sk_X509_pop_free(sk3, NULL);
  53976. sk3 = NULL;
  53977. #endif
  53978. /* test X509_STORE_CTX_get/set_ex_data */
  53979. {
  53980. int i = 0, tmpData = 5;
  53981. void* tmpDataRet;
  53982. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53983. #ifdef HAVE_EX_DATA
  53984. for (i = 0; i < MAX_EX_DATA; i++) {
  53985. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53986. WOLFSSL_SUCCESS);
  53987. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53988. ExpectNotNull(tmpDataRet);
  53989. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53990. }
  53991. #else
  53992. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53993. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53994. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53995. ExpectNull(tmpDataRet);
  53996. #endif
  53997. X509_STORE_CTX_free(ctx);
  53998. ctx = NULL;
  53999. }
  54000. /* test X509_STORE_get/set_ex_data */
  54001. {
  54002. int i = 0, tmpData = 99;
  54003. void* tmpDataRet;
  54004. ExpectNotNull(str = X509_STORE_new());
  54005. #ifdef HAVE_EX_DATA
  54006. for (i = 0; i < MAX_EX_DATA; i++) {
  54007. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54008. WOLFSSL_SUCCESS);
  54009. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54010. ExpectNotNull(tmpDataRet);
  54011. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54012. }
  54013. #else
  54014. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54015. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54016. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54017. ExpectNull(tmpDataRet);
  54018. #endif
  54019. X509_STORE_free(str);
  54020. str = NULL;
  54021. }
  54022. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54023. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54024. return EXPECT_RESULT();
  54025. }
  54026. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54027. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  54028. STACK_OF(X509)* chain)
  54029. {
  54030. EXPECT_DECLS;
  54031. XFILE fp = XBADFILE;
  54032. X509* cert = NULL;
  54033. ExpectTrue((fp = XFOPEN(filename, "rb"))
  54034. != XBADFILE);
  54035. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54036. if (fp != XBADFILE) {
  54037. XFCLOSE(fp);
  54038. fp = XBADFILE;
  54039. }
  54040. ExpectIntGT(sk_X509_push(chain, cert), 0);
  54041. if (EXPECT_FAIL())
  54042. X509_free(cert);
  54043. return EXPECT_RESULT();
  54044. }
  54045. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  54046. int err, int loadCA)
  54047. {
  54048. EXPECT_DECLS;
  54049. X509_STORE_CTX* ctx = NULL;
  54050. X509_STORE* str = NULL;
  54051. XFILE fp = XBADFILE;
  54052. X509* cert = NULL;
  54053. STACK_OF(X509)* untrusted = NULL;
  54054. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  54055. != XBADFILE);
  54056. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54057. if (fp != XBADFILE) {
  54058. XFCLOSE(fp);
  54059. fp = XBADFILE;
  54060. }
  54061. ExpectNotNull(str = X509_STORE_new());
  54062. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54063. ExpectNotNull(untrusted = sk_X509_new_null());
  54064. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  54065. if (loadCA) {
  54066. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  54067. 1);
  54068. }
  54069. for (; *filenames; filenames++) {
  54070. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  54071. untrusted), TEST_SUCCESS);
  54072. }
  54073. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  54074. ExpectIntEQ(X509_verify_cert(ctx), ret);
  54075. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  54076. X509_free(cert);
  54077. X509_STORE_free(str);
  54078. X509_STORE_CTX_free(ctx);
  54079. sk_X509_pop_free(untrusted, NULL);
  54080. return EXPECT_RESULT();
  54081. }
  54082. #endif
  54083. static int test_X509_STORE_untrusted(void)
  54084. {
  54085. EXPECT_DECLS;
  54086. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54087. const char* untrusted1[] = {
  54088. "./certs/intermediate/ca-int2-cert.pem",
  54089. NULL
  54090. };
  54091. const char* untrusted2[] = {
  54092. "./certs/intermediate/ca-int-cert.pem",
  54093. "./certs/intermediate/ca-int2-cert.pem",
  54094. NULL
  54095. };
  54096. const char* untrusted3[] = {
  54097. "./certs/intermediate/ca-int-cert.pem",
  54098. "./certs/intermediate/ca-int2-cert.pem",
  54099. "./certs/ca-cert.pem",
  54100. NULL
  54101. };
  54102. /* Adding unrelated certs that should be ignored */
  54103. const char* untrusted4[] = {
  54104. "./certs/client-ca.pem",
  54105. "./certs/intermediate/ca-int-cert.pem",
  54106. "./certs/server-cert.pem",
  54107. "./certs/intermediate/ca-int2-cert.pem",
  54108. NULL
  54109. };
  54110. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  54111. * to loaded CA. */
  54112. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  54113. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  54114. /* Succeeds because path to loaded CA is available. */
  54115. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  54116. TEST_SUCCESS);
  54117. /* Fails because root CA is in the untrusted stack */
  54118. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  54119. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  54120. /* Succeeds because path to loaded CA is available. */
  54121. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  54122. TEST_SUCCESS);
  54123. #endif
  54124. return EXPECT_RESULT();
  54125. }
  54126. static int test_wolfSSL_X509_STORE_set_flags(void)
  54127. {
  54128. EXPECT_DECLS;
  54129. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54130. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54131. X509_STORE* store = NULL;
  54132. X509* x509 = NULL;
  54133. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  54134. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  54135. WOLFSSL_FILETYPE_PEM)));
  54136. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  54137. #ifdef HAVE_CRL
  54138. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54139. WOLFSSL_SUCCESS);
  54140. #else
  54141. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54142. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  54143. #endif
  54144. wolfSSL_X509_free(x509);
  54145. wolfSSL_X509_STORE_free(store);
  54146. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  54147. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54148. return EXPECT_RESULT();
  54149. }
  54150. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  54151. {
  54152. EXPECT_DECLS;
  54153. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  54154. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  54155. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  54156. WOLFSSL_X509_STORE* store = NULL;
  54157. WOLFSSL_X509_LOOKUP* lookup = NULL;
  54158. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  54159. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  54160. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  54161. X509_FILETYPE_PEM), 1);
  54162. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  54163. X509_FILETYPE_PEM), 1);
  54164. if (store != NULL) {
  54165. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  54166. WOLFSSL_FILETYPE_PEM), 1);
  54167. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54168. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  54169. }
  54170. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  54171. X509_FILETYPE_PEM), 1);
  54172. if (store != NULL) {
  54173. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54174. WOLFSSL_FILETYPE_PEM), 1);
  54175. }
  54176. wolfSSL_X509_STORE_free(store);
  54177. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  54178. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54179. return EXPECT_RESULT();
  54180. }
  54181. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  54182. {
  54183. EXPECT_DECLS;
  54184. #if defined(OPENSSL_EXTRA)
  54185. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  54186. time_t c_time;
  54187. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  54188. c_time = 365*24*60*60;
  54189. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  54190. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  54191. WOLFSSL_USE_CHECK_TIME);
  54192. ExpectTrue(ctx->param->check_time == c_time);
  54193. wolfSSL_X509_STORE_CTX_free(ctx);
  54194. #endif /* OPENSSL_EXTRA */
  54195. return EXPECT_RESULT();
  54196. }
  54197. static int test_wolfSSL_CTX_get0_set1_param(void)
  54198. {
  54199. EXPECT_DECLS;
  54200. #if defined(OPENSSL_EXTRA)
  54201. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54202. SSL_CTX* ctx = NULL;
  54203. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54204. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  54205. char testIPv4[] = "127.0.0.1";
  54206. char testhostName[] = "foo.hoge.com";
  54207. #ifndef NO_WOLFSSL_SERVER
  54208. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54209. #else
  54210. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54211. #endif
  54212. ExpectNull(SSL_CTX_get0_param(NULL));
  54213. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  54214. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  54215. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  54216. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  54217. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  54218. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  54219. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  54220. WOLFSSL_SUCCESS);
  54221. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  54222. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  54223. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  54224. (int)XSTRLEN(testhostName)));
  54225. ExpectIntEQ(0x01, pParam->hostFlags);
  54226. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  54227. /* test for incorrect parameter */
  54228. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  54229. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  54230. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  54231. SSL_CTX_free(ctx);
  54232. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  54233. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54234. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  54235. return EXPECT_RESULT();
  54236. }
  54237. static int test_wolfSSL_get0_param(void)
  54238. {
  54239. EXPECT_DECLS;
  54240. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54241. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54242. SSL_CTX* ctx = NULL;
  54243. SSL* ssl = NULL;
  54244. #ifndef NO_WOLFSSL_SERVER
  54245. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54246. #else
  54247. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54248. #endif
  54249. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54250. SSL_FILETYPE_PEM));
  54251. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54252. ExpectNotNull(ssl = SSL_new(ctx));
  54253. ExpectNotNull(SSL_get0_param(ssl));
  54254. SSL_free(ssl);
  54255. SSL_CTX_free(ctx);
  54256. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54257. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  54258. return EXPECT_RESULT();
  54259. }
  54260. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  54261. {
  54262. EXPECT_DECLS;
  54263. #if defined(OPENSSL_EXTRA)
  54264. const char host[] = "www.example.com";
  54265. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54266. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  54267. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  54268. if (pParam != NULL) {
  54269. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54270. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  54271. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54272. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54273. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54274. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54275. }
  54276. #endif /* OPENSSL_EXTRA */
  54277. return EXPECT_RESULT();
  54278. }
  54279. static int test_wolfSSL_set1_host(void)
  54280. {
  54281. EXPECT_DECLS;
  54282. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54283. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54284. const char host[] = "www.test_wolfSSL_set1_host.com";
  54285. const char emptyStr[] = "";
  54286. SSL_CTX* ctx = NULL;
  54287. SSL* ssl = NULL;
  54288. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54289. #ifndef NO_WOLFSSL_SERVER
  54290. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54291. #else
  54292. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54293. #endif
  54294. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54295. SSL_FILETYPE_PEM));
  54296. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54297. ExpectNotNull(ssl = SSL_new(ctx));
  54298. pParam = SSL_get0_param(ssl);
  54299. /* we should get back host string */
  54300. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54301. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54302. /* we should get back empty string */
  54303. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  54304. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54305. /* we should get back host string */
  54306. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54307. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54308. /* we should get back empty string */
  54309. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  54310. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54311. SSL_free(ssl);
  54312. SSL_CTX_free(ctx);
  54313. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54314. #endif /* OPENSSL_EXTRA */
  54315. return EXPECT_RESULT();
  54316. }
  54317. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  54318. {
  54319. EXPECT_DECLS;
  54320. #if defined(OPENSSL_EXTRA)
  54321. unsigned char buf[16] = {0};
  54322. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  54323. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  54324. /* test 127.0.0.1 */
  54325. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  54326. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  54327. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  54328. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  54329. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54330. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  54331. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  54332. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  54333. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54334. ExpectIntEQ(XSTRNCMP(param->ipasc,
  54335. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  54336. /* test 2001:db8:: */
  54337. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54338. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54339. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54340. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  54341. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54342. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  54343. /* test ::1234:5678 */
  54344. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  54345. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54346. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54347. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54348. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54349. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  54350. /* test 2001:db8::1234:5678 */
  54351. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54352. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54353. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54354. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54355. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54356. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  54357. sizeof(param->ipasc)), 0);
  54358. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  54359. /* 2001:db8:1::ab9:c0a8:102 */
  54360. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54361. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  54362. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  54363. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  54364. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54365. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  54366. sizeof(param->ipasc)), 0);
  54367. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54368. #endif /* OPENSSL_EXTRA */
  54369. return EXPECT_RESULT();
  54370. }
  54371. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  54372. {
  54373. EXPECT_DECLS;
  54374. #if defined(OPENSSL_EXTRA)
  54375. X509_STORE* store = NULL;
  54376. X509_STORE_CTX* ctx = NULL;
  54377. X509_STORE_CTX* ctx_no_init = NULL;
  54378. ExpectNotNull((store = X509_STORE_new()));
  54379. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54380. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  54381. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  54382. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  54383. /* should return NULL if ctx has not bee initialized */
  54384. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  54385. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  54386. wolfSSL_X509_STORE_CTX_free(ctx);
  54387. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  54388. X509_STORE_free(store);
  54389. #endif /* OPENSSL_EXTRA */
  54390. return EXPECT_RESULT();
  54391. }
  54392. static int test_wolfSSL_CTX_set_client_CA_list(void)
  54393. {
  54394. EXPECT_DECLS;
  54395. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54396. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  54397. WOLFSSL_CTX* ctx = NULL;
  54398. WOLFSSL* ssl = NULL;
  54399. X509_NAME* name = NULL;
  54400. STACK_OF(X509_NAME)* names = NULL;
  54401. STACK_OF(X509_NAME)* ca_list = NULL;
  54402. int names_len = 0;
  54403. int i;
  54404. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  54405. /* Send two X501 names in cert request */
  54406. names = SSL_load_client_CA_file(cliCertFile);
  54407. ExpectNotNull(names);
  54408. ca_list = SSL_load_client_CA_file(caCertFile);
  54409. ExpectNotNull(ca_list);
  54410. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  54411. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  54412. if (EXPECT_FAIL()) {
  54413. wolfSSL_X509_NAME_free(name);
  54414. name = NULL;
  54415. }
  54416. SSL_CTX_set_client_CA_list(ctx, names);
  54417. /* This should only free the stack structure */
  54418. sk_X509_NAME_free(ca_list);
  54419. ca_list = NULL;
  54420. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54421. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54422. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54423. for (i = 0; i < names_len; i++) {
  54424. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54425. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54426. }
  54427. /* Needed to be able to create ssl object */
  54428. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54429. SSL_FILETYPE_PEM));
  54430. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54431. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54432. /* load again as old names are responsibility of ctx to free*/
  54433. names = SSL_load_client_CA_file(cliCertFile);
  54434. ExpectNotNull(names);
  54435. SSL_set_client_CA_list(ssl, names);
  54436. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  54437. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54438. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54439. for (i = 0; i < names_len; i++) {
  54440. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54441. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54442. }
  54443. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  54444. {
  54445. tcp_ready ready;
  54446. func_args server_args;
  54447. callback_functions server_cb;
  54448. THREAD_TYPE serverThread;
  54449. WOLFSSL* ssl_client = NULL;
  54450. WOLFSSL_CTX* ctx_client = NULL;
  54451. SOCKET_T sockfd = 0;
  54452. /* wolfSSL_get_client_CA_list() with handshake */
  54453. StartTCP();
  54454. InitTcpReady(&ready);
  54455. XMEMSET(&server_args, 0, sizeof(func_args));
  54456. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54457. server_args.signal = &ready;
  54458. server_args.callbacks = &server_cb;
  54459. /* we are responsible for free'ing WOLFSSL_CTX */
  54460. server_cb.ctx = ctx;
  54461. server_cb.isSharedCtx = 1;
  54462. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  54463. cliCertFile, 0));
  54464. start_thread(test_server_nofail, &server_args, &serverThread);
  54465. wait_tcp_ready(&server_args);
  54466. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54467. ExpectNotNull(ctx_client =
  54468. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  54469. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  54470. ctx_client, caCertFile, 0));
  54471. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  54472. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  54473. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  54474. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  54475. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  54476. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  54477. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  54478. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  54479. /* We are expecting two cert names to be sent */
  54480. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  54481. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  54482. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  54483. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  54484. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  54485. }
  54486. wolfSSL_shutdown(ssl_client);
  54487. wolfSSL_free(ssl_client);
  54488. wolfSSL_CTX_free(ctx_client);
  54489. CloseSocket(sockfd);
  54490. join_thread(serverThread);
  54491. FreeTcpReady(&ready);
  54492. }
  54493. #endif
  54494. wolfSSL_free(ssl);
  54495. wolfSSL_CTX_free(ctx);
  54496. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  54497. * !NO_BIO */
  54498. return EXPECT_RESULT();
  54499. }
  54500. static int test_wolfSSL_CTX_add_client_CA(void)
  54501. {
  54502. EXPECT_DECLS;
  54503. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54504. !defined(NO_WOLFSSL_CLIENT)
  54505. WOLFSSL_CTX* ctx = NULL;
  54506. WOLFSSL_X509* x509 = NULL;
  54507. WOLFSSL_X509* x509_a = NULL;
  54508. STACK_OF(X509_NAME)* ca_list = NULL;
  54509. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54510. /* Add client cert */
  54511. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  54512. SSL_FILETYPE_PEM));
  54513. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  54514. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54515. /* Add another client cert */
  54516. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  54517. SSL_FILETYPE_PEM));
  54518. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  54519. /* test for incorrect parameter */
  54520. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  54521. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  54522. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  54523. X509_free(x509);
  54524. X509_free(x509_a);
  54525. SSL_CTX_free(ctx);
  54526. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  54527. return EXPECT_RESULT();
  54528. }
  54529. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54530. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54531. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  54532. {
  54533. callback_functions* callbacks = ((func_args*)args)->callbacks;
  54534. WOLFSSL_CTX* ctx = callbacks->ctx;
  54535. WOLFSSL* ssl = NULL;
  54536. SOCKET_T sfd = 0;
  54537. SOCKET_T cfd = 0;
  54538. word16 port;
  54539. char input[1024];
  54540. int idx;
  54541. int ret, err = 0;
  54542. const char* privateName = "ech-private-name.com";
  54543. int privateNameLen = (int)XSTRLEN(privateName);
  54544. ((func_args*)args)->return_code = TEST_FAIL;
  54545. port = ((func_args*)args)->signal->port;
  54546. AssertIntEQ(WOLFSSL_SUCCESS,
  54547. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  54548. AssertIntEQ(WOLFSSL_SUCCESS,
  54549. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  54550. WOLFSSL_FILETYPE_PEM));
  54551. AssertIntEQ(WOLFSSL_SUCCESS,
  54552. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54553. WOLFSSL_FILETYPE_PEM));
  54554. if (callbacks->ctx_ready)
  54555. callbacks->ctx_ready(ctx);
  54556. ssl = wolfSSL_new(ctx);
  54557. /* set the sni for the server */
  54558. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  54559. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  54560. CloseSocket(sfd);
  54561. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  54562. if (callbacks->ssl_ready)
  54563. callbacks->ssl_ready(ssl);
  54564. do {
  54565. err = 0; /* Reset error */
  54566. ret = wolfSSL_accept(ssl);
  54567. if (ret != WOLFSSL_SUCCESS) {
  54568. err = wolfSSL_get_error(ssl, 0);
  54569. }
  54570. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  54571. if (ret != WOLFSSL_SUCCESS) {
  54572. char buff[WOLFSSL_MAX_ERROR_SZ];
  54573. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  54574. }
  54575. else {
  54576. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  54577. input[idx] = 0;
  54578. fprintf(stderr, "Client message: %s\n", input);
  54579. }
  54580. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  54581. privateNameLen));
  54582. ((func_args*)args)->return_code = TEST_SUCCESS;
  54583. }
  54584. if (callbacks->on_result)
  54585. callbacks->on_result(ssl);
  54586. wolfSSL_shutdown(ssl);
  54587. wolfSSL_free(ssl);
  54588. wolfSSL_CTX_free(ctx);
  54589. CloseSocket(cfd);
  54590. #ifdef FP_ECC
  54591. wc_ecc_fp_free();
  54592. #endif
  54593. WOLFSSL_RETURN_FROM_THREAD(0);
  54594. }
  54595. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54596. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54597. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  54598. {
  54599. XFILE fp;
  54600. const byte lf = '\n';
  54601. AssertNotNull(ssl);
  54602. AssertNotNull(line);
  54603. fp = XFOPEN("./MyKeyLog.txt", "a");
  54604. XFWRITE(line, 1, XSTRLEN(line), fp);
  54605. XFWRITE((void*)&lf, 1, 1, fp);
  54606. XFFLUSH(fp);
  54607. XFCLOSE(fp);
  54608. }
  54609. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54610. static int test_wolfSSL_CTX_set_keylog_callback(void)
  54611. {
  54612. EXPECT_DECLS;
  54613. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54614. !defined(NO_WOLFSSL_CLIENT)
  54615. SSL_CTX* ctx = NULL;
  54616. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54617. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54618. SSL_CTX_free(ctx);
  54619. SSL_CTX_set_keylog_callback(NULL, NULL);
  54620. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54621. return EXPECT_RESULT();
  54622. }
  54623. static int test_wolfSSL_CTX_get_keylog_callback(void)
  54624. {
  54625. EXPECT_DECLS;
  54626. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54627. !defined(NO_WOLFSSL_CLIENT)
  54628. SSL_CTX* ctx = NULL;
  54629. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54630. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54631. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54632. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  54633. SSL_CTX_set_keylog_callback(ctx, NULL );
  54634. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54635. SSL_CTX_free(ctx);
  54636. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54637. return EXPECT_RESULT();
  54638. }
  54639. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54640. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54641. {
  54642. /* set keylog callback */
  54643. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54644. return TEST_SUCCESS;
  54645. }
  54646. #endif
  54647. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  54648. {
  54649. EXPECT_DECLS;
  54650. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54651. /* This test is intended for checking whether keylog callback is called
  54652. * in client during TLS handshake between the client and a server.
  54653. */
  54654. test_ssl_cbf server_cbf;
  54655. test_ssl_cbf client_cbf;
  54656. XFILE fp = XBADFILE;
  54657. char buff[500];
  54658. int found = 0;
  54659. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54660. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54661. server_cbf.method = wolfTLSv1_2_server_method;
  54662. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  54663. /* clean up keylog file */
  54664. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54665. if (fp != XBADFILE) {
  54666. XFFLUSH(fp);
  54667. XFCLOSE(fp);
  54668. fp = XBADFILE;
  54669. }
  54670. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54671. &server_cbf, NULL), TEST_SUCCESS);
  54672. /* check if the keylog file exists */
  54673. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54674. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  54675. XMEMSET(buff, 0, sizeof(buff));
  54676. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54677. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  54678. found = 1;
  54679. break;
  54680. }
  54681. }
  54682. if (fp != XBADFILE) {
  54683. XFCLOSE(fp);
  54684. }
  54685. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  54686. ExpectIntEQ(found, 1);
  54687. /* clean up */
  54688. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  54689. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54690. return EXPECT_RESULT();
  54691. }
  54692. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54693. defined(HAVE_SECRET_CALLBACK)
  54694. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54695. {
  54696. /* set keylog callback */
  54697. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54698. return TEST_SUCCESS;
  54699. }
  54700. #endif
  54701. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  54702. {
  54703. EXPECT_DECLS;
  54704. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54705. defined(HAVE_SECRET_CALLBACK)
  54706. /* This test is intended for checking whether keylog callback is called
  54707. * in client during TLS handshake between the client and a server.
  54708. */
  54709. test_ssl_cbf server_cbf;
  54710. test_ssl_cbf client_cbf;
  54711. XFILE fp = XBADFILE;
  54712. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54713. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54714. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54715. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  54716. /* clean up keylog file */
  54717. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54718. if (fp != XBADFILE) {
  54719. XFCLOSE(fp);
  54720. fp = XBADFILE;
  54721. }
  54722. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54723. &server_cbf, NULL), TEST_SUCCESS);
  54724. /* check if the keylog file exists */
  54725. {
  54726. char buff[300] = {0};
  54727. int found[4] = {0};
  54728. int numfnd = 0;
  54729. int i;
  54730. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54731. while (EXPECT_SUCCESS() &&
  54732. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54733. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  54734. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54735. found[0] = 1;
  54736. continue;
  54737. }
  54738. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  54739. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54740. found[1] = 1;
  54741. continue;
  54742. }
  54743. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  54744. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  54745. found[2] = 1;
  54746. continue;
  54747. }
  54748. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  54749. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  54750. found[3] = 1;
  54751. continue;
  54752. }
  54753. }
  54754. if (fp != XBADFILE)
  54755. XFCLOSE(fp);
  54756. for (i = 0; i < 4; i++) {
  54757. if (found[i] != 0)
  54758. numfnd++;
  54759. }
  54760. ExpectIntEQ(numfnd, 4);
  54761. }
  54762. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  54763. return EXPECT_RESULT();
  54764. }
  54765. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54766. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54767. static int test_wolfSSL_Tls13_ECH_params(void)
  54768. {
  54769. EXPECT_DECLS;
  54770. #if !defined(NO_WOLFSSL_CLIENT)
  54771. word32 outputLen = 0;
  54772. byte testBuf[72];
  54773. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  54774. WOLFSSL *ssl = wolfSSL_new(ctx);
  54775. ExpectNotNull(ctx);
  54776. ExpectNotNull(ssl);
  54777. /* invalid ctx */
  54778. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  54779. "ech-public-name.com", 0, 0, 0));
  54780. /* invalid public name */
  54781. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  54782. 0, 0));
  54783. /* invalid algorithms */
  54784. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  54785. "ech-public-name.com", 1000, 1000, 1000));
  54786. /* invalid ctx */
  54787. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  54788. &outputLen));
  54789. /* invalid output len */
  54790. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  54791. /* invalid ssl */
  54792. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  54793. (char*)testBuf, sizeof(testBuf)));
  54794. /* invalid configs64 */
  54795. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  54796. sizeof(testBuf)));
  54797. /* invalid size */
  54798. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  54799. (char*)testBuf, 0));
  54800. /* invalid ssl */
  54801. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  54802. sizeof(testBuf)));
  54803. /* invalid configs */
  54804. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  54805. sizeof(testBuf)));
  54806. /* invalid size */
  54807. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  54808. /* invalid ssl */
  54809. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  54810. /* invalid size */
  54811. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  54812. wolfSSL_free(ssl);
  54813. wolfSSL_CTX_free(ctx);
  54814. #endif /* !NO_WOLFSSL_CLIENT */
  54815. return EXPECT_RESULT();
  54816. }
  54817. static int test_wolfSSL_Tls13_ECH(void)
  54818. {
  54819. EXPECT_DECLS;
  54820. tcp_ready ready;
  54821. func_args client_args;
  54822. func_args server_args;
  54823. THREAD_TYPE serverThread;
  54824. callback_functions server_cbf;
  54825. callback_functions client_cbf;
  54826. SOCKET_T sockfd = 0;
  54827. WOLFSSL_CTX* ctx = NULL;
  54828. WOLFSSL* ssl = NULL;
  54829. const char* publicName = "ech-public-name.com";
  54830. const char* privateName = "ech-private-name.com";
  54831. int privateNameLen = 20;
  54832. char reply[1024];
  54833. int replyLen = 0;
  54834. byte rawEchConfig[128];
  54835. word32 rawEchConfigLen = sizeof(rawEchConfig);
  54836. InitTcpReady(&ready);
  54837. ready.port = 22222;
  54838. XMEMSET(&client_args, 0, sizeof(func_args));
  54839. XMEMSET(&server_args, 0, sizeof(func_args));
  54840. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  54841. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  54842. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54843. /* create the server context here so we can get the ech config */
  54844. ExpectNotNull(server_cbf.ctx =
  54845. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  54846. /* generate ech config */
  54847. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  54848. publicName, 0, 0, 0));
  54849. /* get the config for the client to use */
  54850. ExpectIntEQ(WOLFSSL_SUCCESS,
  54851. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  54852. &rawEchConfigLen));
  54853. server_args.callbacks = &server_cbf;
  54854. server_args.signal = &ready;
  54855. /* start server task */
  54856. start_thread(server_task_ech, &server_args, &serverThread);
  54857. wait_tcp_ready(&server_args);
  54858. /* run as a TLS1.3 client */
  54859. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  54860. ExpectIntEQ(WOLFSSL_SUCCESS,
  54861. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  54862. ExpectIntEQ(WOLFSSL_SUCCESS,
  54863. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  54864. ExpectIntEQ(WOLFSSL_SUCCESS,
  54865. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  54866. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54867. /* get connected the server task */
  54868. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54869. /* set the ech configs for the client */
  54870. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  54871. rawEchConfigLen));
  54872. /* set the sni for the client */
  54873. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  54874. privateName, privateNameLen));
  54875. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  54876. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54877. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  54878. privateNameLen);
  54879. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  54880. /* add th null terminator for string compare */
  54881. reply[replyLen] = 0;
  54882. /* check that the server replied with the private name */
  54883. ExpectStrEQ(privateName, reply);
  54884. wolfSSL_free(ssl);
  54885. wolfSSL_CTX_free(ctx);
  54886. CloseSocket(sockfd);
  54887. join_thread(serverThread);
  54888. FreeTcpReady(&ready);
  54889. return EXPECT_RESULT();
  54890. }
  54891. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54892. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54893. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54894. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54895. static int post_auth_version_cb(WOLFSSL* ssl)
  54896. {
  54897. EXPECT_DECLS;
  54898. /* do handshake and then test version error */
  54899. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54900. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54901. return EXPECT_RESULT();
  54902. }
  54903. static int post_auth_version_client_cb(WOLFSSL* ssl)
  54904. {
  54905. EXPECT_DECLS;
  54906. /* do handshake and then test version error */
  54907. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54908. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54909. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54910. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  54911. /* check was added to error queue */
  54912. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  54913. /* check the string matches expected string */
  54914. #ifndef NO_ERROR_STRINGS
  54915. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  54916. "WRONG_SSL_VERSION");
  54917. #endif
  54918. #endif
  54919. return EXPECT_RESULT();
  54920. }
  54921. static int post_auth_cb(WOLFSSL* ssl)
  54922. {
  54923. EXPECT_DECLS;
  54924. WOLFSSL_X509* x509 = NULL;
  54925. /* do handshake and then test version error */
  54926. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54927. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  54928. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  54929. wolfSSL_X509_free(x509);
  54930. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  54931. return EXPECT_RESULT();
  54932. }
  54933. static int set_post_auth_cb(WOLFSSL* ssl)
  54934. {
  54935. if (!wolfSSL_is_server(ssl)) {
  54936. EXPECT_DECLS;
  54937. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  54938. return EXPECT_RESULT();
  54939. }
  54940. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  54941. return TEST_SUCCESS;
  54942. }
  54943. #endif
  54944. static int test_wolfSSL_Tls13_postauth(void)
  54945. {
  54946. EXPECT_DECLS;
  54947. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54948. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54949. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54950. test_ssl_cbf server_cbf;
  54951. test_ssl_cbf client_cbf;
  54952. /* test version failure doing post auth with TLS 1.2 connection */
  54953. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54954. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54955. server_cbf.method = wolfTLSv1_2_server_method;
  54956. server_cbf.ssl_ready = set_post_auth_cb;
  54957. server_cbf.on_result = post_auth_version_cb;
  54958. client_cbf.ssl_ready = set_post_auth_cb;
  54959. client_cbf.on_result = post_auth_version_client_cb;
  54960. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54961. &server_cbf, NULL), TEST_SUCCESS);
  54962. /* tests on post auth with TLS 1.3 */
  54963. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54964. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54965. server_cbf.method = wolfTLSv1_3_server_method;
  54966. server_cbf.ssl_ready = set_post_auth_cb;
  54967. client_cbf.ssl_ready = set_post_auth_cb;
  54968. server_cbf.on_result = post_auth_cb;
  54969. client_cbf.on_result = NULL;
  54970. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54971. &server_cbf, NULL), TEST_SUCCESS);
  54972. #endif
  54973. return EXPECT_RESULT();
  54974. }
  54975. static int test_wolfSSL_X509_NID(void)
  54976. {
  54977. EXPECT_DECLS;
  54978. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  54979. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  54980. int sigType;
  54981. int nameSz;
  54982. X509* cert = NULL;
  54983. EVP_PKEY* pubKeyTmp = NULL;
  54984. X509_NAME* name = NULL;
  54985. char commonName[80];
  54986. char countryName[80];
  54987. char localityName[80];
  54988. char stateName[80];
  54989. char orgName[80];
  54990. char orgUnit[80];
  54991. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  54992. /* convert cert from DER to internal WOLFSSL_X509 struct */
  54993. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  54994. sizeof_client_cert_der_2048, HEAP_HINT));
  54995. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  54996. /* extract PUBLIC KEY from cert */
  54997. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  54998. /* extract signatureType */
  54999. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  55000. /* extract subjectName info */
  55001. ExpectNotNull(name = X509_get_subject_name(cert));
  55002. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  55003. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55004. NULL, 0)), 0);
  55005. ExpectIntEQ(nameSz, 15);
  55006. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55007. commonName, sizeof(commonName))), 0);
  55008. ExpectIntEQ(nameSz, 15);
  55009. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  55010. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55011. commonName, 9)), 0);
  55012. ExpectIntEQ(nameSz, 8);
  55013. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  55014. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  55015. countryName, sizeof(countryName))), 0);
  55016. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  55017. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  55018. localityName, sizeof(localityName))), 0);
  55019. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  55020. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55021. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  55022. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  55023. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  55024. orgName, sizeof(orgName))), 0);
  55025. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  55026. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55027. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  55028. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  55029. EVP_PKEY_free(pubKeyTmp);
  55030. X509_free(cert);
  55031. #endif
  55032. return EXPECT_RESULT();
  55033. }
  55034. static int test_wolfSSL_CTX_set_srp_username(void)
  55035. {
  55036. EXPECT_DECLS;
  55037. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  55038. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55039. WOLFSSL_CTX* ctx = NULL;
  55040. WOLFSSL* ssl = NULL;
  55041. const char *username = "TESTUSER";
  55042. const char *password = "TESTPASSWORD";
  55043. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55044. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55045. SSL_SUCCESS);
  55046. wolfSSL_CTX_free(ctx);
  55047. ctx = NULL;
  55048. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55049. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55050. SSL_SUCCESS);
  55051. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55052. SSL_SUCCESS);
  55053. ExpectNotNull(ssl = SSL_new(ctx));
  55054. ExpectNotNull(SSL_get_srp_username(ssl));
  55055. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  55056. wolfSSL_free(ssl);
  55057. wolfSSL_CTX_free(ctx);
  55058. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55059. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55060. return EXPECT_RESULT();
  55061. }
  55062. static int test_wolfSSL_CTX_set_srp_password(void)
  55063. {
  55064. EXPECT_DECLS;
  55065. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  55066. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55067. WOLFSSL_CTX* ctx = NULL;
  55068. const char *username = "TESTUSER";
  55069. const char *password = "TESTPASSWORD";
  55070. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55071. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55072. SSL_SUCCESS);
  55073. wolfSSL_CTX_free(ctx);
  55074. ctx = NULL;
  55075. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55076. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55077. SSL_SUCCESS);
  55078. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55079. SSL_SUCCESS);
  55080. wolfSSL_CTX_free(ctx);
  55081. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55082. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55083. return EXPECT_RESULT();
  55084. }
  55085. static int test_wolfSSL_X509_STORE(void)
  55086. {
  55087. EXPECT_DECLS;
  55088. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55089. X509_STORE *store = NULL;
  55090. #ifdef HAVE_CRL
  55091. X509_STORE_CTX *storeCtx = NULL;
  55092. X509 *ca = NULL;
  55093. X509 *cert = NULL;
  55094. const char srvCert[] = "./certs/server-revoked-cert.pem";
  55095. const char caCert[] = "./certs/ca-cert.pem";
  55096. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55097. X509_CRL *crl = NULL;
  55098. const char crlPem[] = "./certs/crl/crl.revoked";
  55099. XFILE fp = XBADFILE;
  55100. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55101. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55102. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55103. SSL_FILETYPE_PEM)));
  55104. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55105. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55106. SSL_FILETYPE_PEM)));
  55107. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55108. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55109. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55110. X509_STORE_free(store);
  55111. store = NULL;
  55112. X509_STORE_CTX_free(storeCtx);
  55113. storeCtx = NULL;
  55114. X509_free(cert);
  55115. cert = NULL;
  55116. X509_free(ca);
  55117. ca = NULL;
  55118. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55119. /* should fail to verify now after adding in CRL */
  55120. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55121. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55122. SSL_FILETYPE_PEM)));
  55123. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55124. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  55125. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  55126. NULL, NULL));
  55127. if (fp != XBADFILE)
  55128. XFCLOSE(fp);
  55129. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  55130. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  55131. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55132. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55133. SSL_FILETYPE_PEM)));
  55134. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55135. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55136. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  55137. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  55138. X509_CRL_free(crl);
  55139. crl = NULL;
  55140. X509_STORE_free(store);
  55141. store = NULL;
  55142. X509_STORE_CTX_free(storeCtx);
  55143. storeCtx = NULL;
  55144. X509_free(cert);
  55145. cert = NULL;
  55146. X509_free(ca);
  55147. ca = NULL;
  55148. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55149. #endif /* HAVE_CRL */
  55150. #ifndef WOLFCRYPT_ONLY
  55151. {
  55152. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55153. SSL_CTX* ctx = NULL;
  55154. SSL* ssl = NULL;
  55155. int i;
  55156. for (i = 0; i < 2; i++) {
  55157. #ifndef NO_WOLFSSL_SERVER
  55158. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55159. #else
  55160. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55161. #endif
  55162. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55163. SSL_CTX_set_cert_store(ctx, store);
  55164. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55165. SSL_CTX_set_cert_store(ctx, store);
  55166. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55167. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55168. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55169. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55170. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55171. ExpectNotNull(ssl = SSL_new(ctx));
  55172. if (i == 0) {
  55173. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  55174. SSL_SUCCESS);
  55175. }
  55176. else {
  55177. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  55178. #ifdef OPENSSL_ALL
  55179. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  55180. #endif
  55181. }
  55182. if (EXPECT_FAIL() || (i == 1)) {
  55183. X509_STORE_free(store);
  55184. store = NULL;
  55185. }
  55186. SSL_free(ssl);
  55187. ssl = NULL;
  55188. SSL_CTX_free(ctx);
  55189. ctx = NULL;
  55190. }
  55191. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55192. }
  55193. #endif
  55194. #endif
  55195. return EXPECT_RESULT();
  55196. }
  55197. static int test_wolfSSL_X509_STORE_load_locations(void)
  55198. {
  55199. EXPECT_DECLS;
  55200. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  55201. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  55202. SSL_CTX *ctx = NULL;
  55203. X509_STORE *store = NULL;
  55204. const char ca_file[] = "./certs/ca-cert.pem";
  55205. const char client_pem_file[] = "./certs/client-cert.pem";
  55206. const char client_der_file[] = "./certs/client-cert.der";
  55207. const char ecc_file[] = "./certs/ecc-key.pem";
  55208. const char certs_path[] = "./certs/";
  55209. const char bad_path[] = "./bad-path/";
  55210. #ifdef HAVE_CRL
  55211. const char crl_path[] = "./certs/crl/";
  55212. const char crl_file[] = "./certs/crl/crl.pem";
  55213. #endif
  55214. #ifndef NO_WOLFSSL_SERVER
  55215. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  55216. #else
  55217. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  55218. #endif
  55219. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  55220. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  55221. WOLFSSL_SUCCESS);
  55222. /* Test bad arguments */
  55223. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  55224. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55225. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55226. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  55227. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55228. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  55229. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55230. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  55231. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55232. #ifdef HAVE_CRL
  55233. /* Test with CRL */
  55234. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  55235. WOLFSSL_SUCCESS);
  55236. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  55237. WOLFSSL_SUCCESS);
  55238. #endif
  55239. /* Test with CA */
  55240. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  55241. WOLFSSL_SUCCESS);
  55242. /* Test with client_cert and certs path */
  55243. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  55244. WOLFSSL_SUCCESS);
  55245. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  55246. WOLFSSL_SUCCESS);
  55247. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  55248. /* Clear nodes */
  55249. ERR_clear_error();
  55250. #endif
  55251. SSL_CTX_free(ctx);
  55252. #endif
  55253. return EXPECT_RESULT();
  55254. }
  55255. static int test_X509_STORE_get0_objects(void)
  55256. {
  55257. EXPECT_DECLS;
  55258. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  55259. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  55260. X509_STORE *store = NULL;
  55261. X509_STORE *store_cpy = NULL;
  55262. SSL_CTX *ctx = NULL;
  55263. X509_OBJECT *obj = NULL;
  55264. STACK_OF(X509_OBJECT) *objs = NULL;
  55265. int i;
  55266. /* Setup store */
  55267. #ifndef NO_WOLFSSL_SERVER
  55268. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  55269. #else
  55270. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  55271. #endif
  55272. ExpectNotNull(store_cpy = X509_STORE_new());
  55273. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  55274. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  55275. WOLFSSL_SUCCESS);
  55276. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  55277. WOLFSSL_SUCCESS);
  55278. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  55279. WOLFSSL_SUCCESS);
  55280. #ifdef HAVE_CRL
  55281. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  55282. WOLFSSL_SUCCESS);
  55283. #endif
  55284. /* Store ready */
  55285. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  55286. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  55287. #ifdef HAVE_CRL
  55288. #ifdef WOLFSSL_SIGNER_DER_CERT
  55289. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  55290. #else
  55291. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  55292. #endif
  55293. #else
  55294. #ifdef WOLFSSL_SIGNER_DER_CERT
  55295. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  55296. #else
  55297. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  55298. #endif
  55299. #endif
  55300. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  55301. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  55302. switch (X509_OBJECT_get_type(obj)) {
  55303. case X509_LU_X509:
  55304. {
  55305. X509* x509 = NULL;
  55306. X509_NAME *subj_name = NULL;
  55307. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  55308. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  55309. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  55310. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  55311. subj_name));
  55312. break;
  55313. }
  55314. case X509_LU_CRL:
  55315. #ifdef HAVE_CRL
  55316. {
  55317. X509_CRL* crl = NULL;
  55318. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  55319. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  55320. break;
  55321. }
  55322. #endif
  55323. case X509_LU_NONE:
  55324. default:
  55325. Fail(("X509_OBJECT_get_type should return x509 or crl "
  55326. "(when built with crl support)"),
  55327. ("Unrecognized X509_OBJECT type or none"));
  55328. }
  55329. }
  55330. X509_STORE_free(store_cpy);
  55331. SSL_CTX_free(ctx);
  55332. #endif
  55333. return EXPECT_RESULT();
  55334. }
  55335. static int test_wolfSSL_BN_CTX(void)
  55336. {
  55337. EXPECT_DECLS;
  55338. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55339. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55340. WOLFSSL_BN_CTX* bn_ctx = NULL;
  55341. WOLFSSL_BIGNUM* t = NULL;
  55342. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  55343. /* No implementation. */
  55344. BN_CTX_init(NULL);
  55345. ExpectNotNull(t = BN_CTX_get(NULL));
  55346. BN_free(t);
  55347. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  55348. BN_free(t);
  55349. #ifndef NO_WOLFSSL_STUB
  55350. /* No implementation. */
  55351. BN_CTX_start(NULL);
  55352. BN_CTX_start(bn_ctx);
  55353. #endif
  55354. BN_CTX_free(NULL);
  55355. BN_CTX_free(bn_ctx);
  55356. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55357. return EXPECT_RESULT();
  55358. }
  55359. static int test_wolfSSL_BN(void)
  55360. {
  55361. EXPECT_DECLS;
  55362. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55363. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55364. BIGNUM* a = NULL;
  55365. BIGNUM* b = NULL;
  55366. BIGNUM* c = NULL;
  55367. BIGNUM* d = NULL;
  55368. BIGNUM emptyBN;
  55369. /* Setup */
  55370. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55371. /* internal not set emptyBN. */
  55372. ExpectNotNull(a = BN_new());
  55373. ExpectNotNull(b = BN_new());
  55374. ExpectNotNull(c = BN_dup(b));
  55375. ExpectNotNull(d = BN_new());
  55376. /* Invalid parameter testing. */
  55377. BN_free(NULL);
  55378. ExpectNull(BN_dup(NULL));
  55379. ExpectNull(BN_dup(&emptyBN));
  55380. ExpectNull(BN_copy(NULL, NULL));
  55381. ExpectNull(BN_copy(b, NULL));
  55382. ExpectNull(BN_copy(NULL, c));
  55383. ExpectNull(BN_copy(b, &emptyBN));
  55384. ExpectNull(BN_copy(&emptyBN, c));
  55385. BN_clear(NULL);
  55386. BN_clear(&emptyBN);
  55387. ExpectIntEQ(BN_num_bytes(NULL), 0);
  55388. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  55389. ExpectIntEQ(BN_num_bits(NULL), 0);
  55390. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  55391. ExpectIntEQ(BN_is_negative(NULL), 0);
  55392. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  55393. /* END Invalid Parameters */
  55394. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  55395. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  55396. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  55397. ExpectIntEQ(BN_num_bits(a), 2);
  55398. ExpectIntEQ(BN_num_bytes(a), 1);
  55399. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  55400. defined(WOLFSSL_SP_INT_NEGATIVE))
  55401. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  55402. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  55403. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  55404. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55405. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  55406. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55407. {
  55408. /* Do additional tests on negative BN conversions. */
  55409. char* ret = NULL;
  55410. ASN1_INTEGER* asn1 = NULL;
  55411. BIGNUM* tmp = NULL;
  55412. /* Sanity check we have a negative BN. */
  55413. ExpectIntEQ(BN_is_negative(c), 1);
  55414. ExpectNotNull(ret = BN_bn2dec(c));
  55415. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55416. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55417. ret = NULL;
  55418. /* Convert to ASN1_INTEGER and back to BN. */
  55419. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  55420. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  55421. /* After converting back BN should be negative and correct. */
  55422. ExpectIntEQ(BN_is_negative(tmp), 1);
  55423. ExpectNotNull(ret = BN_bn2dec(tmp));
  55424. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55425. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55426. ASN1_INTEGER_free(asn1);
  55427. BN_free(tmp);
  55428. }
  55429. #endif
  55430. ExpectIntEQ(BN_get_word(c), 4);
  55431. #endif
  55432. ExpectIntEQ(BN_set_word(a, 3), 1);
  55433. ExpectIntEQ(BN_set_word(b, 3), 1);
  55434. ExpectIntEQ(BN_set_word(c, 4), 1);
  55435. /* NULL == NULL, NULL < num, num > NULL */
  55436. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  55437. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  55438. ExpectIntLT(BN_cmp(NULL, b), 0);
  55439. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  55440. ExpectIntGT(BN_cmp(a, NULL), 0);
  55441. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  55442. ExpectIntEQ(BN_cmp(a, b), 0);
  55443. ExpectIntLT(BN_cmp(a, c), 0);
  55444. ExpectIntGT(BN_cmp(c, b), 0);
  55445. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  55446. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  55447. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  55448. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  55449. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  55450. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  55451. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  55452. #endif
  55453. BN_clear(a);
  55454. BN_free(a);
  55455. BN_free(b);
  55456. BN_free(c);
  55457. BN_clear_free(d);
  55458. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55459. return EXPECT_RESULT();
  55460. }
  55461. static int test_wolfSSL_BN_init(void)
  55462. {
  55463. EXPECT_DECLS;
  55464. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55465. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55466. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  55467. BIGNUM* ap = NULL;
  55468. BIGNUM bv;
  55469. BIGNUM cv;
  55470. BIGNUM dv;
  55471. ExpectNotNull(ap = BN_new());
  55472. BN_init(NULL);
  55473. XMEMSET(&bv, 0, sizeof(bv));
  55474. ExpectNull(BN_dup(&bv));
  55475. BN_init(&bv);
  55476. BN_init(&cv);
  55477. BN_init(&dv);
  55478. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  55479. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  55480. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  55481. /* a^b mod c = */
  55482. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55483. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  55484. /* check result 3^2 mod 5 */
  55485. ExpectIntEQ(BN_get_word(&dv), 4);
  55486. /* a*b mod c = */
  55487. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55488. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  55489. /* check result 3*2 mod 5 */
  55490. ExpectIntEQ(BN_get_word(&dv), 1);
  55491. BN_free(ap);
  55492. #endif
  55493. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55494. return EXPECT_RESULT();
  55495. }
  55496. static int test_wolfSSL_BN_enc_dec(void)
  55497. {
  55498. EXPECT_DECLS;
  55499. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55500. BIGNUM* a = NULL;
  55501. BIGNUM* b = NULL;
  55502. BIGNUM* c = NULL;
  55503. BIGNUM emptyBN;
  55504. char* str = NULL;
  55505. const char* emptyStr = "";
  55506. const char* numberStr = "12345";
  55507. const char* badStr = "g12345";
  55508. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55509. const char* twoStr = "2";
  55510. #endif
  55511. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  55512. unsigned char outNum[5];
  55513. /* Setup */
  55514. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55515. ExpectNotNull(a = BN_new());
  55516. ExpectNotNull(b = BN_new());
  55517. /* Invalid parameters */
  55518. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  55519. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  55520. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  55521. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  55522. ExpectNull(BN_bn2hex(NULL));
  55523. ExpectNull(BN_bn2hex(&emptyBN));
  55524. ExpectNull(BN_bn2dec(NULL));
  55525. ExpectNull(BN_bn2dec(&emptyBN));
  55526. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  55527. BN_free(a);
  55528. ExpectNotNull(a = BN_new());
  55529. ExpectIntEQ(BN_set_word(a, 2), 1);
  55530. ExpectNull(BN_bin2bn(binNum, -1, a));
  55531. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  55532. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  55533. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  55534. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  55535. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  55536. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  55537. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  55538. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  55539. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  55540. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  55541. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  55542. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  55543. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  55544. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  55545. ExpectIntEQ(BN_set_word(a, 2), 1);
  55546. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  55547. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  55548. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  55549. ExpectIntEQ(BN_cmp(a, b), 0);
  55550. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  55551. ExpectIntEQ(BN_cmp(a, b), -1);
  55552. ExpectNotNull(str = BN_bn2hex(a));
  55553. ExpectNotNull(BN_hex2bn(&b, str));
  55554. ExpectIntEQ(BN_cmp(a, b), 0);
  55555. ExpectNotNull(BN_hex2bn(&b, numberStr));
  55556. ExpectIntEQ(BN_cmp(a, b), -1);
  55557. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55558. str = NULL;
  55559. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55560. ExpectNotNull(str = BN_bn2dec(a));
  55561. ExpectStrEQ(str, twoStr);
  55562. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55563. str = NULL;
  55564. #ifndef NO_RSA
  55565. ExpectNotNull(str = BN_bn2dec(a));
  55566. ExpectNotNull(BN_dec2bn(&b, str));
  55567. ExpectIntEQ(BN_cmp(a, b), 0);
  55568. ExpectNotNull(BN_dec2bn(&b, numberStr));
  55569. ExpectIntEQ(BN_cmp(a, b), -1);
  55570. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55571. str = NULL;
  55572. #else
  55573. /* No implementation - fail with good parameters. */
  55574. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  55575. #endif
  55576. #endif
  55577. BN_free(b);
  55578. BN_free(a);
  55579. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55580. return EXPECT_RESULT();
  55581. }
  55582. static int test_wolfSSL_BN_word(void)
  55583. {
  55584. EXPECT_DECLS;
  55585. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55586. BIGNUM* a = NULL;
  55587. BIGNUM* b = NULL;
  55588. BIGNUM* c = NULL;
  55589. BIGNUM av;
  55590. ExpectNotNull(a = BN_new());
  55591. ExpectNotNull(b = BN_new());
  55592. ExpectNotNull(c = BN_new());
  55593. XMEMSET(&av, 0, sizeof(av));
  55594. /* Invalid parameter. */
  55595. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  55596. ExpectIntEQ(BN_add_word(&av, 3), 0);
  55597. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  55598. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  55599. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  55600. ExpectIntEQ(BN_set_word(&av, 3), 0);
  55601. ExpectIntEQ(BN_get_word(NULL), 0);
  55602. ExpectIntEQ(BN_get_word(&av), 0);
  55603. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  55604. ExpectIntEQ(BN_is_word(&av, 3), 0);
  55605. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55606. !defined(NO_DSA))
  55607. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  55608. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  55609. #endif
  55610. ExpectIntEQ(BN_one(NULL), 0);
  55611. ExpectIntEQ(BN_one(&av), 0);
  55612. BN_zero(NULL);
  55613. BN_zero(&av);
  55614. ExpectIntEQ(BN_is_one(NULL), 0);
  55615. ExpectIntEQ(BN_is_one(&av), 0);
  55616. ExpectIntEQ(BN_is_zero(NULL), 0);
  55617. ExpectIntEQ(BN_is_zero(&av), 0);
  55618. ExpectIntEQ(BN_set_word(a, 3), 1);
  55619. ExpectIntEQ(BN_set_word(b, 2), 1);
  55620. ExpectIntEQ(BN_set_word(c, 5), 1);
  55621. /* a + 3 = */
  55622. ExpectIntEQ(BN_add_word(a, 3), 1);
  55623. /* check result 3 + 3*/
  55624. ExpectIntEQ(BN_get_word(a), 6);
  55625. ExpectIntEQ(BN_is_word(a, 6), 1);
  55626. ExpectIntEQ(BN_is_word(a, 5), 0);
  55627. /* set a back to 3 */
  55628. ExpectIntEQ(BN_set_word(a, 3), 1);
  55629. /* a - 3 = */
  55630. ExpectIntEQ(BN_sub_word(a, 3), 1);
  55631. /* check result 3 - 3*/
  55632. ExpectIntEQ(BN_get_word(a), 0);
  55633. ExpectIntEQ(BN_one(a), 1);
  55634. ExpectIntEQ(BN_is_word(a, 1), 1);
  55635. ExpectIntEQ(BN_is_word(a, 0), 0);
  55636. ExpectIntEQ(BN_is_one(a), 1);
  55637. ExpectIntEQ(BN_is_zero(a), 0);
  55638. BN_zero(a);
  55639. ExpectIntEQ(BN_is_word(a, 0), 1);
  55640. ExpectIntEQ(BN_is_word(a, 1), 0);
  55641. ExpectIntEQ(BN_is_zero(a), 1);
  55642. ExpectIntEQ(BN_is_one(a), 0);
  55643. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55644. !defined(NO_DSA))
  55645. ExpectIntEQ(BN_set_word(a, 5), 1);
  55646. ExpectIntEQ(BN_mod_word(a, 3), 2);
  55647. ExpectIntEQ(BN_mod_word(a, 0), -1);
  55648. #endif
  55649. BN_free(c);
  55650. BN_free(b);
  55651. BN_free(a);
  55652. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55653. return EXPECT_RESULT();
  55654. }
  55655. static int test_wolfSSL_BN_bits(void)
  55656. {
  55657. EXPECT_DECLS;
  55658. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55659. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55660. BIGNUM* a = NULL;
  55661. BIGNUM emptyBN;
  55662. /* Setup */
  55663. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55664. ExpectNotNull(a = BN_new());
  55665. /* Invalid parameters. */
  55666. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  55667. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  55668. ExpectIntEQ(BN_set_bit(a, -1), 0);
  55669. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  55670. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  55671. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  55672. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  55673. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  55674. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  55675. ExpectIntEQ(BN_is_odd(NULL), 0);
  55676. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  55677. ExpectIntEQ(BN_set_word(a, 0), 1);
  55678. ExpectIntEQ(BN_is_zero(a), 1);
  55679. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  55680. ExpectIntEQ(BN_is_zero(a), 0);
  55681. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  55682. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  55683. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  55684. ExpectIntEQ(BN_is_zero(a), 1);
  55685. ExpectIntEQ(BN_set_bit(a, 0), 1);
  55686. ExpectIntEQ(BN_is_odd(a), 1);
  55687. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55688. ExpectIntEQ(BN_is_odd(a), 0);
  55689. ExpectIntEQ(BN_set_bit(a, 1), 1);
  55690. ExpectIntEQ(BN_is_odd(a), 0);
  55691. ExpectIntEQ(BN_set_bit(a, 129), 1);
  55692. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  55693. #ifndef NO_WOLFSSL_STUB
  55694. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  55695. #endif
  55696. BN_free(a);
  55697. #endif
  55698. return EXPECT_RESULT();
  55699. }
  55700. static int test_wolfSSL_BN_shift(void)
  55701. {
  55702. EXPECT_DECLS;
  55703. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55704. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55705. BIGNUM* a = NULL;
  55706. BIGNUM* b = NULL;
  55707. BIGNUM emptyBN;
  55708. /* Setup */
  55709. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55710. ExpectNotNull(a = BN_new());
  55711. ExpectNotNull(b = BN_new());
  55712. /* Invalid parameters. */
  55713. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  55714. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  55715. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  55716. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  55717. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  55718. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  55719. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  55720. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  55721. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  55722. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  55723. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  55724. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  55725. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  55726. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  55727. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  55728. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  55729. ExpectIntEQ(BN_set_word(a, 1), 1);
  55730. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  55731. ExpectIntEQ(BN_is_word(b, 2), 1);
  55732. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  55733. ExpectIntEQ(BN_is_word(a, 2), 1);
  55734. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  55735. ExpectIntEQ(BN_is_word(b, 1), 1);
  55736. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  55737. ExpectIntEQ(BN_is_word(a, 1), 1);
  55738. BN_free(b);
  55739. BN_free(a);
  55740. #endif
  55741. return EXPECT_RESULT();
  55742. }
  55743. static int test_wolfSSL_BN_math(void)
  55744. {
  55745. EXPECT_DECLS;
  55746. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55747. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55748. BIGNUM* a = NULL;
  55749. BIGNUM* b = NULL;
  55750. BIGNUM* r = NULL;
  55751. BIGNUM* rem = NULL;
  55752. BIGNUM emptyBN;
  55753. BN_ULONG val1;
  55754. BN_ULONG val2;
  55755. /* Setup */
  55756. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55757. ExpectNotNull(a = BN_new());
  55758. ExpectNotNull(b = BN_new());
  55759. ExpectNotNull(r = BN_new());
  55760. ExpectNotNull(rem = BN_new());
  55761. /* Invalid parameters. */
  55762. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  55763. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  55764. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  55765. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  55766. ExpectIntEQ(BN_add(r, a, NULL), 0);
  55767. ExpectIntEQ(BN_add(r, NULL, b), 0);
  55768. ExpectIntEQ(BN_add(NULL, a, b), 0);
  55769. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  55770. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  55771. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  55772. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  55773. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  55774. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  55775. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  55776. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  55777. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  55778. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  55779. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  55780. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  55781. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  55782. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  55783. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  55784. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  55785. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  55786. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  55787. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  55788. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  55789. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  55790. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  55791. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  55792. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  55793. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  55794. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  55795. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  55796. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  55797. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55798. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  55799. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  55800. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  55801. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  55802. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  55803. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  55804. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  55805. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  55806. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  55807. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  55808. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  55809. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  55810. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  55811. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  55812. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  55813. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55814. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55815. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  55816. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  55817. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  55818. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  55819. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  55820. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  55821. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  55822. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  55823. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  55824. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  55825. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  55826. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  55827. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  55828. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  55829. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55830. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  55831. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  55832. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  55833. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  55834. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  55835. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  55836. /* END Invalid parameters. */
  55837. val1 = 8;
  55838. val2 = 3;
  55839. ExpectIntEQ(BN_set_word(a, val1), 1);
  55840. ExpectIntEQ(BN_set_word(b, val2), 1);
  55841. ExpectIntEQ(BN_add(r, a, b), 1);
  55842. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  55843. ExpectIntEQ(BN_sub(r, a, b), 1);
  55844. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  55845. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  55846. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  55847. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  55848. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  55849. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  55850. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  55851. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  55852. BN_free(rem);
  55853. BN_free(r);
  55854. BN_free(b);
  55855. BN_free(a);
  55856. #endif
  55857. return EXPECT_RESULT();
  55858. }
  55859. static int test_wolfSSL_BN_math_mod(void)
  55860. {
  55861. EXPECT_DECLS;
  55862. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55863. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55864. BIGNUM* a = NULL;
  55865. BIGNUM* b = NULL;
  55866. BIGNUM* m = NULL;
  55867. BIGNUM* r = NULL;
  55868. BIGNUM* t = NULL;
  55869. BIGNUM emptyBN;
  55870. BN_ULONG val1;
  55871. BN_ULONG val2;
  55872. BN_ULONG val3;
  55873. /* Setup */
  55874. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55875. ExpectNotNull(a = BN_new());
  55876. ExpectNotNull(b = BN_new());
  55877. ExpectNotNull(m = BN_new());
  55878. ExpectNotNull(r = BN_new());
  55879. /* Invalid parameters. */
  55880. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  55881. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  55882. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  55883. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  55884. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  55885. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  55886. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  55887. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  55888. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  55889. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55890. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55891. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55892. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55893. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55894. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  55895. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  55896. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  55897. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  55898. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  55899. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  55900. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  55901. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  55902. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  55903. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  55904. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  55905. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  55906. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  55907. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55908. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55909. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55910. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55911. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55912. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  55913. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  55914. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  55915. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  55916. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  55917. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  55918. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  55919. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  55920. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  55921. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  55922. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  55923. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  55924. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  55925. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55926. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55927. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55928. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55929. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55930. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  55931. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  55932. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  55933. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  55934. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  55935. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55936. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55937. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55938. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55939. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  55940. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  55941. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  55942. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  55943. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  55944. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  55945. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  55946. /* END Invalid parameters. */
  55947. val1 = 9;
  55948. val2 = 13;
  55949. val3 = 5;
  55950. ExpectIntEQ(BN_set_word(a, val1), 1);
  55951. ExpectIntEQ(BN_set_word(b, val2), 1);
  55952. ExpectIntEQ(BN_set_word(m, val3), 1);
  55953. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  55954. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  55955. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  55956. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  55957. ExpectIntEQ(BN_set_word(a, 2), 1);
  55958. ExpectIntEQ(BN_set_word(b, 3), 1);
  55959. ExpectIntEQ(BN_set_word(m, 5), 1);
  55960. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  55961. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  55962. ExpectIntEQ(BN_is_word(r, 3), 1);
  55963. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  55964. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  55965. ExpectIntEQ(BN_is_word(r, 3), 1);
  55966. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  55967. ExpectIntEQ(BN_is_word(t, 3), 1);
  55968. BN_free(t);
  55969. /* No inverse case. No inverse when a divides b. */
  55970. ExpectIntEQ(BN_set_word(a, 3), 1);
  55971. ExpectIntEQ(BN_set_word(m, 9), 1);
  55972. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  55973. BN_free(r);
  55974. BN_free(m);
  55975. BN_free(b);
  55976. BN_free(a);
  55977. #endif
  55978. return EXPECT_RESULT();
  55979. }
  55980. static int test_wolfSSL_BN_math_other(void)
  55981. {
  55982. EXPECT_DECLS;
  55983. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55984. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55985. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  55986. BIGNUM* a = NULL;
  55987. BIGNUM* b = NULL;
  55988. BIGNUM* r = NULL;
  55989. BIGNUM emptyBN;
  55990. /* Setup */
  55991. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55992. ExpectNotNull(a = BN_new());
  55993. ExpectNotNull(b = BN_new());
  55994. ExpectNotNull(r = BN_new());
  55995. /* Invalid parameters. */
  55996. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  55997. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  55998. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  55999. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  56000. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  56001. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  56002. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  56003. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56004. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  56005. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  56006. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  56007. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  56008. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  56009. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  56010. /* END Invalid parameters. */
  56011. /* No common factors between 2 and 3. */
  56012. ExpectIntEQ(BN_set_word(a, 2), 1);
  56013. ExpectIntEQ(BN_set_word(b, 3), 1);
  56014. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56015. ExpectIntEQ(BN_is_word(r, 1), 1);
  56016. /* 3 is largest value that divides both 6 and 9. */
  56017. ExpectIntEQ(BN_set_word(a, 6), 1);
  56018. ExpectIntEQ(BN_set_word(b, 9), 1);
  56019. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56020. ExpectIntEQ(BN_is_word(r, 3), 1);
  56021. /* GCD of 0 and 0 is undefined. */
  56022. ExpectIntEQ(BN_set_word(a, 0), 1);
  56023. ExpectIntEQ(BN_set_word(b, 0), 1);
  56024. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  56025. /* Teardown */
  56026. BN_free(r);
  56027. BN_free(b);
  56028. BN_free(a);
  56029. #endif
  56030. #endif
  56031. return EXPECT_RESULT();
  56032. }
  56033. static int test_wolfSSL_BN_rand(void)
  56034. {
  56035. EXPECT_DECLS;
  56036. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  56037. BIGNUM* bn = NULL;
  56038. BIGNUM* range = NULL;
  56039. BIGNUM emptyBN;
  56040. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56041. ExpectNotNull(bn = BN_new());
  56042. ExpectNotNull(range = BN_new());
  56043. /* Invalid parameters. */
  56044. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  56045. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56046. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  56047. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  56048. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56049. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  56050. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  56051. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56052. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  56053. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  56054. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56055. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  56056. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  56057. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  56058. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  56059. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  56060. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  56061. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  56062. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  56063. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56064. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56065. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56066. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56067. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56068. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56069. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56070. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56071. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56072. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56073. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56074. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56075. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56076. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56077. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56078. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56079. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56080. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56081. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56082. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56083. /* 1 bit random value must have no more than one top bit set. */
  56084. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56085. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56086. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56087. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56088. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56089. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56090. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56091. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56092. /* END Invalid parameters. */
  56093. /* 0 bit random: 0. */
  56094. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56095. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56096. ExpectIntEQ(BN_is_zero(bn), 1);
  56097. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  56098. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56099. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56100. ExpectIntEQ(BN_is_zero(bn), 1);
  56101. /* 1 bit random: 0 or 1. */
  56102. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56103. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56104. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56105. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56106. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56107. ExpectIntEQ(BN_get_word(bn), 1);
  56108. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56109. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56110. ExpectIntEQ(BN_get_word(bn), 1);
  56111. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56112. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56113. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56114. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56115. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56116. ExpectIntEQ(BN_get_word(bn), 1);
  56117. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56118. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56119. ExpectIntEQ(BN_get_word(bn), 1);
  56120. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56121. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56122. ExpectIntEQ(BN_num_bits(bn), 8);
  56123. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56124. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56125. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56126. ExpectIntEQ(BN_num_bits(bn), 8);
  56127. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56128. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  56129. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56130. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56131. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  56132. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  56133. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56134. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56135. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  56136. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56137. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56138. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56139. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56140. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56141. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56142. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  56143. * requested number of bits up to the nearest multiple of 8. E.g. in this
  56144. * case, requesting a 13-bit random number would actually return a 16-bit
  56145. * random number. */
  56146. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  56147. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56148. ExpectIntEQ(BN_num_bits(bn), 13);
  56149. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  56150. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56151. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56152. ExpectIntEQ(BN_set_word(range, 0), 1);
  56153. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56154. ExpectIntEQ(BN_set_word(range, 1), 1);
  56155. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56156. BN_free(bn);
  56157. BN_free(range);
  56158. #endif
  56159. return EXPECT_RESULT();
  56160. }
  56161. static int test_wolfSSL_BN_prime(void)
  56162. {
  56163. EXPECT_DECLS;
  56164. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56165. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56166. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  56167. BIGNUM* a = NULL;
  56168. BIGNUM* add = NULL;
  56169. BIGNUM* rem = NULL;
  56170. BIGNUM emptyBN;
  56171. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56172. ExpectNotNull(a = BN_new());
  56173. ExpectNotNull(add = BN_new());
  56174. ExpectNotNull(rem = BN_new());
  56175. /* Invalid parameters. */
  56176. /* BN_generate_prime_ex()
  56177. * prime - must have valid BIGNUM
  56178. * bits - Greater then 0
  56179. * safe - not supported, must be 0
  56180. * add - not supported, must be NULL
  56181. * rem - not supported, must be NULL
  56182. * cb - anything
  56183. */
  56184. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  56185. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  56186. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  56187. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  56188. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  56189. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  56190. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  56191. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  56192. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  56193. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  56194. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  56195. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  56196. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  56197. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  56198. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  56199. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  56200. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  56201. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  56202. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  56203. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  56204. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  56205. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  56206. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  56207. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  56208. /* END Invalid parameters. */
  56209. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  56210. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  56211. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  56212. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  56213. BN_free(rem);
  56214. BN_free(add);
  56215. BN_free(a);
  56216. #endif
  56217. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56218. return EXPECT_RESULT();
  56219. }
  56220. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56221. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56222. #define TEST_ARG 0x1234
  56223. static void msg_cb(int write_p, int version, int content_type,
  56224. const void *buf, size_t len, SSL *ssl, void *arg)
  56225. {
  56226. (void)write_p;
  56227. (void)version;
  56228. (void)content_type;
  56229. (void)buf;
  56230. (void)len;
  56231. (void)ssl;
  56232. AssertTrue(arg == (void*)TEST_ARG);
  56233. }
  56234. #endif
  56235. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  56236. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56237. #if defined(SESSION_CERTS)
  56238. #include "wolfssl/internal.h"
  56239. #endif
  56240. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  56241. {
  56242. EXPECT_DECLS;
  56243. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  56244. STACK_OF(X509)* sk = NULL;
  56245. X509* x509 = NULL;
  56246. int i, num;
  56247. BIO* bio = NULL;
  56248. #endif
  56249. ExpectNotNull(ctx);
  56250. ExpectNotNull(ssl);
  56251. fprintf(stderr, "\n===== msgcb called ====\n");
  56252. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  56253. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  56254. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  56255. ExpectNotNull(SSL_get0_verified_chain(ssl));
  56256. #endif
  56257. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  56258. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  56259. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  56260. if (sk == NULL) {
  56261. BIO_free(bio);
  56262. return TEST_FAIL;
  56263. }
  56264. num = sk_X509_num(sk);
  56265. ExpectTrue(num > 0);
  56266. for (i = 0; i < num; i++) {
  56267. ExpectNotNull(x509 = sk_X509_value(sk,i));
  56268. if (x509 == NULL)
  56269. break;
  56270. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  56271. X509_print(bio,x509);
  56272. fprintf(stderr, "\n\n");
  56273. }
  56274. BIO_free(bio);
  56275. #endif
  56276. return EXPECT_RESULT();
  56277. }
  56278. #endif
  56279. static int test_wolfSSL_msgCb(void)
  56280. {
  56281. EXPECT_DECLS;
  56282. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  56283. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56284. test_ssl_cbf client_cb;
  56285. test_ssl_cbf server_cb;
  56286. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56287. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56288. #ifndef WOLFSSL_NO_TLS12
  56289. client_cb.method = wolfTLSv1_2_client_method;
  56290. server_cb.method = wolfTLSv1_2_server_method;
  56291. #else
  56292. client_cb.method = wolfTLSv1_3_client_method;
  56293. server_cb.method = wolfTLSv1_3_server_method;
  56294. #endif
  56295. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56296. &server_cb, msgCb), TEST_SUCCESS);
  56297. #endif
  56298. return EXPECT_RESULT();
  56299. }
  56300. static int test_wolfSSL_either_side(void)
  56301. {
  56302. EXPECT_DECLS;
  56303. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56304. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56305. test_ssl_cbf client_cb;
  56306. test_ssl_cbf server_cb;
  56307. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56308. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56309. /* Use different CTX for client and server */
  56310. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56311. ExpectNotNull(client_cb.ctx);
  56312. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56313. ExpectNotNull(server_cb.ctx);
  56314. /* we are responsible for free'ing WOLFSSL_CTX */
  56315. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56316. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56317. &server_cb, NULL), TEST_SUCCESS);
  56318. wolfSSL_CTX_free(client_cb.ctx);
  56319. wolfSSL_CTX_free(server_cb.ctx);
  56320. #endif
  56321. return EXPECT_RESULT();
  56322. }
  56323. static int test_wolfSSL_DTLS_either_side(void)
  56324. {
  56325. EXPECT_DECLS;
  56326. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56327. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  56328. test_ssl_cbf client_cb;
  56329. test_ssl_cbf server_cb;
  56330. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56331. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56332. /* Use different CTX for client and server */
  56333. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56334. ExpectNotNull(client_cb.ctx);
  56335. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56336. ExpectNotNull(server_cb.ctx);
  56337. /* we are responsible for free'ing WOLFSSL_CTX */
  56338. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56339. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56340. &server_cb, NULL), TEST_SUCCESS);
  56341. wolfSSL_CTX_free(client_cb.ctx);
  56342. wolfSSL_CTX_free(server_cb.ctx);
  56343. #endif
  56344. return EXPECT_RESULT();
  56345. }
  56346. static int test_generate_cookie(void)
  56347. {
  56348. EXPECT_DECLS;
  56349. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  56350. SSL_CTX* ctx = NULL;
  56351. SSL* ssl = NULL;
  56352. byte buf[FOURK_BUF] = {0};
  56353. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  56354. ExpectNotNull(ssl = SSL_new(ctx));
  56355. /* Test unconnected */
  56356. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  56357. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  56358. wolfSSL_SetCookieCtx(ssl, ctx);
  56359. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  56360. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  56361. SSL_free(ssl);
  56362. SSL_CTX_free(ctx);
  56363. #endif
  56364. return EXPECT_RESULT();
  56365. }
  56366. static int test_wolfSSL_set_options(void)
  56367. {
  56368. EXPECT_DECLS;
  56369. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56370. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56371. WOLFSSL* ssl = NULL;
  56372. WOLFSSL_CTX* ctx = NULL;
  56373. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56374. char appData[] = "extra msg";
  56375. #endif
  56376. #ifdef OPENSSL_EXTRA
  56377. unsigned char protos[] = {
  56378. 7, 't', 'l', 's', '/', '1', '.', '2',
  56379. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  56380. };
  56381. unsigned int len = sizeof(protos);
  56382. void *arg = (void *)TEST_ARG;
  56383. #endif
  56384. #ifndef NO_WOLFSSL_SERVER
  56385. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56386. #else
  56387. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56388. #endif
  56389. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56390. WOLFSSL_FILETYPE_PEM));
  56391. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56392. WOLFSSL_FILETYPE_PEM));
  56393. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  56394. == WOLFSSL_OP_NO_TLSv1);
  56395. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  56396. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56397. WOLFSSL_OP_NO_SSLv2)), 0);
  56398. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56399. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56400. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  56401. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56402. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56403. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56404. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56405. WOLFSSL_OP_NO_COMPRESSION));
  56406. wolfSSL_CTX_free(ctx);
  56407. ctx = NULL;
  56408. #ifndef NO_WOLFSSL_SERVER
  56409. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56410. #else
  56411. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56412. #endif
  56413. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56414. WOLFSSL_FILETYPE_PEM));
  56415. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56416. WOLFSSL_FILETYPE_PEM));
  56417. #ifdef OPENSSL_EXTRA
  56418. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  56419. #endif
  56420. ExpectNotNull(ssl = wolfSSL_new(ctx));
  56421. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56422. #ifdef HAVE_EX_DATA
  56423. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  56424. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56425. if (ssl != NULL) {
  56426. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  56427. appData, sizeof(appData)), 0);
  56428. }
  56429. #else
  56430. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56431. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56432. #endif
  56433. #endif
  56434. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  56435. WOLFSSL_OP_NO_TLSv1);
  56436. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  56437. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56438. WOLFSSL_OP_NO_SSLv2)), 0);
  56439. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56440. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56441. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  56442. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56443. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56444. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56445. #ifdef OPENSSL_EXTRA
  56446. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56447. WOLFSSL_OP_NO_COMPRESSION));
  56448. #endif
  56449. #ifdef OPENSSL_EXTRA
  56450. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  56451. wolfSSL_set_msg_callback_arg(ssl, arg);
  56452. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56453. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  56454. #else
  56455. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  56456. #endif
  56457. #endif
  56458. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  56459. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  56460. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  56461. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  56462. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56463. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  56464. #else
  56465. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  56466. #endif
  56467. #endif /* HAVE_ALPN && !NO_BIO */
  56468. #endif
  56469. wolfSSL_free(ssl);
  56470. wolfSSL_CTX_free(ctx);
  56471. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56472. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56473. return EXPECT_RESULT();
  56474. }
  56475. static int test_wolfSSL_sk_SSL_CIPHER(void)
  56476. {
  56477. EXPECT_DECLS;
  56478. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  56479. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56480. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56481. SSL* ssl = NULL;
  56482. SSL_CTX* ctx = NULL;
  56483. STACK_OF(SSL_CIPHER) *sk = NULL;
  56484. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  56485. #ifndef NO_WOLFSSL_SERVER
  56486. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56487. #else
  56488. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56489. #endif
  56490. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  56491. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56492. ExpectNotNull(ssl = SSL_new(ctx));
  56493. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  56494. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  56495. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  56496. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  56497. /* error case because connection has not been established yet */
  56498. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  56499. sk_SSL_CIPHER_free(dupSk);
  56500. /* sk is pointer to internal struct that should be free'd in SSL_free */
  56501. SSL_free(ssl);
  56502. SSL_CTX_free(ctx);
  56503. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56504. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56505. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56506. return EXPECT_RESULT();
  56507. }
  56508. static int test_wolfSSL_set1_curves_list(void)
  56509. {
  56510. EXPECT_DECLS;
  56511. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  56512. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56513. SSL* ssl = NULL;
  56514. SSL_CTX* ctx = NULL;
  56515. #ifndef NO_WOLFSSL_SERVER
  56516. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56517. #else
  56518. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56519. #endif
  56520. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  56521. SSL_FILETYPE_PEM));
  56522. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  56523. ExpectNotNull(ssl = SSL_new(ctx));
  56524. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56525. #ifdef HAVE_ECC
  56526. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56527. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  56528. #endif
  56529. #ifdef HAVE_CURVE25519
  56530. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  56531. #else
  56532. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56533. #endif
  56534. #ifdef HAVE_CURVE448
  56535. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  56536. #else
  56537. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56538. #endif
  56539. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56540. #ifdef HAVE_ECC
  56541. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56542. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  56543. #endif
  56544. #ifdef HAVE_CURVE25519
  56545. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  56546. #else
  56547. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56548. #endif
  56549. #ifdef HAVE_CURVE448
  56550. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  56551. #else
  56552. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56553. #endif
  56554. SSL_free(ssl);
  56555. SSL_CTX_free(ctx);
  56556. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56557. #endif
  56558. return EXPECT_RESULT();
  56559. }
  56560. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56561. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56562. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  56563. {
  56564. static int counter = 0;
  56565. EXPECT_DECLS;
  56566. if (counter % 2) {
  56567. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  56568. WOLFSSL_SUCCESS);
  56569. }
  56570. else {
  56571. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  56572. WOLFSSL_SUCCESS);
  56573. }
  56574. /* Ciphersuites that require curves */
  56575. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  56576. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  56577. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  56578. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  56579. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  56580. "ECDHE-ECDSA-CHACHA20-POLY1305");
  56581. counter++;
  56582. return EXPECT_RESULT();
  56583. }
  56584. #endif
  56585. static int test_wolfSSL_curves_mismatch(void)
  56586. {
  56587. EXPECT_DECLS;
  56588. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56589. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56590. test_ssl_cbf func_cb_client;
  56591. test_ssl_cbf func_cb_server;
  56592. size_t i;
  56593. struct {
  56594. method_provider client_meth;
  56595. method_provider server_meth;
  56596. const char* desc;
  56597. int client_last_err;
  56598. int server_last_err;
  56599. } test_params[] = {
  56600. #ifdef WOLFSSL_TLS13
  56601. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  56602. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  56603. #endif
  56604. #ifndef WOLFSSL_NO_TLS12
  56605. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  56606. WC_NO_ERR_TRACE(FATAL_ERROR),
  56607. #ifdef OPENSSL_EXTRA
  56608. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56609. #else
  56610. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56611. #endif
  56612. },
  56613. #endif
  56614. #ifndef NO_OLD_TLS
  56615. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  56616. WC_NO_ERR_TRACE(FATAL_ERROR),
  56617. #ifdef OPENSSL_EXTRA
  56618. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56619. #else
  56620. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56621. #endif
  56622. },
  56623. #endif
  56624. };
  56625. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  56626. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  56627. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  56628. printf("\tTesting with %s...\n", test_params[i].desc);
  56629. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56630. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56631. func_cb_client.method = test_params[i].client_meth;
  56632. func_cb_server.method = test_params[i].server_meth;
  56633. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  56634. &func_cb_server, NULL), -1001);
  56635. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  56636. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  56637. if (!EXPECT_SUCCESS())
  56638. break;
  56639. printf("\t%s passed\n", test_params[i].desc);
  56640. }
  56641. #endif
  56642. return EXPECT_RESULT();
  56643. }
  56644. static int test_wolfSSL_set1_sigalgs_list(void)
  56645. {
  56646. EXPECT_DECLS;
  56647. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56648. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56649. SSL* ssl = NULL;
  56650. SSL_CTX* ctx = NULL;
  56651. #ifndef NO_WOLFSSL_SERVER
  56652. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56653. #else
  56654. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56655. #endif
  56656. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56657. SSL_FILETYPE_PEM));
  56658. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56659. ExpectNotNull(ssl = SSL_new(ctx));
  56660. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56661. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56662. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56663. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56664. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56665. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56666. #ifndef NO_RSA
  56667. #ifndef NO_SHA256
  56668. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56669. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56670. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56671. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56672. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  56673. WOLFSSL_SUCCESS);
  56674. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  56675. WOLFSSL_SUCCESS);
  56676. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  56677. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56678. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  56679. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56680. #ifdef WC_RSA_PSS
  56681. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  56682. WOLFSSL_SUCCESS);
  56683. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  56684. WOLFSSL_SUCCESS);
  56685. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  56686. WOLFSSL_SUCCESS);
  56687. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  56688. WOLFSSL_SUCCESS);
  56689. #endif
  56690. #ifdef WOLFSSL_SHA512
  56691. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56692. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56693. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56694. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56695. #elif defined(WOLFSSL_SHA384)
  56696. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56697. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56698. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56699. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56700. #endif
  56701. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56702. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56703. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  56704. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56705. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  56706. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56707. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  56708. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56709. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  56710. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56711. #endif
  56712. #endif
  56713. #ifdef HAVE_ECC
  56714. #ifndef NO_SHA256
  56715. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  56716. WOLFSSL_SUCCESS);
  56717. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  56718. WOLFSSL_SUCCESS);
  56719. #ifdef WOLFSSL_SHA512
  56720. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56721. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56722. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56723. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56724. #elif defined(WOLFSSL_SHA384)
  56725. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56726. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56727. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56728. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56729. #endif
  56730. #endif
  56731. #endif
  56732. #ifdef HAVE_ED25519
  56733. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  56734. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  56735. #endif
  56736. #ifdef HAVE_ED448
  56737. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  56738. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  56739. #endif
  56740. #ifndef NO_DSA
  56741. #ifndef NO_SHA256
  56742. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  56743. WOLFSSL_SUCCESS);
  56744. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  56745. WOLFSSL_SUCCESS);
  56746. #endif
  56747. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  56748. defined(WOLFSSL_ALLOW_TLS_SHA1))
  56749. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  56750. WOLFSSL_SUCCESS);
  56751. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  56752. WOLFSSL_SUCCESS);
  56753. #endif
  56754. #endif
  56755. SSL_free(ssl);
  56756. SSL_CTX_free(ctx);
  56757. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56758. #endif
  56759. return EXPECT_RESULT();
  56760. }
  56761. /* Testing wolfSSL_set_tlsext_status_type function.
  56762. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  56763. */
  56764. static int test_wolfSSL_set_tlsext_status_type(void)
  56765. {
  56766. EXPECT_DECLS;
  56767. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  56768. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  56769. SSL* ssl = NULL;
  56770. SSL_CTX* ctx = NULL;
  56771. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56772. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56773. SSL_FILETYPE_PEM));
  56774. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56775. ExpectNotNull(ssl = SSL_new(ctx));
  56776. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  56777. SSL_SUCCESS);
  56778. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  56779. SSL_free(ssl);
  56780. SSL_CTX_free(ctx);
  56781. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  56782. return EXPECT_RESULT();
  56783. }
  56784. #ifndef NO_BIO
  56785. static int test_wolfSSL_PEM_read_bio(void)
  56786. {
  56787. EXPECT_DECLS;
  56788. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56789. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56790. byte buff[6000];
  56791. XFILE f = XBADFILE;
  56792. int bytes = 0;
  56793. X509* x509 = NULL;
  56794. BIO* bio = NULL;
  56795. BUF_MEM* buf = NULL;
  56796. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  56797. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  56798. if (f != XBADFILE)
  56799. XFCLOSE(f);
  56800. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56801. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  56802. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  56803. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56804. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  56805. /* BIO should return the set EOF value */
  56806. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  56807. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  56808. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  56809. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  56810. BIO_free(bio);
  56811. BUF_MEM_free(buf);
  56812. X509_free(x509);
  56813. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  56814. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56815. return EXPECT_RESULT();
  56816. }
  56817. #if defined(OPENSSL_EXTRA)
  56818. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  56819. long argl, long ret)
  56820. {
  56821. (void)bio;
  56822. (void)cmd;
  56823. (void)argp;
  56824. (void)argi;
  56825. (void)argl;
  56826. return ret;
  56827. }
  56828. #endif
  56829. static int test_wolfSSL_BIO(void)
  56830. {
  56831. EXPECT_DECLS;
  56832. #if defined(OPENSSL_EXTRA)
  56833. const unsigned char* p = NULL;
  56834. byte buff[20];
  56835. BIO* bio1 = NULL;
  56836. BIO* bio2 = NULL;
  56837. BIO* bio3 = NULL;
  56838. char* bufPt = NULL;
  56839. int i;
  56840. for (i = 0; i < 20; i++) {
  56841. buff[i] = i;
  56842. }
  56843. /* test BIO_free with NULL */
  56844. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56845. /* Creating and testing type BIO_s_bio */
  56846. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56847. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  56848. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  56849. /* read/write before set up */
  56850. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56851. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56852. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  56853. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  56854. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  56855. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  56856. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  56857. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  56858. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  56859. /* write buffer full */
  56860. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  56861. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  56862. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  56863. /* write the other direction with pair */
  56864. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  56865. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  56866. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  56867. /* try read */
  56868. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  56869. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  56870. /* try read using ctrl function */
  56871. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  56872. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  56873. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  56874. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  56875. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  56876. for (i = 0; i < 20; i++) {
  56877. ExpectIntEQ((int)bufPt[i], i);
  56878. }
  56879. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  56880. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  56881. for (i = 0; i < 8; i++) {
  56882. ExpectIntEQ((int)bufPt[i], i);
  56883. }
  56884. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  56885. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  56886. /* new pair */
  56887. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56888. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  56889. bio2 = NULL;
  56890. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  56891. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56892. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  56893. /* test wrap around... */
  56894. ExpectIntEQ(BIO_reset(bio1), 1);
  56895. ExpectIntEQ(BIO_reset(bio3), 1);
  56896. /* fill write buffer, read only small amount then write again */
  56897. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56898. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56899. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  56900. for (i = 0; i < 4; i++) {
  56901. ExpectIntEQ(bufPt[i], i);
  56902. }
  56903. /* try writing over read index */
  56904. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  56905. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  56906. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  56907. /* read and write 0 bytes */
  56908. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56909. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  56910. /* should read only to end of write buffer then need to read again */
  56911. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  56912. for (i = 0; i < 16; i++) {
  56913. ExpectIntEQ(bufPt[i], buff[4 + i]);
  56914. }
  56915. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56916. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  56917. for (i = 0; i < 4; i++) {
  56918. ExpectIntEQ(bufPt[i], 0);
  56919. }
  56920. /* read index should not have advanced with nread0 */
  56921. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  56922. for (i = 0; i < 4; i++) {
  56923. ExpectIntEQ(bufPt[i], 0);
  56924. }
  56925. /* write and fill up buffer checking reset of index state */
  56926. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56927. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56928. /* test reset on data in bio1 write buffer */
  56929. ExpectIntEQ(BIO_reset(bio1), 1);
  56930. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56931. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  56932. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56933. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  56934. ExpectNotNull(p);
  56935. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56936. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  56937. for (i = 0; i < 6; i++) {
  56938. ExpectIntEQ(bufPt[i], i);
  56939. }
  56940. /* test case of writing twice with offset read index */
  56941. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  56942. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  56943. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56944. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56945. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56946. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  56947. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  56948. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56949. BIO_free(bio1);
  56950. bio1 = NULL;
  56951. BIO_free(bio3);
  56952. bio3 = NULL;
  56953. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  56954. {
  56955. BIO* bioA = NULL;
  56956. BIO* bioB = NULL;
  56957. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  56958. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  56959. BIO_free(bioA);
  56960. bioA = NULL;
  56961. BIO_free(bioB);
  56962. bioB = NULL;
  56963. }
  56964. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  56965. /* BIOs with file pointers */
  56966. #if !defined(NO_FILESYSTEM)
  56967. {
  56968. XFILE f1 = XBADFILE;
  56969. XFILE f2 = XBADFILE;
  56970. BIO* f_bio1 = NULL;
  56971. BIO* f_bio2 = NULL;
  56972. unsigned char cert[300];
  56973. char testFile[] = "tests/bio_write_test.txt";
  56974. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  56975. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  56976. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  56977. /* Failure due to wrong BIO type */
  56978. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56979. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  56980. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  56981. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  56982. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  56983. WOLFSSL_SUCCESS);
  56984. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56985. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  56986. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  56987. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  56988. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  56989. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  56990. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  56991. ExpectIntEQ(BIO_reset(f_bio2), 1);
  56992. ExpectIntEQ(BIO_tell(NULL),-1);
  56993. ExpectIntEQ(BIO_tell(f_bio2),0);
  56994. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  56995. ExpectIntEQ(BIO_tell(f_bio2),4);
  56996. BIO_free(f_bio1);
  56997. f_bio1 = NULL;
  56998. BIO_free(f_bio2);
  56999. f_bio2 = NULL;
  57000. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  57001. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  57002. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  57003. BIO_free(f_bio1);
  57004. f_bio1 = NULL;
  57005. }
  57006. #endif /* !defined(NO_FILESYSTEM) */
  57007. /* BIO info callback */
  57008. {
  57009. const char* testArg = "test";
  57010. BIO* cb_bio = NULL;
  57011. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  57012. BIO_set_callback(cb_bio, bioCallback);
  57013. ExpectNotNull(BIO_get_callback(cb_bio));
  57014. BIO_set_callback(cb_bio, NULL);
  57015. ExpectNull(BIO_get_callback(cb_bio));
  57016. BIO_set_callback_arg(cb_bio, (char*)testArg);
  57017. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  57018. ExpectNull(BIO_get_callback_arg(NULL));
  57019. BIO_free(cb_bio);
  57020. cb_bio = NULL;
  57021. }
  57022. /* BIO_vfree */
  57023. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57024. BIO_vfree(NULL);
  57025. BIO_vfree(bio1);
  57026. #endif
  57027. return EXPECT_RESULT();
  57028. }
  57029. static int test_wolfSSL_BIO_BIO_ring_read(void)
  57030. {
  57031. EXPECT_DECLS;
  57032. #if defined(OPENSSL_ALL)
  57033. BIO* bio1 = NULL;
  57034. BIO* bio2 = NULL;
  57035. byte data[50];
  57036. byte tmp[50];
  57037. XMEMSET(data, 42, sizeof(data));
  57038. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  57039. SSL_SUCCESS);
  57040. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  57041. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  57042. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  57043. ExpectBufEQ(tmp, data, 20);
  57044. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  57045. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  57046. ExpectBufEQ(tmp, data, 40);
  57047. BIO_free(bio1);
  57048. BIO_free(bio2);
  57049. #endif
  57050. return EXPECT_RESULT();
  57051. }
  57052. #endif /* !NO_BIO */
  57053. static int test_wolfSSL_a2i_IPADDRESS(void)
  57054. {
  57055. EXPECT_DECLS;
  57056. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  57057. const unsigned char* data = NULL;
  57058. int dataSz = 0;
  57059. ASN1_OCTET_STRING *st = NULL;
  57060. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  57061. const unsigned char ipv6_exp[] = {
  57062. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  57063. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  57064. };
  57065. const unsigned char ipv6_home[] = {
  57066. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57067. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  57068. };
  57069. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  57070. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  57071. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57072. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  57073. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  57074. ASN1_STRING_free(st);
  57075. st = NULL;
  57076. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  57077. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57078. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57079. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  57080. ASN1_STRING_free(st);
  57081. st = NULL;
  57082. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  57083. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57084. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57085. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  57086. ASN1_STRING_free(st);
  57087. #endif
  57088. return EXPECT_RESULT();
  57089. }
  57090. static int test_wolfSSL_X509_cmp_time(void)
  57091. {
  57092. EXPECT_DECLS;
  57093. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  57094. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  57095. WOLFSSL_ASN1_TIME asn_time;
  57096. time_t t;
  57097. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  57098. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  57099. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  57100. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  57101. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  57102. #endif
  57103. return EXPECT_RESULT();
  57104. }
  57105. static int test_wolfSSL_X509_time_adj(void)
  57106. {
  57107. EXPECT_DECLS;
  57108. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  57109. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  57110. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  57111. !defined(NO_ASN_TIME)
  57112. X509* x509 = NULL;
  57113. time_t t;
  57114. time_t not_before;
  57115. time_t not_after;
  57116. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57117. client_cert_der_2048, sizeof_client_cert_der_2048,
  57118. WOLFSSL_FILETYPE_ASN1));
  57119. t = 0;
  57120. not_before = wc_Time(0);
  57121. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  57122. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  57123. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  57124. /* Check X509_gmtime_adj, too. */
  57125. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  57126. X509_free(x509);
  57127. #endif
  57128. return EXPECT_RESULT();
  57129. }
  57130. static int test_wolfSSL_X509_bad_altname(void)
  57131. {
  57132. EXPECT_DECLS;
  57133. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57134. const unsigned char malformed_alt_name_cert[] = {
  57135. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  57136. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  57137. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  57138. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  57139. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  57140. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  57141. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  57142. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  57143. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  57144. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  57145. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  57146. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  57147. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  57148. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  57149. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  57150. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  57151. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  57152. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  57153. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  57154. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  57155. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  57156. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  57157. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  57158. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  57159. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  57160. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  57161. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  57162. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  57163. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  57164. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  57165. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  57166. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  57167. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  57168. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  57169. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  57170. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  57171. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  57172. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  57173. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  57174. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  57175. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  57176. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  57177. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  57178. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  57179. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  57180. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  57181. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  57182. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  57183. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  57184. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  57185. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  57186. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  57187. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  57188. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  57189. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  57190. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  57191. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  57192. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  57193. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  57194. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  57195. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  57196. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  57197. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  57198. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  57199. };
  57200. X509* x509 = NULL;
  57201. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  57202. const char *name = "aaaaa";
  57203. int nameLen = (int)XSTRLEN(name);
  57204. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57205. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  57206. /* malformed_alt_name_cert has a malformed alternative
  57207. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  57208. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  57209. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  57210. X509_free(x509);
  57211. #endif
  57212. return EXPECT_RESULT();
  57213. }
  57214. static int test_wolfSSL_X509_name_match(void)
  57215. {
  57216. EXPECT_DECLS;
  57217. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57218. /* A certificate with the subject alternative name a* */
  57219. const unsigned char cert_der[] = {
  57220. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  57221. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  57222. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  57223. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57224. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57225. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57226. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57227. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57228. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57229. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57230. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57231. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57232. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57233. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57234. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57235. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57236. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  57237. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57238. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57239. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57240. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57241. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57242. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57243. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57244. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57245. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57246. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57247. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57248. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57249. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  57250. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  57251. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  57252. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  57253. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  57254. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  57255. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  57256. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  57257. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  57258. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  57259. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  57260. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  57261. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  57262. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  57263. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  57264. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  57265. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  57266. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  57267. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  57268. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  57269. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  57270. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  57271. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  57272. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  57273. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  57274. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  57275. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  57276. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  57277. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  57278. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  57279. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  57280. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  57281. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  57282. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  57283. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  57284. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  57285. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  57286. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  57287. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  57288. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  57289. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  57290. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  57291. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  57292. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  57293. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  57294. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  57295. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  57296. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  57297. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  57298. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  57299. };
  57300. WOLFSSL_X509* x509 = NULL;
  57301. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57302. const char *name1 = "aaaaa";
  57303. int nameLen1 = (int)(XSTRLEN(name1));
  57304. const char *name2 = "a";
  57305. int nameLen2 = (int)(XSTRLEN(name2));
  57306. const char *name3 = "abbbb";
  57307. int nameLen3 = (int)(XSTRLEN(name3));
  57308. const char *name4 = "bbb";
  57309. int nameLen4 = (int)(XSTRLEN(name4));
  57310. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57311. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57312. /* Ensure that "a*" matches "aaaaa" */
  57313. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57314. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57315. /* Ensure that "a*" matches "a" */
  57316. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57317. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57318. /* Ensure that "a*" matches "abbbb" */
  57319. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57320. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57321. /* Ensure that "a*" does not match "bbb" */
  57322. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57323. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  57324. wolfSSL_X509_free(x509);
  57325. #endif
  57326. return EXPECT_RESULT();
  57327. }
  57328. static int test_wolfSSL_X509_name_match2(void)
  57329. {
  57330. EXPECT_DECLS;
  57331. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57332. /* A certificate with the subject alternative name a*b* */
  57333. const unsigned char cert_der[] = {
  57334. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  57335. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  57336. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  57337. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57338. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57339. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57340. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57341. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57342. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57343. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57344. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57345. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57346. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57347. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57348. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57349. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57350. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  57351. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57352. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57353. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57354. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57355. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57356. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57357. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57358. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57359. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57360. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57361. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57362. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57363. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  57364. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  57365. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  57366. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  57367. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  57368. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  57369. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  57370. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  57371. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  57372. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  57373. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  57374. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  57375. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  57376. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  57377. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  57378. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  57379. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  57380. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  57381. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  57382. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  57383. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  57384. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  57385. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  57386. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  57387. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  57388. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  57389. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  57390. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  57391. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  57392. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  57393. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  57394. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  57395. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  57396. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  57397. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  57398. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  57399. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  57400. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  57401. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  57402. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  57403. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  57404. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  57405. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  57406. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  57407. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  57408. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  57409. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  57410. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  57411. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  57412. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  57413. };
  57414. WOLFSSL_X509* x509 = NULL;
  57415. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57416. const char *name1 = "ab";
  57417. int nameLen1 = (int)(XSTRLEN(name1));
  57418. const char *name2 = "acccbccc";
  57419. int nameLen2 = (int)(XSTRLEN(name2));
  57420. const char *name3 = "accb";
  57421. int nameLen3 = (int)(XSTRLEN(name3));
  57422. const char *name4 = "accda";
  57423. int nameLen4 = (int)(XSTRLEN(name4));
  57424. const char *name5 = "acc\0bcc";
  57425. int nameLen5 = 7;
  57426. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57427. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57428. /* Ensure that "a*b*" matches "ab" */
  57429. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57430. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57431. /* Ensure that "a*b*" matches "acccbccc" */
  57432. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57433. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57434. /* Ensure that "a*b*" matches "accb" */
  57435. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57436. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57437. /* Ensure that "a*b*" does not match "accda" */
  57438. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57439. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57440. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  57441. * on check len input handling, 0 for len is OK as it should then use
  57442. * strlen(name1) */
  57443. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  57444. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57445. /* Openssl also allows for len to include NULL terminator */
  57446. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  57447. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57448. /* Ensure that check string with NULL terminator in middle is
  57449. * rejected */
  57450. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  57451. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57452. wolfSSL_X509_free(x509);
  57453. #endif
  57454. return EXPECT_RESULT();
  57455. }
  57456. static int test_wolfSSL_X509_name_match3(void)
  57457. {
  57458. EXPECT_DECLS;
  57459. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57460. /* A certificate with the subject alternative name *.example.com */
  57461. const unsigned char cert_der[] = {
  57462. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  57463. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  57464. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  57465. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57466. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57467. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57468. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57469. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57470. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57471. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57472. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57473. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57474. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57475. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57476. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57477. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57478. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  57479. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57480. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57481. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57482. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57483. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57484. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57485. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57486. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57487. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57488. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57489. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57490. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57491. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  57492. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  57493. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  57494. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  57495. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  57496. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  57497. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  57498. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  57499. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  57500. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  57501. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  57502. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  57503. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  57504. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  57505. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  57506. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  57507. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  57508. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  57509. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  57510. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  57511. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  57512. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  57513. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  57514. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  57515. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  57516. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  57517. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  57518. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  57519. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  57520. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  57521. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  57522. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  57523. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  57524. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  57525. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  57526. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  57527. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  57528. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  57529. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  57530. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  57531. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  57532. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  57533. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  57534. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  57535. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  57536. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  57537. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  57538. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  57539. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  57540. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  57541. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  57542. };
  57543. WOLFSSL_X509* x509 = NULL;
  57544. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57545. const char *name1 = "foo.example.com";
  57546. int nameLen1 = (int)(XSTRLEN(name1));
  57547. const char *name2 = "x.y.example.com";
  57548. int nameLen2 = (int)(XSTRLEN(name2));
  57549. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57550. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57551. /* Ensure that "*.example.com" matches "foo.example.com" */
  57552. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57553. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57554. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  57555. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57556. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57557. wolfSSL_X509_free(x509);
  57558. #endif
  57559. return EXPECT_RESULT();
  57560. }
  57561. static int test_wolfSSL_X509_max_altnames(void)
  57562. {
  57563. EXPECT_DECLS;
  57564. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  57565. /* Only test if max alt names has not been modified */
  57566. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  57567. WOLFSSL_CTX* ctx = NULL;
  57568. /* File contains a certificate encoded with 130 subject alternative names */
  57569. const char* over_max_altnames_cert = \
  57570. "./certs/test/cert-over-max-altnames.pem";
  57571. #ifndef NO_WOLFSSL_SERVER
  57572. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57573. #else
  57574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57575. #endif
  57576. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  57577. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  57578. WOLFSSL_SUCCESS);
  57579. wolfSSL_CTX_free(ctx);
  57580. #endif
  57581. #endif
  57582. return EXPECT_RESULT();
  57583. }
  57584. static int test_wolfSSL_X509_max_name_constraints(void)
  57585. {
  57586. EXPECT_DECLS;
  57587. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  57588. !defined(IGNORE_NAME_CONSTRAINTS)
  57589. /* Only test if max name constraints has not been modified */
  57590. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  57591. WOLFSSL_CTX* ctx = NULL;
  57592. /* File contains a certificate with 130 name constraints */
  57593. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  57594. #ifndef NO_WOLFSSL_SERVER
  57595. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57596. #else
  57597. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57598. #endif
  57599. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  57600. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  57601. wolfSSL_CTX_free(ctx);
  57602. #endif
  57603. #endif
  57604. return EXPECT_RESULT();
  57605. }
  57606. static int test_wolfSSL_X509(void)
  57607. {
  57608. EXPECT_DECLS;
  57609. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57610. !defined(NO_RSA)
  57611. X509* x509 = NULL;
  57612. #ifndef NO_BIO
  57613. BIO* bio = NULL;
  57614. X509_STORE_CTX* ctx = NULL;
  57615. X509_STORE* store = NULL;
  57616. #endif
  57617. char der[] = "certs/ca-cert.der";
  57618. XFILE fp = XBADFILE;
  57619. ExpectNotNull(x509 = X509_new());
  57620. X509_free(x509);
  57621. x509 = NULL;
  57622. #ifndef NO_BIO
  57623. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57624. SSL_FILETYPE_PEM));
  57625. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  57626. #ifdef WOLFSSL_CERT_GEN
  57627. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  57628. #endif
  57629. ExpectNotNull(ctx = X509_STORE_CTX_new());
  57630. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  57631. ExpectNotNull(store = X509_STORE_new());
  57632. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  57633. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  57634. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  57635. X509_STORE_CTX_free(ctx);
  57636. X509_STORE_free(store);
  57637. X509_free(x509);
  57638. x509 = NULL;
  57639. BIO_free(bio);
  57640. #endif
  57641. /** d2i_X509_fp test **/
  57642. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57643. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  57644. ExpectNotNull(x509);
  57645. X509_free(x509);
  57646. x509 = NULL;
  57647. if (fp != XBADFILE) {
  57648. XFCLOSE(fp);
  57649. fp = XBADFILE;
  57650. }
  57651. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57652. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  57653. ExpectNotNull(x509);
  57654. X509_free(x509);
  57655. if (fp != XBADFILE)
  57656. XFCLOSE(fp);
  57657. /* X509_up_ref test */
  57658. ExpectIntEQ(X509_up_ref(NULL), 0);
  57659. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  57660. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  57661. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  57662. X509_free(x509); /* refCount = 2 */
  57663. X509_free(x509); /* refCount = 1 */
  57664. X509_free(x509); /* refCount = 0, free */
  57665. #endif
  57666. return EXPECT_RESULT();
  57667. }
  57668. static int test_wolfSSL_X509_get_ext_count(void)
  57669. {
  57670. EXPECT_DECLS;
  57671. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57672. !defined(NO_RSA)
  57673. int ret = 0;
  57674. WOLFSSL_X509* x509 = NULL;
  57675. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  57676. XFILE f = XBADFILE;
  57677. /* NULL parameter check */
  57678. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57679. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  57680. SSL_FILETYPE_PEM));
  57681. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57682. wolfSSL_X509_free(x509);
  57683. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  57684. SSL_FILETYPE_PEM));
  57685. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57686. wolfSSL_X509_free(x509);
  57687. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  57688. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  57689. if (f != XBADFILE)
  57690. XFCLOSE(f);
  57691. /* wolfSSL_X509_get_ext_count() valid input */
  57692. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  57693. /* wolfSSL_X509_get_ext_count() NULL argument */
  57694. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57695. wolfSSL_X509_free(x509);
  57696. #endif
  57697. return EXPECT_RESULT();
  57698. }
  57699. static int test_wolfSSL_X509_sign2(void)
  57700. {
  57701. EXPECT_DECLS;
  57702. /* test requires WOLFSSL_AKID_NAME to match expected output */
  57703. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  57704. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  57705. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  57706. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  57707. defined(WOLFSSL_IP_ALT_NAME))
  57708. WOLFSSL_X509 *x509 = NULL;
  57709. WOLFSSL_X509 *ca = NULL;
  57710. const unsigned char *der = NULL;
  57711. const unsigned char *pt = NULL;
  57712. WOLFSSL_EVP_PKEY *priv = NULL;
  57713. WOLFSSL_X509_NAME *name = NULL;
  57714. int derSz;
  57715. #ifndef NO_ASN_TIME
  57716. WOLFSSL_ASN1_TIME *notBefore = NULL;
  57717. WOLFSSL_ASN1_TIME *notAfter = NULL;
  57718. const int year = 365*24*60*60;
  57719. const int day = 24*60*60;
  57720. const int hour = 60*60;
  57721. const int mini = 60;
  57722. time_t t;
  57723. #endif
  57724. const unsigned char expected[] = {
  57725. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  57726. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  57727. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  57728. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  57729. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  57730. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  57731. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  57732. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  57733. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  57734. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  57735. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  57736. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  57737. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  57738. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  57739. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57740. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  57741. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  57742. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  57743. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  57744. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  57745. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  57746. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  57747. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  57748. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  57749. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  57750. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  57751. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  57752. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  57753. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  57754. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  57755. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  57756. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  57757. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  57758. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57759. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  57760. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  57761. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  57762. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  57763. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  57764. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  57765. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  57766. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  57767. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  57768. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  57769. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  57770. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  57771. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  57772. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  57773. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  57774. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  57775. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  57776. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  57777. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  57778. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  57779. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  57780. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  57781. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  57782. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  57783. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  57784. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  57785. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  57786. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  57787. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57788. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57789. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  57790. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57791. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57792. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  57793. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  57794. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  57795. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  57796. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  57797. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  57798. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  57799. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  57800. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  57801. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  57802. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  57803. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  57804. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  57805. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  57806. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  57807. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  57808. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  57809. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  57810. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  57811. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  57812. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  57813. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  57814. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  57815. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  57816. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  57817. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  57818. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  57819. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  57820. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  57821. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  57822. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  57823. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  57824. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  57825. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  57826. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  57827. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  57828. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  57829. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  57830. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  57831. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  57832. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  57833. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  57834. };
  57835. pt = ca_key_der_2048;
  57836. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  57837. sizeof_ca_key_der_2048));
  57838. pt = client_cert_der_2048;
  57839. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  57840. sizeof_client_cert_der_2048));
  57841. pt = ca_cert_der_2048;
  57842. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  57843. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  57844. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  57845. #ifndef NO_ASN_TIME
  57846. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  57847. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  57848. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  57849. ExpectIntEQ(notAfter->length, 13);
  57850. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  57851. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  57852. #endif
  57853. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  57854. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  57855. ExpectIntEQ(derSz, sizeof(expected));
  57856. #ifndef NO_ASN_TIME
  57857. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  57858. #endif
  57859. wolfSSL_X509_free(ca);
  57860. wolfSSL_X509_free(x509);
  57861. wolfSSL_EVP_PKEY_free(priv);
  57862. #ifndef NO_ASN_TIME
  57863. wolfSSL_ASN1_TIME_free(notBefore);
  57864. wolfSSL_ASN1_TIME_free(notAfter);
  57865. #endif
  57866. #endif
  57867. return EXPECT_RESULT();
  57868. }
  57869. static int test_wolfSSL_X509_sign(void)
  57870. {
  57871. EXPECT_DECLS;
  57872. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  57873. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  57874. int ret = 0;
  57875. char *cn = NULL;
  57876. word32 cnSz = 0;
  57877. X509_NAME *name = NULL;
  57878. X509 *x509 = NULL;
  57879. X509 *ca = NULL;
  57880. DecodedCert dCert;
  57881. EVP_PKEY *pub = NULL;
  57882. EVP_PKEY *priv = NULL;
  57883. EVP_MD_CTX *mctx = NULL;
  57884. #if defined(USE_CERT_BUFFERS_1024)
  57885. const unsigned char* rsaPriv = client_key_der_1024;
  57886. const unsigned char* rsaPub = client_keypub_der_1024;
  57887. const unsigned char* certIssuer = client_cert_der_1024;
  57888. long clientKeySz = (long)sizeof_client_key_der_1024;
  57889. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  57890. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  57891. #elif defined(USE_CERT_BUFFERS_2048)
  57892. const unsigned char* rsaPriv = client_key_der_2048;
  57893. const unsigned char* rsaPub = client_keypub_der_2048;
  57894. const unsigned char* certIssuer = client_cert_der_2048;
  57895. long clientKeySz = (long)sizeof_client_key_der_2048;
  57896. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  57897. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  57898. #endif
  57899. byte sn[16];
  57900. int snSz = sizeof(sn);
  57901. /* Set X509_NAME fields */
  57902. ExpectNotNull(name = X509_NAME_new());
  57903. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  57904. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  57905. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  57906. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  57907. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  57908. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  57909. /* Get private and public keys */
  57910. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  57911. clientKeySz));
  57912. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  57913. ExpectNotNull(x509 = X509_new());
  57914. /* Set version 3 */
  57915. ExpectIntNE(X509_set_version(x509, 2L), 0);
  57916. /* Set subject name, add pubkey, and sign certificate */
  57917. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  57918. X509_NAME_free(name);
  57919. name = NULL;
  57920. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  57921. #ifdef WOLFSSL_ALT_NAMES
  57922. /* Add some subject alt names */
  57923. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  57924. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  57925. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57926. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  57927. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57928. "sphygmomanometer",
  57929. ASN_DNS_TYPE), SSL_SUCCESS);
  57930. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57931. "supercalifragilisticexpialidocious",
  57932. ASN_DNS_TYPE), SSL_SUCCESS);
  57933. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57934. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  57935. ASN_DNS_TYPE), SSL_SUCCESS);
  57936. #ifdef WOLFSSL_IP_ALT_NAME
  57937. {
  57938. unsigned char ip4_type[] = {127,128,0,255};
  57939. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  57940. 0xff, 0xee, 0x99, 0x88,
  57941. 0x77, 0x66, 0x55, 0x44,
  57942. 0x00, 0x33, 0x22, 0x11};
  57943. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  57944. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  57945. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  57946. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  57947. }
  57948. #endif
  57949. #endif /* WOLFSSL_ALT_NAMES */
  57950. {
  57951. ASN1_UTCTIME* infinite_past = NULL;
  57952. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  57953. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  57954. ASN1_UTCTIME_free(infinite_past);
  57955. }
  57956. /* test valid sign case */
  57957. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  57958. /* test valid X509_sign_ctx case */
  57959. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57960. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  57961. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  57962. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  57963. ExpectIntEQ(X509_get_ext_count(x509), 1);
  57964. #endif
  57965. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  57966. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  57967. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  57968. #endif
  57969. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  57970. WOLFSSL_SUCCESS);
  57971. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  57972. /* Variation in size depends on ASN.1 encoding when MSB is set.
  57973. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  57974. * with the MSB set. See GenerateInteger in asn.c */
  57975. #ifndef USE_CERT_BUFFERS_1024
  57976. #ifndef WOLFSSL_ALT_NAMES
  57977. /* Valid case - size should be 781-786 with 16 byte serial number */
  57978. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  57979. #elif defined(WOLFSSL_IP_ALT_NAME)
  57980. /* Valid case - size should be 955-960 with 16 byte serial number */
  57981. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  57982. #else
  57983. /* Valid case - size should be 926-931 with 16 byte serial number */
  57984. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  57985. #endif
  57986. #else
  57987. #ifndef WOLFSSL_ALT_NAMES
  57988. /* Valid case - size should be 537-542 with 16 byte serial number */
  57989. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  57990. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  57991. /* Valid case - size should be 695-670 with 16 byte serial number */
  57992. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  57993. #else
  57994. /* Valid case - size should be 666-671 with 16 byte serial number */
  57995. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  57996. #endif
  57997. #endif
  57998. /* check that issuer name is as expected after signature */
  57999. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  58000. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  58001. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  58002. ExpectNotNull(name = X509_get_subject_name(ca));
  58003. cnSz = X509_NAME_get_sz(name);
  58004. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58005. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58006. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  58007. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58008. cn = NULL;
  58009. #ifdef WOLFSSL_MULTI_ATTRIB
  58010. /* test adding multiple OU's to the signer */
  58011. ExpectNotNull(name = X509_get_subject_name(ca));
  58012. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58013. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  58014. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58015. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  58016. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  58017. #endif
  58018. ExpectNotNull(name = X509_get_subject_name(ca));
  58019. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  58020. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58021. ExpectNotNull(name = X509_get_issuer_name(x509));
  58022. cnSz = X509_NAME_get_sz(name);
  58023. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58024. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58025. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  58026. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  58027. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58028. cn = NULL;
  58029. FreeDecodedCert(&dCert);
  58030. /* Test invalid parameters */
  58031. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  58032. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  58033. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  58034. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  58035. EVP_MD_CTX_free(mctx);
  58036. mctx = NULL;
  58037. ExpectNotNull(mctx = EVP_MD_CTX_new());
  58038. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  58039. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  58040. /* test invalid version number */
  58041. #if defined(OPENSSL_ALL)
  58042. ExpectIntNE(X509_set_version(x509, 6L), 0);
  58043. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58044. /* uses ParseCert which fails on bad version number */
  58045. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58046. #endif
  58047. EVP_MD_CTX_free(mctx);
  58048. EVP_PKEY_free(priv);
  58049. EVP_PKEY_free(pub);
  58050. X509_free(x509);
  58051. X509_free(ca);
  58052. #endif
  58053. return EXPECT_RESULT();
  58054. }
  58055. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  58056. {
  58057. EXPECT_DECLS;
  58058. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58059. X509* x509 = NULL;
  58060. const X509_ALGOR* alg;
  58061. ExpectNotNull(x509 = X509_new());
  58062. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  58063. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58064. X509_free(x509);
  58065. #endif
  58066. return EXPECT_RESULT();
  58067. }
  58068. static int test_wolfSSL_X509_ALGOR_get0(void)
  58069. {
  58070. EXPECT_DECLS;
  58071. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58072. !defined(NO_SHA256) && !defined(NO_RSA)
  58073. X509* x509 = NULL;
  58074. const ASN1_OBJECT* obj = NULL;
  58075. const X509_ALGOR* alg = NULL;
  58076. X509_ALGOR* alg2 = NULL;
  58077. int pptype = 0;
  58078. const void *ppval = NULL;
  58079. byte* der = NULL;
  58080. const byte* tmp = NULL;
  58081. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  58082. SSL_FILETYPE_PEM));
  58083. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58084. /* Invalid case */
  58085. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  58086. ExpectNull(obj);
  58087. /* Valid case */
  58088. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  58089. ExpectNotNull(obj);
  58090. ExpectNull(ppval);
  58091. ExpectIntNE(pptype, 0);
  58092. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  58093. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  58094. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  58095. tmp = der;
  58096. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  58097. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  58098. X509_free(x509);
  58099. X509_ALGOR_free(alg2);
  58100. #endif
  58101. return EXPECT_RESULT();
  58102. }
  58103. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  58104. {
  58105. EXPECT_DECLS;
  58106. #if defined(OPENSSL_EXTRA)
  58107. X509_VERIFY_PARAM *paramTo = NULL;
  58108. X509_VERIFY_PARAM *paramFrom = NULL;
  58109. char testIPv4[] = "127.0.0.1";
  58110. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  58111. char testhostName1[] = "foo.hoge.com";
  58112. char testhostName2[] = "foobar.hoge.com";
  58113. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  58114. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  58115. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  58116. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  58117. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  58118. (int)XSTRLEN(testhostName1)), 1);
  58119. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  58120. (int)XSTRLEN(testhostName1)));
  58121. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  58122. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  58123. ExpectIntEQ(0x01, paramFrom->hostFlags);
  58124. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  58125. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  58126. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58127. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  58128. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  58129. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58130. /* null pointer */
  58131. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  58132. /* in the case of "from" null, returns success */
  58133. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  58134. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  58135. /* inherit flags test : VPARAM_DEFAULT */
  58136. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58137. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58138. (int)XSTRLEN(testhostName1)));
  58139. ExpectIntEQ(0x01, paramTo->hostFlags);
  58140. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58141. /* inherit flags test : VPARAM OVERWRITE */
  58142. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58143. (int)XSTRLEN(testhostName2)), 1);
  58144. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58145. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58146. if (paramTo != NULL) {
  58147. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  58148. }
  58149. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58150. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58151. (int)XSTRLEN(testhostName1)));
  58152. ExpectIntEQ(0x01, paramTo->hostFlags);
  58153. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58154. /* inherit flags test : VPARAM_RESET_FLAGS */
  58155. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58156. (int)XSTRLEN(testhostName2)), 1);
  58157. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58158. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  58159. if (paramTo != NULL) {
  58160. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  58161. }
  58162. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58163. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58164. (int)XSTRLEN(testhostName1)));
  58165. ExpectIntEQ(0x01, paramTo->hostFlags);
  58166. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58167. /* inherit flags test : VPARAM_LOCKED */
  58168. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58169. (int)XSTRLEN(testhostName2)), 1);
  58170. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58171. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58172. if (paramTo != NULL) {
  58173. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  58174. }
  58175. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58176. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  58177. (int)XSTRLEN(testhostName2)));
  58178. ExpectIntEQ(0x00, paramTo->hostFlags);
  58179. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58180. /* test for incorrect parameters */
  58181. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  58182. 0);
  58183. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  58184. /* inherit flags test : VPARAM_ONCE, not testable yet */
  58185. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  58186. 1);
  58187. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  58188. X509_V_FLAG_CRL_CHECK_ALL);
  58189. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  58190. X509_V_FLAG_CRL_CHECK_ALL), 1);
  58191. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  58192. X509_VERIFY_PARAM_free(paramTo);
  58193. X509_VERIFY_PARAM_free(paramFrom);
  58194. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  58195. #endif
  58196. return EXPECT_RESULT();
  58197. }
  58198. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  58199. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  58200. static int test_wolfSSL_check_domain_verify_count = 0;
  58201. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  58202. WOLFSSL_X509_STORE_CTX* store)
  58203. {
  58204. EXPECT_DECLS;
  58205. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  58206. ExpectIntEQ(preverify, 1);
  58207. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  58208. return EXPECT_SUCCESS();
  58209. }
  58210. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  58211. {
  58212. EXPECT_DECLS;
  58213. X509_VERIFY_PARAM *param = NULL;
  58214. ExpectNotNull(param = SSL_get0_param(ssl));
  58215. /* Domain check should only be done on the leaf cert */
  58216. X509_VERIFY_PARAM_set_hostflags(param,
  58217. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  58218. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  58219. "wolfSSL Server Chain", 0), 1);
  58220. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  58221. test_wolfSSL_check_domain_verify_cb);
  58222. return EXPECT_RESULT();
  58223. }
  58224. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  58225. {
  58226. EXPECT_DECLS;
  58227. /* Use a cert with different domains in chain */
  58228. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  58229. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  58230. return EXPECT_RESULT();
  58231. }
  58232. static int test_wolfSSL_check_domain(void)
  58233. {
  58234. EXPECT_DECLS;
  58235. test_ssl_cbf func_cb_client;
  58236. test_ssl_cbf func_cb_server;
  58237. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  58238. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  58239. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  58240. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  58241. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  58242. &func_cb_server, NULL), TEST_SUCCESS);
  58243. /* Should have been called once for each cert in sent chain */
  58244. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  58245. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  58246. #else
  58247. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  58248. #endif
  58249. return EXPECT_RESULT();
  58250. }
  58251. #else
  58252. static int test_wolfSSL_check_domain(void)
  58253. {
  58254. EXPECT_DECLS;
  58255. return EXPECT_RESULT();
  58256. }
  58257. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  58258. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  58259. {
  58260. EXPECT_DECLS;
  58261. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58262. X509* x509 = NULL;
  58263. X509_PUBKEY* pubKey;
  58264. ExpectNotNull(x509 = X509_new());
  58265. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  58266. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  58267. X509_free(x509);
  58268. #endif
  58269. return EXPECT_RESULT();
  58270. }
  58271. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  58272. {
  58273. EXPECT_DECLS;
  58274. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58275. !defined(NO_SHA256) && !defined(NO_RSA)
  58276. X509* x509 = NULL;
  58277. ASN1_OBJECT* obj = NULL;
  58278. const ASN1_OBJECT* pa_oid = NULL;
  58279. X509_PUBKEY* pubKey = NULL;
  58280. X509_PUBKEY* pubKey2 = NULL;
  58281. EVP_PKEY* evpKey = NULL;
  58282. const unsigned char *pk = NULL;
  58283. int ppklen;
  58284. int pptype;
  58285. X509_ALGOR *pa = NULL;
  58286. const void *pval;
  58287. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  58288. SSL_FILETYPE_PEM));
  58289. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58290. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58291. ExpectNotNull(pk);
  58292. ExpectNotNull(pa);
  58293. ExpectNotNull(pubKey);
  58294. ExpectIntGT(ppklen, 0);
  58295. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  58296. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58297. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58298. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58299. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58300. ExpectNotNull(pk);
  58301. ExpectNotNull(pa);
  58302. ExpectIntGT(ppklen, 0);
  58303. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58304. ExpectNotNull(pa_oid);
  58305. ExpectNull(pval);
  58306. ExpectIntEQ(pptype, V_ASN1_NULL);
  58307. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  58308. X509_PUBKEY_free(pubKey2);
  58309. X509_free(x509);
  58310. EVP_PKEY_free(evpKey);
  58311. #endif
  58312. return EXPECT_RESULT();
  58313. }
  58314. static int test_wolfSSL_X509_PUBKEY_EC(void)
  58315. {
  58316. EXPECT_DECLS;
  58317. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  58318. X509* x509 = NULL;
  58319. ASN1_OBJECT* obj = NULL;
  58320. ASN1_OBJECT* poid = NULL;
  58321. const ASN1_OBJECT* pa_oid = NULL;
  58322. X509_PUBKEY* pubKey = NULL;
  58323. X509_PUBKEY* pubKey2 = NULL;
  58324. EVP_PKEY* evpKey = NULL;
  58325. const unsigned char *pk = NULL;
  58326. int ppklen;
  58327. int pptype;
  58328. X509_ALGOR *pa = NULL;
  58329. const void *pval;
  58330. char buf[50];
  58331. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  58332. SSL_FILETYPE_PEM));
  58333. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58334. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58335. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58336. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58337. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58338. ExpectNotNull(pk);
  58339. ExpectNotNull(pa);
  58340. ExpectIntGT(ppklen, 0);
  58341. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58342. ExpectNotNull(pa_oid);
  58343. ExpectNotNull(pval);
  58344. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  58345. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  58346. poid = (ASN1_OBJECT *)pval;
  58347. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  58348. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  58349. X509_PUBKEY_free(pubKey2);
  58350. X509_free(x509);
  58351. EVP_PKEY_free(evpKey);
  58352. #endif
  58353. return EXPECT_RESULT();
  58354. }
  58355. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  58356. {
  58357. EXPECT_DECLS;
  58358. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  58359. word32 bytes;
  58360. #ifdef USE_CERT_BUFFERS_1024
  58361. byte tmp[ONEK_BUF];
  58362. #elif defined(USE_CERT_BUFFERS_2048)
  58363. byte tmp[TWOK_BUF];
  58364. #else
  58365. byte tmp[TWOK_BUF];
  58366. #endif /* END USE_CERT_BUFFERS_1024 */
  58367. const unsigned char* dsaKeyDer = tmp;
  58368. ASN1_OBJECT* obj = NULL;
  58369. ASN1_STRING* str;
  58370. const ASN1_OBJECT* pa_oid = NULL;
  58371. X509_PUBKEY* pubKey = NULL;
  58372. EVP_PKEY* evpKey = NULL;
  58373. const unsigned char *pk = NULL;
  58374. int ppklen, pptype;
  58375. X509_ALGOR *pa = NULL;
  58376. const void *pval;
  58377. #ifdef USE_CERT_BUFFERS_1024
  58378. XMEMSET(tmp, 0, sizeof(tmp));
  58379. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  58380. bytes = sizeof_dsa_key_der_1024;
  58381. #elif defined(USE_CERT_BUFFERS_2048)
  58382. XMEMSET(tmp, 0, sizeof(tmp));
  58383. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  58384. bytes = sizeof_dsa_key_der_2048;
  58385. #else
  58386. {
  58387. XFILE fp = XBADFILE;
  58388. XMEMSET(tmp, 0, sizeof(tmp));
  58389. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  58390. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  58391. if (fp != XBADFILE)
  58392. XFCLOSE(fp);
  58393. }
  58394. #endif
  58395. /* Initialize pkey with der format dsa key */
  58396. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  58397. ExpectNotNull(pubKey = X509_PUBKEY_new());
  58398. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  58399. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58400. ExpectNotNull(pk);
  58401. ExpectNotNull(pa);
  58402. ExpectIntGT(ppklen, 0);
  58403. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58404. ExpectNotNull(pa_oid);
  58405. ExpectNotNull(pval);
  58406. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  58407. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  58408. str = (ASN1_STRING *)pval;
  58409. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  58410. #ifdef USE_CERT_BUFFERS_1024
  58411. ExpectIntEQ(ASN1_STRING_length(str), 291);
  58412. #else
  58413. ExpectIntEQ(ASN1_STRING_length(str), 549);
  58414. #endif /* END USE_CERT_BUFFERS_1024 */
  58415. X509_PUBKEY_free(pubKey);
  58416. EVP_PKEY_free(evpKey);
  58417. #endif
  58418. return EXPECT_RESULT();
  58419. }
  58420. static int test_wolfSSL_BUF(void)
  58421. {
  58422. EXPECT_DECLS;
  58423. #if defined(OPENSSL_EXTRA)
  58424. BUF_MEM* buf = NULL;
  58425. ExpectNotNull(buf = BUF_MEM_new());
  58426. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  58427. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  58428. BUF_MEM_free(buf);
  58429. #endif
  58430. return EXPECT_RESULT();
  58431. }
  58432. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58433. static int stub_rand_seed(const void *buf, int num)
  58434. {
  58435. (void)buf;
  58436. (void)num;
  58437. return 123;
  58438. }
  58439. static int stub_rand_bytes(unsigned char *buf, int num)
  58440. {
  58441. (void)buf;
  58442. (void)num;
  58443. return 456;
  58444. }
  58445. static byte* was_stub_rand_cleanup_called(void)
  58446. {
  58447. static byte was_called = 0;
  58448. return &was_called;
  58449. }
  58450. static void stub_rand_cleanup(void)
  58451. {
  58452. byte* was_called = was_stub_rand_cleanup_called();
  58453. *was_called = 1;
  58454. return;
  58455. }
  58456. static byte* was_stub_rand_add_called(void)
  58457. {
  58458. static byte was_called = 0;
  58459. return &was_called;
  58460. }
  58461. static int stub_rand_add(const void *buf, int num, double entropy)
  58462. {
  58463. byte* was_called = was_stub_rand_add_called();
  58464. (void)buf;
  58465. (void)num;
  58466. (void)entropy;
  58467. *was_called = 1;
  58468. return 0;
  58469. }
  58470. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  58471. {
  58472. (void)buf;
  58473. (void)num;
  58474. return 9876;
  58475. }
  58476. static int stub_rand_status(void)
  58477. {
  58478. return 5432;
  58479. }
  58480. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58481. static int test_wolfSSL_RAND_set_rand_method(void)
  58482. {
  58483. EXPECT_DECLS;
  58484. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58485. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  58486. unsigned char* buf = NULL;
  58487. int num = 0;
  58488. double entropy = 0;
  58489. int ret;
  58490. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  58491. byte* was_add_called = was_stub_rand_add_called();
  58492. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  58493. DYNAMIC_TYPE_TMP_BUFFER));
  58494. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  58495. ExpectIntEQ(*was_cleanup_called, 0);
  58496. RAND_cleanup();
  58497. ExpectIntEQ(*was_cleanup_called, 0);
  58498. rand_methods.seed = &stub_rand_seed;
  58499. rand_methods.bytes = &stub_rand_bytes;
  58500. rand_methods.cleanup = &stub_rand_cleanup;
  58501. rand_methods.add = &stub_rand_add;
  58502. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  58503. rand_methods.status = &stub_rand_status;
  58504. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  58505. ExpectIntEQ(RAND_seed(buf, num), 123);
  58506. ExpectIntEQ(RAND_bytes(buf, num), 456);
  58507. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  58508. ExpectIntEQ(RAND_status(), 5432);
  58509. ExpectIntEQ(*was_add_called, 0);
  58510. /* The function pointer for RAND_add returns int, but RAND_add itself
  58511. * returns void. */
  58512. RAND_add(buf, num, entropy);
  58513. ExpectIntEQ(*was_add_called, 1);
  58514. was_add_called = 0;
  58515. ExpectIntEQ(*was_cleanup_called, 0);
  58516. RAND_cleanup();
  58517. ExpectIntEQ(*was_cleanup_called, 1);
  58518. *was_cleanup_called = 0;
  58519. ret = RAND_set_rand_method(NULL);
  58520. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  58521. ExpectIntNE(RAND_status(), 5432);
  58522. ExpectIntEQ(*was_cleanup_called, 0);
  58523. RAND_cleanup();
  58524. ExpectIntEQ(*was_cleanup_called, 0);
  58525. RAND_set_rand_method(NULL);
  58526. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58527. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58528. return EXPECT_RESULT();
  58529. }
  58530. static int test_wolfSSL_RAND_bytes(void)
  58531. {
  58532. EXPECT_DECLS;
  58533. #if defined(OPENSSL_EXTRA)
  58534. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  58535. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  58536. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  58537. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  58538. int max_bufsize;
  58539. byte *my_buf = NULL;
  58540. /* sanity check */
  58541. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  58542. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  58543. max_bufsize = size4;
  58544. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  58545. DYNAMIC_TYPE_TMP_BUFFER));
  58546. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  58547. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  58548. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  58549. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  58550. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  58551. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  58552. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  58553. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58554. #endif
  58555. return EXPECT_RESULT();
  58556. }
  58557. static int test_wolfSSL_RAND(void)
  58558. {
  58559. EXPECT_DECLS;
  58560. #if defined(OPENSSL_EXTRA)
  58561. byte seed[16];
  58562. XMEMSET(seed, 0, sizeof(seed));
  58563. /* No global methods set. */
  58564. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  58565. ExpectIntEQ(RAND_poll(), 1);
  58566. RAND_cleanup();
  58567. ExpectIntEQ(RAND_egd(NULL), -1);
  58568. #ifndef NO_FILESYSTEM
  58569. {
  58570. char fname[100];
  58571. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  58572. ExpectIntEQ(RAND_write_file(NULL), 0);
  58573. }
  58574. #endif
  58575. #endif
  58576. return EXPECT_RESULT();
  58577. }
  58578. static int test_wolfSSL_PKCS8_Compat(void)
  58579. {
  58580. EXPECT_DECLS;
  58581. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  58582. !defined(NO_BIO)
  58583. PKCS8_PRIV_KEY_INFO* pt = NULL;
  58584. BIO* bio = NULL;
  58585. XFILE f = XBADFILE;
  58586. int bytes = 0;
  58587. char pkcs8_buffer[512];
  58588. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58589. EVP_PKEY *pkey = NULL;
  58590. #endif
  58591. /* file from wolfssl/certs/ directory */
  58592. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  58593. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  58594. 0);
  58595. if (f != XBADFILE)
  58596. XFCLOSE(f);
  58597. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58598. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  58599. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58600. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  58601. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  58602. /* gets PKCS8 pointer to pkey */
  58603. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  58604. EVP_PKEY_free(pkey);
  58605. #endif
  58606. BIO_free(bio);
  58607. PKCS8_PRIV_KEY_INFO_free(pt);
  58608. #endif
  58609. return EXPECT_RESULT();
  58610. }
  58611. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  58612. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  58613. {
  58614. (void)passwd;
  58615. (void)sz;
  58616. (void)rw;
  58617. (void)userdata;
  58618. return -1;
  58619. }
  58620. #endif
  58621. static int test_wolfSSL_PKCS8_d2i(void)
  58622. {
  58623. EXPECT_DECLS;
  58624. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  58625. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  58626. * requires a 12 byte password in FIPS mode. This test ends up
  58627. * trying to use an 8 byte password. */
  58628. #ifndef NO_FILESYSTEM
  58629. unsigned char pkcs8_buffer[2048];
  58630. const unsigned char* p = NULL;
  58631. int bytes = 0;
  58632. XFILE file = XBADFILE;
  58633. WOLFSSL_EVP_PKEY* pkey = NULL;
  58634. #ifndef NO_BIO
  58635. BIO* bio = NULL;
  58636. #if defined(OPENSSL_ALL) && \
  58637. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  58638. defined(HAVE_ECC)) && \
  58639. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58640. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  58641. #endif
  58642. #endif
  58643. #ifndef NO_RSA
  58644. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  58645. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  58646. #ifndef NO_DES3
  58647. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  58648. #endif
  58649. #endif /* NO_RSA */
  58650. #ifdef HAVE_ECC
  58651. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  58652. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  58653. #ifndef NO_DES3
  58654. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  58655. #endif
  58656. #endif /* HAVE_ECC */
  58657. #endif /* !NO_FILESYSTEM */
  58658. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  58659. #ifndef NO_RSA
  58660. #ifdef USE_CERT_BUFFERS_1024
  58661. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  58662. int rsaSz = sizeof_server_key_der_1024;
  58663. #else
  58664. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  58665. int rsaSz = sizeof_server_key_der_2048;
  58666. #endif
  58667. #endif
  58668. #ifdef HAVE_ECC
  58669. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  58670. int ecSz = sizeof_ecc_key_der_256;
  58671. #endif
  58672. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  58673. #ifndef NO_FILESYSTEM
  58674. (void)pkcs8_buffer;
  58675. (void)p;
  58676. (void)bytes;
  58677. (void)file;
  58678. #ifndef NO_BIO
  58679. (void)bio;
  58680. #endif
  58681. #endif
  58682. #ifdef OPENSSL_ALL
  58683. #ifndef NO_RSA
  58684. /* Try to auto-detect normal RSA private key */
  58685. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  58686. EVP_PKEY_free(pkey);
  58687. pkey = NULL;
  58688. #endif
  58689. #ifdef HAVE_ECC
  58690. /* Try to auto-detect normal EC private key */
  58691. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  58692. EVP_PKEY_free(pkey);
  58693. pkey = NULL;
  58694. #endif
  58695. #endif /* OPENSSL_ALL */
  58696. #ifndef NO_FILESYSTEM
  58697. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58698. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  58699. NULL), 0);
  58700. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  58701. NULL), 0);
  58702. #endif
  58703. #ifndef NO_RSA
  58704. /* Get DER encoded RSA PKCS#8 data. */
  58705. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  58706. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58707. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58708. file)), 0);
  58709. if (file != XBADFILE) {
  58710. XFCLOSE(file);
  58711. file = XBADFILE;
  58712. }
  58713. p = pkcs8_buffer;
  58714. #ifdef OPENSSL_ALL
  58715. /* Try to decode - auto-detect key type. */
  58716. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58717. #else
  58718. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  58719. #endif
  58720. /* Get PEM encoded RSA PKCS#8 data. */
  58721. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  58722. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58723. file)), 0);
  58724. if (file != XBADFILE) {
  58725. XFCLOSE(file);
  58726. file = XBADFILE;
  58727. }
  58728. #if defined(OPENSSL_ALL) && \
  58729. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58730. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58731. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  58732. NULL), 0);
  58733. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  58734. NULL), 0);
  58735. /* Write PKCS#8 PEM to BIO. */
  58736. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58737. NULL), bytes);
  58738. /* Write PKCS#8 PEM to stderr. */
  58739. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58740. NULL), bytes);
  58741. /* Compare file and written data */
  58742. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58743. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58744. BIO_free(bio);
  58745. bio = NULL;
  58746. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  58747. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  58748. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  58749. #endif
  58750. #if !defined(NO_DES3) && !defined(NO_SHA)
  58751. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58752. /* Write Encrypted PKCS#8 PEM to BIO. */
  58753. bytes = 1834;
  58754. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  58755. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58756. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  58757. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58758. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58759. (void*)"yassl123"));
  58760. EVP_PKEY_free(evpPkey);
  58761. evpPkey = NULL;
  58762. BIO_free(bio);
  58763. bio = NULL;
  58764. #endif /* !NO_DES3 && !NO_SHA */
  58765. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58766. EVP_PKEY_free(pkey);
  58767. pkey = NULL;
  58768. /* PKCS#8 encrypted RSA key */
  58769. #ifndef NO_DES3
  58770. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  58771. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58772. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58773. file)), 0);
  58774. if (file != XBADFILE) {
  58775. XFCLOSE(file);
  58776. file = XBADFILE;
  58777. }
  58778. #if defined(OPENSSL_ALL) && \
  58779. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58780. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58781. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58782. (void*)"yassl123"));
  58783. EVP_PKEY_free(pkey);
  58784. pkey = NULL;
  58785. BIO_free(bio);
  58786. bio = NULL;
  58787. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58788. #endif /* !NO_DES3 */
  58789. #endif /* NO_RSA */
  58790. #ifdef HAVE_ECC
  58791. /* PKCS#8 encode EC key */
  58792. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  58793. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58794. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58795. file)), 0);
  58796. if (file != XBADFILE) {
  58797. XFCLOSE(file);
  58798. file = XBADFILE;
  58799. }
  58800. p = pkcs8_buffer;
  58801. #ifdef OPENSSL_ALL
  58802. /* Try to decode - auto-detect key type. */
  58803. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58804. #else
  58805. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  58806. #endif
  58807. /* Get PEM encoded RSA PKCS#8 data. */
  58808. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  58809. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58810. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58811. file)), 0);
  58812. if (file != XBADFILE) {
  58813. XFCLOSE(file);
  58814. file = XBADFILE;
  58815. }
  58816. #if defined(OPENSSL_ALL) && \
  58817. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  58818. defined(HAVE_AES_CBC)
  58819. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58820. /* Write PKCS#8 PEM to BIO. */
  58821. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58822. NULL), bytes);
  58823. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58824. NULL), bytes);
  58825. /* Compare file and written data */
  58826. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58827. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58828. BIO_free(bio);
  58829. bio = NULL;
  58830. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58831. /* Write Encrypted PKCS#8 PEM to BIO. */
  58832. bytes = 379;
  58833. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58834. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  58835. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58836. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58837. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58838. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58839. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58840. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  58841. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  58842. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58843. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58844. (void*)"yassl123"));
  58845. EVP_PKEY_free(evpPkey);
  58846. evpPkey = NULL;
  58847. BIO_free(bio);
  58848. bio = NULL;
  58849. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  58850. EVP_PKEY_free(pkey);
  58851. pkey = NULL;
  58852. /* PKCS#8 encrypted EC key */
  58853. #ifndef NO_DES3
  58854. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  58855. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58856. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58857. file)), 0);
  58858. if (file != XBADFILE) {
  58859. XFCLOSE(file);
  58860. file = XBADFILE;
  58861. }
  58862. #if defined(OPENSSL_ALL) && \
  58863. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58864. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58865. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58866. (void*)"yassl123"));
  58867. EVP_PKEY_free(pkey);
  58868. pkey = NULL;
  58869. BIO_free(bio);
  58870. bio = NULL;
  58871. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58872. #endif /* !NO_DES3 */
  58873. #endif /* HAVE_ECC */
  58874. #endif /* !NO_FILESYSTEM */
  58875. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  58876. return EXPECT_RESULT();
  58877. }
  58878. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58879. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58880. defined(DEBUG_WOLFSSL)
  58881. #define LOGGING_THREADS 5
  58882. #define ERROR_COUNT 10
  58883. /* copied from logging.c since this is not exposed otherwise */
  58884. #ifndef ERROR_QUEUE_MAX
  58885. #ifdef ERROR_QUEUE_PER_THREAD
  58886. #define ERROR_QUEUE_MAX 16
  58887. #else
  58888. /* this breaks from compat of unlimited error queue size */
  58889. #define ERROR_QUEUE_MAX 100
  58890. #endif
  58891. #endif
  58892. static volatile int loggingThreadsReady;
  58893. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  58894. {
  58895. const char* file;
  58896. int line;
  58897. unsigned long err;
  58898. int errorCount = 0;
  58899. int i;
  58900. (void)args;
  58901. while (!loggingThreadsReady);
  58902. for (i = 0; i < ERROR_COUNT; i++)
  58903. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58904. while ((err = ERR_get_error_line(&file, &line))) {
  58905. AssertIntEQ(err, 990 + errorCount);
  58906. errorCount++;
  58907. }
  58908. AssertIntEQ(errorCount, ERROR_COUNT);
  58909. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  58910. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  58911. errorCount = 0;
  58912. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  58913. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58914. while ((err = ERR_get_error_line(&file, &line))) {
  58915. AssertIntEQ(err, 990 + errorCount);
  58916. errorCount++;
  58917. }
  58918. /* test that the 3 errors over the max were dropped */
  58919. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  58920. WOLFSSL_RETURN_FROM_THREAD(0);
  58921. }
  58922. #endif
  58923. static int test_error_queue_per_thread(void)
  58924. {
  58925. int res = TEST_SKIPPED;
  58926. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58927. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58928. defined(DEBUG_WOLFSSL)
  58929. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  58930. int i;
  58931. ERR_clear_error(); /* clear out any error nodes */
  58932. loggingThreadsReady = 0;
  58933. for (i = 0; i < LOGGING_THREADS; i++)
  58934. start_thread(test_logging, NULL, &loggingThreads[i]);
  58935. loggingThreadsReady = 1;
  58936. for (i = 0; i < LOGGING_THREADS; i++)
  58937. join_thread(loggingThreads[i]);
  58938. res = TEST_SUCCESS;
  58939. #endif
  58940. return res;
  58941. }
  58942. static int test_wolfSSL_ERR_put_error(void)
  58943. {
  58944. EXPECT_DECLS;
  58945. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58946. defined(DEBUG_WOLFSSL)
  58947. const char* file;
  58948. int line;
  58949. ERR_clear_error(); /* clear out any error nodes */
  58950. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58951. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58952. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  58953. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  58954. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  58955. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  58956. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  58957. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  58958. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  58959. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  58960. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  58961. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  58962. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  58963. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  58964. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  58965. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  58966. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  58967. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  58968. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  58969. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  58970. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  58971. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  58972. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  58973. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  58974. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  58975. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  58976. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  58977. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  58978. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  58979. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  58980. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  58981. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  58982. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  58983. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  58984. "this file", 100);
  58985. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  58986. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58987. ExpectIntEQ(line, 100);
  58988. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  58989. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58990. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  58991. #endif
  58992. /* try reading past end of error queue */
  58993. file = NULL;
  58994. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58995. ExpectNull(file);
  58996. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  58997. PEMerr(4,4);
  58998. ExpectIntEQ(ERR_get_error(), 4);
  58999. /* Empty and free up all error nodes */
  59000. ERR_clear_error();
  59001. /* Verify all nodes are cleared */
  59002. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  59003. ERR_clear_error();
  59004. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59005. #endif
  59006. return EXPECT_RESULT();
  59007. }
  59008. /*
  59009. * This is a regression test for a bug where the peek/get error functions were
  59010. * drawing from the end of the queue rather than the front.
  59011. */
  59012. static int test_wolfSSL_ERR_get_error_order(void)
  59013. {
  59014. EXPECT_DECLS;
  59015. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  59016. /* Empty the queue. */
  59017. wolfSSL_ERR_clear_error();
  59018. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  59019. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  59020. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59021. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59022. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59023. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59024. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  59025. return EXPECT_RESULT();
  59026. }
  59027. #ifndef NO_BIO
  59028. static int test_wolfSSL_ERR_print_errors(void)
  59029. {
  59030. EXPECT_DECLS;
  59031. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59032. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  59033. BIO* bio = NULL;
  59034. char buf[1024];
  59035. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59036. ERR_clear_error(); /* clear out any error nodes */
  59037. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59038. /* Choosing -600 as an unused errno. */
  59039. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  59040. ERR_print_errors(bio);
  59041. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  59042. ExpectIntEQ(XSTRNCMP(
  59043. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  59044. buf, 55), 0);
  59045. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  59046. ExpectIntEQ(XSTRNCMP(
  59047. "error:600:wolfSSL library:unknown error number:asn.c:100",
  59048. buf, 56), 0);
  59049. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  59050. ExpectIntEQ(buf[0], '\0');
  59051. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  59052. BIO_free(bio);
  59053. #endif
  59054. return EXPECT_RESULT();
  59055. }
  59056. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59057. defined(DEBUG_WOLFSSL)
  59058. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  59059. {
  59060. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  59061. return 0;
  59062. }
  59063. #endif
  59064. static int test_wolfSSL_ERR_print_errors_cb(void)
  59065. {
  59066. EXPECT_DECLS;
  59067. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59068. defined(DEBUG_WOLFSSL)
  59069. BIO* bio = NULL;
  59070. char buf[1024];
  59071. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59072. ERR_clear_error(); /* clear out any error nodes */
  59073. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59074. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  59075. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  59076. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  59077. ExpectIntEQ(XSTRNCMP(
  59078. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  59079. buf, 53), 0);
  59080. ExpectIntEQ(XSTRNCMP(
  59081. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  59082. buf + 53, 55), 0);
  59083. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  59084. BIO_free(bio);
  59085. #endif
  59086. return EXPECT_RESULT();
  59087. }
  59088. /*
  59089. * Testing WOLFSSL_ERROR_MSG
  59090. */
  59091. static int test_WOLFSSL_ERROR_MSG(void)
  59092. {
  59093. int res = TEST_SKIPPED;
  59094. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  59095. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  59096. const char* msg = TEST_STRING;
  59097. WOLFSSL_ERROR_MSG(msg);
  59098. res = TEST_SUCCESS;
  59099. #endif
  59100. return res;
  59101. } /* End test_WOLFSSL_ERROR_MSG */
  59102. /*
  59103. * Testing wc_ERR_remove_state
  59104. */
  59105. static int test_wc_ERR_remove_state(void)
  59106. {
  59107. int res = TEST_SKIPPED;
  59108. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  59109. wc_ERR_remove_state();
  59110. res = TEST_SUCCESS;
  59111. #endif
  59112. return res;
  59113. } /* End test_wc_ERR_remove_state */
  59114. /*
  59115. * Testing wc_ERR_print_errors_fp
  59116. */
  59117. static int test_wc_ERR_print_errors_fp(void)
  59118. {
  59119. EXPECT_DECLS;
  59120. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  59121. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  59122. long sz;
  59123. XFILE fp = XBADFILE;
  59124. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59125. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  59126. XBADFILE);
  59127. wc_ERR_print_errors_fp(fp);
  59128. #if defined(DEBUG_WOLFSSL)
  59129. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  59130. #ifdef NO_ERROR_QUEUE
  59131. ExpectIntEQ(sz = XFTELL(fp), 0);
  59132. #else
  59133. ExpectIntNE(sz = XFTELL(fp), 0);
  59134. #endif
  59135. #endif
  59136. if (fp != XBADFILE)
  59137. XFCLOSE(fp);
  59138. (void)sz;
  59139. #endif
  59140. return EXPECT_RESULT();
  59141. } /* End test_wc_ERR_print_errors_fp */
  59142. #ifdef DEBUG_WOLFSSL
  59143. static void Logging_cb(const int logLevel, const char *const logMessage)
  59144. {
  59145. (void)logLevel;
  59146. (void)logMessage;
  59147. }
  59148. #endif
  59149. /*
  59150. * Testing wolfSSL_GetLoggingCb
  59151. */
  59152. static int test_wolfSSL_GetLoggingCb(void)
  59153. {
  59154. EXPECT_DECLS;
  59155. #ifdef DEBUG_WOLFSSL
  59156. /* Testing without wolfSSL_SetLoggingCb() */
  59157. ExpectNull(wolfSSL_GetLoggingCb());
  59158. /* Testing with wolfSSL_SetLoggingCb() */
  59159. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  59160. ExpectNotNull(wolfSSL_GetLoggingCb());
  59161. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  59162. #endif
  59163. ExpectNull(wolfSSL_GetLoggingCb());
  59164. return EXPECT_RESULT();
  59165. } /* End test_wolfSSL_GetLoggingCb */
  59166. #endif /* !NO_BIO */
  59167. static int test_wolfSSL_MD4(void)
  59168. {
  59169. EXPECT_DECLS;
  59170. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  59171. MD4_CTX md4;
  59172. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  59173. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  59174. "789012345678901234567890";
  59175. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  59176. "\xcc\x05\x36";
  59177. int msgSz = (int)XSTRLEN(msg);
  59178. XMEMSET(out, 0, sizeof(out));
  59179. MD4_Init(&md4);
  59180. MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz);
  59181. MD4_Final(out, &md4);
  59182. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  59183. #endif
  59184. return EXPECT_RESULT();
  59185. }
  59186. static int test_wolfSSL_MD5(void)
  59187. {
  59188. EXPECT_DECLS;
  59189. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  59190. byte input1[] = "";
  59191. byte input2[] = "message digest";
  59192. byte hash[WC_MD5_DIGEST_SIZE];
  59193. unsigned char output1[] =
  59194. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  59195. unsigned char output2[] =
  59196. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  59197. WOLFSSL_MD5_CTX md5;
  59198. XMEMSET(&md5, 0, sizeof(md5));
  59199. /* Test cases for illegal parameters */
  59200. ExpectIntEQ(MD5_Init(NULL), 0);
  59201. ExpectIntEQ(MD5_Init(&md5), 1);
  59202. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  59203. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  59204. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  59205. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  59206. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  59207. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  59208. /* Init MD5 CTX */
  59209. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  59210. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  59211. 1);
  59212. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  59213. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  59214. /* Init MD5 CTX */
  59215. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  59216. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  59217. (int)XSTRLEN((const char*)input2)), 1);
  59218. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  59219. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  59220. #if !defined(NO_OLD_NAMES) && \
  59221. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  59222. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  59223. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  59224. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  59225. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  59226. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  59227. &hash);
  59228. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  59229. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  59230. &hash);
  59231. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  59232. {
  59233. byte data[] = "Data to be hashed.";
  59234. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  59235. ExpectNotNull(MD5(data, sizeof(data), NULL));
  59236. ExpectNotNull(MD5(data, sizeof(data), hash));
  59237. ExpectNotNull(MD5(NULL, 0, hash));
  59238. ExpectNull(MD5(NULL, sizeof(data), hash));
  59239. }
  59240. #endif
  59241. #endif
  59242. return EXPECT_RESULT();
  59243. }
  59244. static int test_wolfSSL_MD5_Transform(void)
  59245. {
  59246. EXPECT_DECLS;
  59247. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  59248. byte input1[] = "";
  59249. byte input2[] = "abc";
  59250. byte local[WC_MD5_BLOCK_SIZE];
  59251. word32 sLen = 0;
  59252. #ifdef BIG_ENDIAN_ORDER
  59253. unsigned char output1[] =
  59254. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  59255. unsigned char output2[] =
  59256. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  59257. #else
  59258. unsigned char output1[] =
  59259. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  59260. unsigned char output2[] =
  59261. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  59262. #endif
  59263. union {
  59264. wc_Md5 native;
  59265. MD5_CTX compat;
  59266. } md5;
  59267. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  59268. XMEMSET(&local, 0, sizeof(local));
  59269. /* sanity check */
  59270. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  59271. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  59272. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  59273. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59274. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59275. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59276. /* Init MD5 CTX */
  59277. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  59278. /* Do Transform*/
  59279. sLen = (word32)XSTRLEN((char*)input1);
  59280. XMEMCPY(local, input1, sLen);
  59281. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59282. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  59283. /* Init MD5 CTX */
  59284. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  59285. sLen = (word32)XSTRLEN((char*)input2);
  59286. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  59287. XMEMCPY(local, input2, sLen);
  59288. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59289. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  59290. #endif
  59291. return EXPECT_RESULT();
  59292. }
  59293. static int test_wolfSSL_SHA(void)
  59294. {
  59295. EXPECT_DECLS;
  59296. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  59297. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  59298. (!defined(HAVE_FIPS) || \
  59299. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59300. {
  59301. const unsigned char in[] = "abc";
  59302. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  59303. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  59304. unsigned char out[WC_SHA_DIGEST_SIZE];
  59305. unsigned char* p = NULL;
  59306. WOLFSSL_SHA_CTX sha;
  59307. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59308. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  59309. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59310. /* SHA interface test */
  59311. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59312. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  59313. ExpectNotNull(SHA(in, 0, out));
  59314. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  59315. ExpectNotNull(SHA(NULL, 0, out));
  59316. ExpectNotNull(SHA(NULL, 0, NULL));
  59317. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  59318. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59319. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  59320. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  59321. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  59322. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59323. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  59324. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59325. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  59326. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59327. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  59328. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59329. }
  59330. #endif
  59331. #if !defined(NO_SHA256)
  59332. {
  59333. const unsigned char in[] = "abc";
  59334. unsigned char expected[] =
  59335. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  59336. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  59337. "\x15\xAD";
  59338. unsigned char out[WC_SHA256_DIGEST_SIZE];
  59339. unsigned char* p = NULL;
  59340. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  59341. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59342. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  59343. #else
  59344. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  59345. #endif
  59346. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  59347. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59348. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  59349. #else
  59350. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  59351. #endif
  59352. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  59353. }
  59354. #endif
  59355. #if defined(WOLFSSL_SHA384)
  59356. {
  59357. const unsigned char in[] = "abc";
  59358. unsigned char expected[] =
  59359. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  59360. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  59361. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  59362. "\xc8\x25\xa7";
  59363. unsigned char out[WC_SHA384_DIGEST_SIZE];
  59364. unsigned char* p = NULL;
  59365. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  59366. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59367. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  59368. #else
  59369. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  59370. #endif
  59371. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  59372. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59373. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  59374. #else
  59375. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  59376. #endif
  59377. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  59378. }
  59379. #endif
  59380. #if defined(WOLFSSL_SHA512)
  59381. {
  59382. const unsigned char in[] = "abc";
  59383. unsigned char expected[] =
  59384. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  59385. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  59386. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  59387. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  59388. "\xa5\x4c\xa4\x9f";
  59389. unsigned char out[WC_SHA512_DIGEST_SIZE];
  59390. unsigned char* p = NULL;
  59391. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  59392. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59393. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  59394. #else
  59395. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  59396. #endif
  59397. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  59398. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59399. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  59400. #else
  59401. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  59402. #endif
  59403. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  59404. }
  59405. #endif
  59406. #endif
  59407. return EXPECT_RESULT();
  59408. }
  59409. static int test_wolfSSL_SHA_Transform(void)
  59410. {
  59411. EXPECT_DECLS;
  59412. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  59413. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59414. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  59415. byte input1[] = "";
  59416. byte input2[] = "abc";
  59417. byte local[WC_SHA_BLOCK_SIZE];
  59418. word32 sLen = 0;
  59419. #ifdef BIG_ENDIAN_ORDER
  59420. unsigned char output1[] =
  59421. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  59422. "\x09\xf7\x3a\x93";
  59423. unsigned char output2[] =
  59424. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  59425. "\x7c\x6e\x08\xb8";
  59426. #else
  59427. unsigned char output1[] =
  59428. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  59429. "\x93\x3a\xf7\x09";
  59430. unsigned char output2[] =
  59431. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  59432. "\xb8\x08\x6e\x7c";
  59433. #endif
  59434. union {
  59435. wc_Sha native;
  59436. SHA_CTX compat;
  59437. } sha;
  59438. union {
  59439. wc_Sha native;
  59440. SHA_CTX compat;
  59441. } sha1;
  59442. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  59443. XMEMSET(&local, 0, sizeof(local));
  59444. /* sanity check */
  59445. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  59446. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  59447. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  59448. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  59449. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  59450. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  59451. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59452. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59453. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59454. /* Init SHA CTX */
  59455. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59456. /* Do Transform*/
  59457. sLen = (word32)XSTRLEN((char*)input1);
  59458. XMEMCPY(local, input1, sLen);
  59459. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59460. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59461. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59462. /* Init SHA CTX */
  59463. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59464. sLen = (word32)XSTRLEN((char*)input2);
  59465. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59466. XMEMCPY(local, input2, sLen);
  59467. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59468. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59469. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59470. /* SHA1 */
  59471. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59472. /* Init SHA CTX */
  59473. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59474. /* Do Transform*/
  59475. sLen = (word32)XSTRLEN((char*)input1);
  59476. XMEMCPY(local, input1, sLen);
  59477. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59478. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59479. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  59480. /* Init SHA CTX */
  59481. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59482. sLen = (word32)XSTRLEN((char*)input2);
  59483. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59484. XMEMCPY(local, input2, sLen);
  59485. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59486. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59487. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  59488. #endif
  59489. #endif
  59490. return EXPECT_RESULT();
  59491. }
  59492. static int test_wolfSSL_SHA224(void)
  59493. {
  59494. EXPECT_DECLS;
  59495. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  59496. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59497. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59498. unsigned char input[] =
  59499. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59500. unsigned char output[] =
  59501. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  59502. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  59503. size_t inLen;
  59504. byte hash[WC_SHA224_DIGEST_SIZE];
  59505. unsigned char* p = NULL;
  59506. inLen = XSTRLEN((char*)input);
  59507. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  59508. ExpectNull(SHA224(NULL, inLen, hash));
  59509. ExpectNotNull(SHA224(input, 0, hash));
  59510. ExpectNotNull(SHA224(input, inLen, NULL));
  59511. ExpectNotNull(SHA224(NULL, 0, hash));
  59512. ExpectNotNull(SHA224(NULL, 0, NULL));
  59513. ExpectNotNull(SHA224(input, inLen, hash));
  59514. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  59515. ExpectNotNull(p = SHA224(input, inLen, NULL));
  59516. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  59517. #endif
  59518. return EXPECT_RESULT();
  59519. }
  59520. static int test_wolfSSL_SHA256(void)
  59521. {
  59522. EXPECT_DECLS;
  59523. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  59524. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  59525. unsigned char input[] =
  59526. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59527. unsigned char output[] =
  59528. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  59529. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  59530. "\x06\xC1";
  59531. size_t inLen;
  59532. byte hash[WC_SHA256_DIGEST_SIZE];
  59533. inLen = XSTRLEN((char*)input);
  59534. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  59535. ExpectNotNull(SHA256(input, inLen, hash));
  59536. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  59537. #endif
  59538. return EXPECT_RESULT();
  59539. }
  59540. static int test_wolfSSL_SHA256_Transform(void)
  59541. {
  59542. EXPECT_DECLS;
  59543. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  59544. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59545. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59546. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  59547. !defined(WOLFSSL_KCAPI_HASH)
  59548. byte input1[] = "";
  59549. byte input2[] = "abc";
  59550. byte local[WC_SHA256_BLOCK_SIZE];
  59551. word32 sLen = 0;
  59552. #ifdef BIG_ENDIAN_ORDER
  59553. unsigned char output1[] =
  59554. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  59555. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  59556. unsigned char output2[] =
  59557. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  59558. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  59559. #else
  59560. unsigned char output1[] =
  59561. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  59562. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  59563. unsigned char output2[] =
  59564. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  59565. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  59566. #endif
  59567. union {
  59568. wc_Sha256 native;
  59569. SHA256_CTX compat;
  59570. } sha256;
  59571. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  59572. XMEMSET(&local, 0, sizeof(local));
  59573. /* sanity check */
  59574. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  59575. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  59576. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  59577. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59578. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59579. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59580. /* Init SHA256 CTX */
  59581. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59582. /* Do Transform*/
  59583. sLen = (word32)XSTRLEN((char*)input1);
  59584. XMEMCPY(local, input1, sLen);
  59585. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59586. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  59587. 0);
  59588. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59589. /* Init SHA256 CTX */
  59590. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59591. sLen = (word32)XSTRLEN((char*)input2);
  59592. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  59593. XMEMCPY(local, input2, sLen);
  59594. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59595. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  59596. 0);
  59597. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59598. #endif
  59599. #endif
  59600. return EXPECT_RESULT();
  59601. }
  59602. static int test_wolfSSL_SHA512_Transform(void)
  59603. {
  59604. EXPECT_DECLS;
  59605. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  59606. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59607. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59608. !defined(WOLFSSL_KCAPI_HASH)
  59609. byte input1[] = "";
  59610. byte input2[] = "abc";
  59611. byte local[WC_SHA512_BLOCK_SIZE];
  59612. word32 sLen = 0;
  59613. #ifdef BIG_ENDIAN_ORDER
  59614. unsigned char output1[] =
  59615. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  59616. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  59617. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  59618. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  59619. unsigned char output2[] =
  59620. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  59621. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  59622. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  59623. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  59624. #else
  59625. unsigned char output1[] =
  59626. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  59627. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  59628. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  59629. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  59630. unsigned char output2[] =
  59631. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  59632. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  59633. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  59634. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  59635. #endif
  59636. union {
  59637. wc_Sha512 native;
  59638. SHA512_CTX compat;
  59639. } sha512;
  59640. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59641. XMEMSET(&local, 0, sizeof(local));
  59642. /* sanity check */
  59643. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  59644. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  59645. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  59646. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59647. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59648. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59649. /* Init SHA512 CTX */
  59650. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  59651. /* Do Transform*/
  59652. sLen = (word32)XSTRLEN((char*)input1);
  59653. XMEMCPY(local, input1, sLen);
  59654. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59655. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59656. WC_SHA512_DIGEST_SIZE), 0);
  59657. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59658. /* Init SHA512 CTX */
  59659. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  59660. sLen = (word32)XSTRLEN((char*)input2);
  59661. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59662. XMEMCPY(local, input2, sLen);
  59663. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59664. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59665. WC_SHA512_DIGEST_SIZE), 0);
  59666. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59667. (void)input1;
  59668. #endif
  59669. #endif
  59670. return EXPECT_RESULT();
  59671. }
  59672. static int test_wolfSSL_SHA512_224_Transform(void)
  59673. {
  59674. EXPECT_DECLS;
  59675. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59676. !defined(WOLFSSL_NOSHA512_224)
  59677. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59678. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59679. !defined(WOLFSSL_KCAPI_HASH)
  59680. byte input1[] = "";
  59681. byte input2[] = "abc";
  59682. byte local[WC_SHA512_BLOCK_SIZE];
  59683. word32 sLen = 0;
  59684. unsigned char output1[] =
  59685. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  59686. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  59687. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  59688. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  59689. unsigned char output2[] =
  59690. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  59691. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  59692. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  59693. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  59694. union {
  59695. wc_Sha512 native;
  59696. SHA512_CTX compat;
  59697. } sha512;
  59698. #ifdef BIG_ENDIAN_ORDER
  59699. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59700. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59701. #endif
  59702. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59703. XMEMSET(&local, 0, sizeof(local));
  59704. /* sanity check */
  59705. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  59706. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  59707. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  59708. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59709. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  59710. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59711. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59712. /* Init SHA512 CTX */
  59713. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  59714. /* Do Transform*/
  59715. sLen = (word32)XSTRLEN((char*)input1);
  59716. XMEMCPY(local, input1, sLen);
  59717. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59718. 1);
  59719. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59720. WC_SHA512_DIGEST_SIZE), 0);
  59721. /* frees resources */
  59722. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59723. /* Init SHA512 CTX */
  59724. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  59725. sLen = (word32)XSTRLEN((char*)input2);
  59726. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59727. XMEMCPY(local, input2, sLen);
  59728. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59729. 1);
  59730. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59731. WC_SHA512_DIGEST_SIZE), 0);
  59732. /* frees resources */
  59733. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59734. #endif
  59735. #endif
  59736. return EXPECT_RESULT();
  59737. }
  59738. static int test_wolfSSL_SHA512_256_Transform(void)
  59739. {
  59740. EXPECT_DECLS;
  59741. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59742. !defined(WOLFSSL_NOSHA512_256)
  59743. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59744. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59745. !defined(WOLFSSL_KCAPI_HASH)
  59746. byte input1[] = "";
  59747. byte input2[] = "abc";
  59748. byte local[WC_SHA512_BLOCK_SIZE];
  59749. word32 sLen = 0;
  59750. unsigned char output1[] =
  59751. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  59752. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  59753. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  59754. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  59755. unsigned char output2[] =
  59756. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  59757. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  59758. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  59759. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  59760. union {
  59761. wc_Sha512 native;
  59762. SHA512_CTX compat;
  59763. } sha512;
  59764. #ifdef BIG_ENDIAN_ORDER
  59765. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59766. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59767. #endif
  59768. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59769. XMEMSET(&local, 0, sizeof(local));
  59770. /* sanity check */
  59771. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  59772. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  59773. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  59774. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59775. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  59776. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59777. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59778. /* Init SHA512 CTX */
  59779. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  59780. /* Do Transform*/
  59781. sLen = (word32)XSTRLEN((char*)input1);
  59782. XMEMCPY(local, input1, sLen);
  59783. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59784. 1);
  59785. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59786. WC_SHA512_DIGEST_SIZE), 0);
  59787. /* frees resources */
  59788. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59789. /* Init SHA512 CTX */
  59790. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  59791. sLen = (word32)XSTRLEN((char*)input2);
  59792. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59793. XMEMCPY(local, input2, sLen);
  59794. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59795. 1);
  59796. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59797. WC_SHA512_DIGEST_SIZE), 0);
  59798. /* frees resources */
  59799. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59800. #endif
  59801. #endif
  59802. return EXPECT_RESULT();
  59803. }
  59804. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59805. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  59806. * buffer of 64 bytes.
  59807. *
  59808. * returns the size of the digest buffer on success and a negative value on
  59809. * failure.
  59810. */
  59811. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  59812. int* sz)
  59813. {
  59814. EXPECT_DECLS;
  59815. HMAC_CTX ctx1;
  59816. HMAC_CTX ctx2;
  59817. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  59818. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  59819. unsigned char long_key[] =
  59820. "0123456789012345678901234567890123456789"
  59821. "0123456789012345678901234567890123456789"
  59822. "0123456789012345678901234567890123456789"
  59823. "0123456789012345678901234567890123456789";
  59824. unsigned char msg[] = "message to hash";
  59825. unsigned int digestSz = 64;
  59826. int keySz = sizeof(key);
  59827. int long_keySz = sizeof(long_key);
  59828. int msgSz = sizeof(msg);
  59829. unsigned char digest2[64];
  59830. unsigned int digestSz2 = 64;
  59831. HMAC_CTX_init(&ctx1);
  59832. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59833. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59834. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59835. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59836. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59837. HMAC_CTX_cleanup(&ctx1);
  59838. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59839. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  59840. HMAC_CTX_cleanup(&ctx2);
  59841. ExpectIntEQ(digestSz, digestSz2);
  59842. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59843. /* test HMAC_Init with NULL key */
  59844. /* init after copy */
  59845. HMAC_CTX_init(&ctx1);
  59846. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59847. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59848. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59849. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59850. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59851. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59852. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59853. HMAC_CTX_cleanup(&ctx1);
  59854. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59855. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59856. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59857. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59858. HMAC_CTX_cleanup(&ctx2);
  59859. ExpectIntEQ(digestSz, digestSz2);
  59860. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59861. /* long key */
  59862. HMAC_CTX_init(&ctx1);
  59863. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  59864. SSL_SUCCESS);
  59865. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59866. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59867. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59868. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59869. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59870. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59871. HMAC_CTX_cleanup(&ctx1);
  59872. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59873. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59874. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59875. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59876. HMAC_CTX_cleanup(&ctx2);
  59877. ExpectIntEQ(digestSz, digestSz2);
  59878. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59879. /* init before copy */
  59880. HMAC_CTX_init(&ctx1);
  59881. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59882. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59883. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59884. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59885. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59886. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59887. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59888. HMAC_CTX_cleanup(&ctx1);
  59889. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59890. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59891. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59892. HMAC_CTX_cleanup(&ctx2);
  59893. ExpectIntEQ(digestSz, digestSz2);
  59894. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59895. *sz = (int)digestSz;
  59896. return EXPECT_RESULT();
  59897. }
  59898. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  59899. static int test_wolfSSL_HMAC_CTX(void)
  59900. {
  59901. EXPECT_DECLS;
  59902. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59903. unsigned char digest[64];
  59904. int digestSz;
  59905. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  59906. WOLFSSL_HMAC_CTX ctx1;
  59907. WOLFSSL_HMAC_CTX ctx2;
  59908. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  59909. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  59910. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  59911. wolfSSL_HMAC_CTX_free(NULL);
  59912. wolfSSL_HMAC_CTX_free(hmac_ctx);
  59913. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  59914. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  59915. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  59916. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  59917. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  59918. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  59919. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59920. ((! defined(HAVE_FIPS_VERSION)) || \
  59921. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59922. /* Copy object that hasn't had a digest set - MD5. */
  59923. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  59924. #else
  59925. /* Copy object that hasn't had a digest set. */
  59926. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  59927. #endif
  59928. HMAC_CTX_cleanup(NULL);
  59929. HMAC_CTX_cleanup(&ctx2);
  59930. ExpectNull(HMAC_CTX_get_md(NULL));
  59931. #ifndef NO_SHA
  59932. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  59933. TEST_SUCCESS);
  59934. ExpectIntEQ(digestSz, 20);
  59935. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  59936. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  59937. #endif /* !NO_SHA */
  59938. #ifdef WOLFSSL_SHA224
  59939. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  59940. TEST_SUCCESS);
  59941. ExpectIntEQ(digestSz, 28);
  59942. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  59943. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  59944. "\x02\x0E", digest, digestSz), 0);
  59945. #endif /* WOLFSSL_SHA224 */
  59946. #ifndef NO_SHA256
  59947. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  59948. TEST_SUCCESS);
  59949. ExpectIntEQ(digestSz, 32);
  59950. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  59951. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  59952. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  59953. #endif /* !NO_SHA256 */
  59954. #ifdef WOLFSSL_SHA384
  59955. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  59956. TEST_SUCCESS);
  59957. ExpectIntEQ(digestSz, 48);
  59958. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  59959. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  59960. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  59961. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  59962. digest, digestSz), 0);
  59963. #endif /* WOLFSSL_SHA384 */
  59964. #ifdef WOLFSSL_SHA512
  59965. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  59966. TEST_SUCCESS);
  59967. ExpectIntEQ(digestSz, 64);
  59968. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  59969. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  59970. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  59971. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  59972. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  59973. digest, digestSz), 0);
  59974. #endif /* WOLFSSL_SHA512 */
  59975. #ifdef WOLFSSL_SHA3
  59976. #ifndef WOLFSSL_NOSHA3_224
  59977. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  59978. TEST_SUCCESS);
  59979. ExpectIntEQ(digestSz, 28);
  59980. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  59981. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  59982. "\x29\x0f", digest, digestSz), 0);
  59983. #endif
  59984. #ifndef WOLFSSL_NOSHA3_256
  59985. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  59986. TEST_SUCCESS);
  59987. ExpectIntEQ(digestSz, 32);
  59988. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  59989. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  59990. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  59991. #endif
  59992. #ifndef WOLFSSL_NOSHA3_384
  59993. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  59994. TEST_SUCCESS);
  59995. ExpectIntEQ(digestSz, 48);
  59996. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  59997. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  59998. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  59999. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  60000. digest, digestSz), 0);
  60001. #endif
  60002. #ifndef WOLFSSL_NOSHA3_512
  60003. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  60004. TEST_SUCCESS);
  60005. ExpectIntEQ(digestSz, 64);
  60006. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  60007. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  60008. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  60009. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  60010. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  60011. digest, digestSz), 0);
  60012. #endif
  60013. #endif
  60014. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  60015. HAVE_FIPS_VERSION <= 2)
  60016. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  60017. TEST_SUCCESS);
  60018. ExpectIntEQ(digestSz, 16);
  60019. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  60020. "\xE4\x98\xDD", digest, digestSz), 0);
  60021. #endif /* !NO_MD5 */
  60022. #endif
  60023. return EXPECT_RESULT();
  60024. }
  60025. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60026. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60027. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60028. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  60029. {
  60030. EXPECT_DECLS;
  60031. static const unsigned char key[] = "simple test key";
  60032. HMAC_CTX* hmac = NULL;
  60033. ENGINE* e = NULL;
  60034. unsigned char hash[WC_MAX_DIGEST_SIZE];
  60035. unsigned int len;
  60036. ExpectNotNull(hmac = HMAC_CTX_new());
  60037. HMAC_CTX_init(hmac);
  60038. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  60039. ((! defined(HAVE_FIPS_VERSION)) || \
  60040. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  60041. /* Get size on object that hasn't had a digest set - MD5. */
  60042. ExpectIntEQ(HMAC_size(hmac), 16);
  60043. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  60044. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  60045. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  60046. #else
  60047. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60048. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  60049. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  60050. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  60051. #endif
  60052. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  60053. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  60054. /* re-using test key as data to hash */
  60055. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  60056. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  60057. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  60058. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  60059. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  60060. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  60061. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  60062. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  60063. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  60064. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  60065. ExpectIntEQ(len, md_len);
  60066. ExpectIntEQ(HMAC_size(NULL), 0);
  60067. ExpectIntEQ(HMAC_size(hmac), md_len);
  60068. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  60069. HMAC_cleanup(NULL);
  60070. HMAC_cleanup(hmac);
  60071. HMAC_CTX_free(hmac);
  60072. len = 0;
  60073. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  60074. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  60075. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  60076. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  60077. ExpectIntEQ(len, md_len);
  60078. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  60079. /* With data. */
  60080. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  60081. &len));
  60082. /* With NULL data. */
  60083. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  60084. &len));
  60085. /* With zero length data. */
  60086. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  60087. return EXPECT_RESULT();
  60088. }
  60089. #endif
  60090. static int test_wolfSSL_HMAC(void)
  60091. {
  60092. EXPECT_DECLS;
  60093. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60094. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60095. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60096. #ifndef NO_SHA256
  60097. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  60098. TEST_SUCCESS);
  60099. #endif
  60100. #ifdef WOLFSSL_SHA224
  60101. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  60102. TEST_SUCCESS);
  60103. #endif
  60104. #ifdef WOLFSSL_SHA384
  60105. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  60106. TEST_SUCCESS);
  60107. #endif
  60108. #ifdef WOLFSSL_SHA512
  60109. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  60110. TEST_SUCCESS);
  60111. #endif
  60112. #ifdef WOLFSSL_SHA3
  60113. #ifndef WOLFSSL_NOSHA3_224
  60114. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  60115. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  60116. #endif
  60117. #ifndef WOLFSSL_NOSHA3_256
  60118. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  60119. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  60120. #endif
  60121. #ifndef WOLFSSL_NOSHA3_384
  60122. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  60123. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  60124. #endif
  60125. #ifndef WOLFSSL_NOSHA3_512
  60126. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  60127. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  60128. #endif
  60129. #endif
  60130. #ifndef NO_SHA
  60131. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  60132. TEST_SUCCESS);
  60133. #endif
  60134. #endif
  60135. return EXPECT_RESULT();
  60136. }
  60137. static int test_wolfSSL_CMAC(void)
  60138. {
  60139. EXPECT_DECLS;
  60140. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  60141. defined(WOLFSSL_AES_DIRECT)
  60142. int i;
  60143. byte key[AES_256_KEY_SIZE];
  60144. CMAC_CTX* cmacCtx = NULL;
  60145. byte out[AES_BLOCK_SIZE];
  60146. size_t outLen = AES_BLOCK_SIZE;
  60147. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  60148. key[i] = i;
  60149. }
  60150. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60151. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  60152. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60153. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60154. NULL), 1);
  60155. /* re-using test key as data to hash */
  60156. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60157. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60158. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  60159. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  60160. /* No Update works. */
  60161. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60162. NULL), 1);
  60163. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60164. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60165. NULL), 1);
  60166. /* Test parameters with CMAC_Update. */
  60167. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  60168. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  60169. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  60170. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  60171. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  60172. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60173. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  60174. /* Test parameters with CMAC_Final. */
  60175. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  60176. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  60177. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  60178. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  60179. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  60180. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  60181. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60182. CMAC_CTX_free(cmacCtx);
  60183. /* Test parameters with CMAC Init. */
  60184. cmacCtx = NULL;
  60185. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60186. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60187. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  60188. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60189. NULL), 0);
  60190. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60191. NULL), 0);
  60192. /* give a key too small for the cipher, verify we get failure */
  60193. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  60194. NULL), 0);
  60195. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  60196. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  60197. /* Only AES-CBC supported. */
  60198. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  60199. NULL), 0);
  60200. #endif
  60201. CMAC_CTX_free(cmacCtx);
  60202. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  60203. cmacCtx = NULL;
  60204. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60205. /* No Init. */
  60206. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  60207. CMAC_CTX_free(cmacCtx);
  60208. /* Test AES-256-CBC */
  60209. cmacCtx = NULL;
  60210. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60211. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  60212. NULL), 1);
  60213. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60214. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60215. CMAC_CTX_free(cmacCtx);
  60216. /* Test AES-192-CBC */
  60217. cmacCtx = NULL;
  60218. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60219. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60220. NULL), 1);
  60221. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60222. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60223. CMAC_CTX_free(cmacCtx);
  60224. cmacCtx = NULL;
  60225. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60226. CMAC_CTX_free(cmacCtx);
  60227. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  60228. return EXPECT_RESULT();
  60229. }
  60230. static int test_wolfSSL_DES(void)
  60231. {
  60232. EXPECT_DECLS;
  60233. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60234. const_DES_cblock myDes;
  60235. DES_cblock iv;
  60236. DES_key_schedule key;
  60237. word32 i = 0;
  60238. DES_LONG dl = 0;
  60239. unsigned char msg[] = "hello wolfssl";
  60240. unsigned char weakKey[][8] = {
  60241. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  60242. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  60243. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  60244. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  60245. };
  60246. unsigned char semiWeakKey[][8] = {
  60247. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  60248. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  60249. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  60250. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  60251. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  60252. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  60253. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  60254. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  60255. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  60256. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  60257. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  60258. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  60259. };
  60260. DES_check_key(1);
  60261. DES_set_key(&myDes, &key);
  60262. /* check, check of odd parity */
  60263. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  60264. myDes[0] = 6; /* set even parity */
  60265. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60266. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  60267. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60268. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  60269. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  60270. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  60271. /* set odd parity for success case */
  60272. DES_set_odd_parity(&myDes);
  60273. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  60274. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  60275. myDes[3]);
  60276. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60277. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60278. ExpectIntEQ(key[i], myDes[i]);
  60279. }
  60280. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60281. /* check weak key */
  60282. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  60283. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60284. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  60285. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60286. DES_set_key_unchecked(NULL, NULL);
  60287. DES_set_key_unchecked(&myDes, NULL);
  60288. DES_set_key_unchecked(NULL, &key);
  60289. /* compare arrays, should be the same */
  60290. /* now do unchecked copy of a weak key over */
  60291. DES_set_key_unchecked(&myDes, &key);
  60292. /* compare arrays, should be the same */
  60293. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60294. ExpectIntEQ(key[i], myDes[i]);
  60295. }
  60296. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  60297. myDes[7] = 2;
  60298. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60299. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60300. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  60301. /* Test all weak keys. */
  60302. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  60303. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  60304. }
  60305. /* Test all semi-weak keys. */
  60306. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  60307. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  60308. }
  60309. /* check DES_key_sched API */
  60310. XMEMSET(key, 1, sizeof(DES_key_schedule));
  60311. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  60312. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  60313. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  60314. /* compare arrays, should be the same */
  60315. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60316. ExpectIntEQ(key[i], myDes[i]);
  60317. }
  60318. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  60319. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  60320. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  60321. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  60322. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  60323. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  60324. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  60325. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  60326. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  60327. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  60328. * DES_cbc_encrypt on the input */
  60329. XMEMSET(iv, 0, sizeof(DES_cblock));
  60330. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  60331. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  60332. ExpectIntEQ(dl, 480052723);
  60333. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  60334. return EXPECT_RESULT();
  60335. }
  60336. static int test_wolfSSL_DES_ncbc(void)
  60337. {
  60338. EXPECT_DECLS;
  60339. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60340. const_DES_cblock myDes;
  60341. DES_cblock iv = {1};
  60342. DES_key_schedule key = {0};
  60343. unsigned char msg[] = "hello wolfssl";
  60344. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  60345. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  60346. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  60347. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  60348. /* partial block test */
  60349. DES_set_key(&key, &myDes);
  60350. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  60351. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  60352. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60353. DES_set_key(&key, &myDes);
  60354. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60355. *((byte*)&iv) = 1;
  60356. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  60357. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  60358. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60359. /* full block test */
  60360. DES_set_key(&key, &myDes);
  60361. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  60362. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60363. *((byte*)&iv) = 1;
  60364. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  60365. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  60366. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60367. DES_set_key(&key, &myDes);
  60368. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60369. *((byte*)&iv) = 1;
  60370. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  60371. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  60372. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60373. #endif
  60374. return EXPECT_RESULT();
  60375. }
  60376. static int test_wolfSSL_DES_ecb_encrypt(void)
  60377. {
  60378. EXPECT_DECLS;
  60379. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  60380. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  60381. WOLFSSL_DES_key_schedule key;
  60382. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60383. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  60384. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  60385. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  60386. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  60387. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  60388. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  60389. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  60390. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  60391. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  60392. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  60393. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  60394. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  60395. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  60396. /* Encrypt messages */
  60397. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  60398. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  60399. {
  60400. /* Decrypt messages */
  60401. int ret1 = 0;
  60402. int ret2 = 0;
  60403. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  60404. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  60405. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  60406. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  60407. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  60408. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  60409. }
  60410. #endif
  60411. return EXPECT_RESULT();
  60412. }
  60413. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  60414. {
  60415. EXPECT_DECLS;
  60416. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60417. unsigned char input1[8], input2[8];
  60418. unsigned char output1[8], output2[8];
  60419. unsigned char back1[8], back2[8];
  60420. WOLFSSL_DES_cblock iv1, iv2;
  60421. WOLFSSL_DES_key_schedule key1, key2, key3;
  60422. int i;
  60423. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60424. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  60425. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  60426. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  60427. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  60428. XMEMSET(output1, 0, sizeof(output1));
  60429. XMEMSET(output2, 0, sizeof(output2));
  60430. XMEMSET(back1, 0, sizeof(back1));
  60431. XMEMSET(back2, 0, sizeof(back2));
  60432. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60433. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60434. /* Encrypt messages */
  60435. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  60436. DES_ENCRYPT);
  60437. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  60438. DES_ENCRYPT);
  60439. {
  60440. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60441. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60442. /* Decrypt messages */
  60443. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  60444. &iv1, DES_DECRYPT);
  60445. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  60446. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  60447. &iv2, DES_DECRYPT);
  60448. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  60449. }
  60450. for (i = 0; i < 8; i++) {
  60451. XMEMSET(output1, 0, sizeof(output1));
  60452. XMEMSET(output2, 0, sizeof(output2));
  60453. XMEMSET(back1, 0, sizeof(back1));
  60454. XMEMSET(back2, 0, sizeof(back2));
  60455. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60456. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60457. /* Encrypt partial messages */
  60458. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  60459. &iv1, DES_ENCRYPT);
  60460. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  60461. &iv2, DES_ENCRYPT);
  60462. {
  60463. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60464. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60465. /* Decrypt messages */
  60466. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  60467. &key3, &iv1, DES_DECRYPT);
  60468. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  60469. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  60470. &key3, &iv2, DES_DECRYPT);
  60471. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  60472. }
  60473. }
  60474. #endif
  60475. return EXPECT_RESULT();
  60476. }
  60477. static int test_wolfSSL_AES_encrypt(void)
  60478. {
  60479. EXPECT_DECLS;
  60480. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60481. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60482. AES_KEY enc;
  60483. AES_KEY dec;
  60484. const byte msg[] = {
  60485. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60486. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60487. };
  60488. const byte exp[] = {
  60489. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  60490. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  60491. };
  60492. const byte key[] = {
  60493. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60494. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60495. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60496. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60497. };
  60498. byte eout[sizeof(msg)];
  60499. byte dout[sizeof(msg)];
  60500. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  60501. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  60502. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  60503. wolfSSL_AES_encrypt(msg, NULL, NULL);
  60504. wolfSSL_AES_encrypt(NULL, eout, NULL);
  60505. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  60506. wolfSSL_AES_encrypt(msg, eout, NULL);
  60507. wolfSSL_AES_encrypt(msg, NULL, &enc);
  60508. wolfSSL_AES_encrypt(NULL, eout, &enc);
  60509. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  60510. wolfSSL_AES_decrypt(eout, NULL, NULL);
  60511. wolfSSL_AES_decrypt(NULL, dout, NULL);
  60512. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  60513. wolfSSL_AES_decrypt(eout, dout, NULL);
  60514. wolfSSL_AES_decrypt(eout, NULL, &dec);
  60515. wolfSSL_AES_decrypt(NULL, dout, &dec);
  60516. wolfSSL_AES_encrypt(msg, eout, &enc);
  60517. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  60518. wolfSSL_AES_decrypt(eout, dout, &dec);
  60519. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  60520. #endif
  60521. return EXPECT_RESULT();
  60522. }
  60523. static int test_wolfSSL_AES_ecb_encrypt(void)
  60524. {
  60525. EXPECT_DECLS;
  60526. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60527. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60528. AES_KEY aes;
  60529. const byte msg[] =
  60530. {
  60531. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60532. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  60533. };
  60534. const byte verify[] =
  60535. {
  60536. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  60537. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  60538. };
  60539. const byte key[] =
  60540. {
  60541. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60542. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60543. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60544. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  60545. };
  60546. byte out[AES_BLOCK_SIZE];
  60547. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  60548. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60549. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  60550. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  60551. #ifdef HAVE_AES_DECRYPT
  60552. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  60553. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60554. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  60555. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  60556. #endif
  60557. /* test bad arguments */
  60558. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  60559. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  60560. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  60561. #endif
  60562. return EXPECT_RESULT();
  60563. }
  60564. static int test_wolfSSL_AES_cbc_encrypt(void)
  60565. {
  60566. EXPECT_DECLS;
  60567. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60568. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60569. AES_KEY aes;
  60570. AES_KEY* aesN = NULL;
  60571. size_t len = 0;
  60572. size_t lenB = 0;
  60573. int keySz0 = 0;
  60574. int keySzN = -1;
  60575. byte out[AES_BLOCK_SIZE] = {0};
  60576. byte* outN = NULL;
  60577. /* Test vectors retrieved from:
  60578. * <begin URL>
  60579. * https://csrc.nist.gov/
  60580. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  60581. * documents/aes/KAT_AES.zip
  60582. * </end URL>
  60583. */
  60584. const byte* pt128N = NULL;
  60585. byte* key128N = NULL;
  60586. byte* iv128N = NULL;
  60587. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  60588. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60590. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  60591. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  60592. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60593. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60594. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  60595. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  60596. len = sizeof(pt128);
  60597. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  60598. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  60599. ExpectIntNE(XMEMCMP(b, g, h), i)
  60600. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  60601. /* Stressing wolfSSL_AES_cbc_encrypt() */
  60602. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60603. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  60604. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  60605. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60606. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  60607. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60608. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60609. /* Stressing wolfSSL_AES_set_encrypt_key */
  60610. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60611. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  60612. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  60613. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  60614. /* Stressing wolfSSL_AES_set_decrypt_key */
  60615. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60616. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  60617. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  60618. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  60619. #ifdef WOLFSSL_AES_128
  60620. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  60621. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60622. RESET_IV(iv128tmp, iv128);
  60623. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60624. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  60625. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60626. wc_AesFree((Aes*)&aes);
  60627. #ifdef HAVE_AES_DECRYPT
  60628. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  60629. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60630. RESET_IV(iv128tmp, iv128);
  60631. len = sizeof(ct128);
  60632. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60633. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  60634. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  60635. wc_AesFree((Aes*)&aes);
  60636. #endif
  60637. #endif /* WOLFSSL_AES_128 */
  60638. #ifdef WOLFSSL_AES_192
  60639. {
  60640. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  60641. * Appendix F.2.3 */
  60642. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  60643. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60644. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60645. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  60646. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  60647. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60648. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60649. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  60650. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  60651. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  60652. len = sizeof(pt192);
  60653. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  60654. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60655. RESET_IV(iv192tmp, iv192);
  60656. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60657. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  60658. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  60659. wc_AesFree((Aes*)&aes);
  60660. #ifdef HAVE_AES_DECRYPT
  60661. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  60662. len = sizeof(ct192);
  60663. RESET_IV(iv192tmp, iv192);
  60664. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60665. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60666. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  60667. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  60668. wc_AesFree((Aes*)&aes);
  60669. #endif
  60670. }
  60671. #endif /* WOLFSSL_AES_192 */
  60672. #ifdef WOLFSSL_AES_256
  60673. {
  60674. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  60675. * Appendix F.2.5 */
  60676. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  60677. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60678. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60679. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  60680. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  60681. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60682. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60683. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60684. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60685. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60686. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  60687. len = sizeof(pt256);
  60688. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  60689. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60690. RESET_IV(iv256tmp, iv256);
  60691. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60692. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  60693. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  60694. wc_AesFree((Aes*)&aes);
  60695. #ifdef HAVE_AES_DECRYPT
  60696. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  60697. len = sizeof(ct256);
  60698. RESET_IV(iv256tmp, iv256);
  60699. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60700. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60701. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  60702. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  60703. wc_AesFree((Aes*)&aes);
  60704. #endif
  60705. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  60706. !defined(HAVE_SELFTEST)
  60707. {
  60708. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  60709. byte wrapPlain[sizeof(key256)] = { 0 };
  60710. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  60711. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  60712. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60713. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60714. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60715. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60716. sizeof(key256)), sizeof(wrapCipher));
  60717. wc_AesFree((Aes*)&aes);
  60718. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  60719. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60720. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60721. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60722. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60723. sizeof(wrapCipher)), sizeof(wrapPlain));
  60724. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60725. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  60726. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  60727. wc_AesFree((Aes*)&aes);
  60728. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  60729. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60730. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  60731. sizeof(key256)), sizeof(wrapCipher));
  60732. wc_AesFree((Aes*)&aes);
  60733. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  60734. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60735. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  60736. sizeof(wrapCipher)), sizeof(wrapPlain));
  60737. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60738. wc_AesFree((Aes*)&aes);
  60739. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60740. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60741. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60742. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  60743. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  60744. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  60745. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  60746. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  60747. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  60748. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60749. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60750. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60751. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  60752. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  60753. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  60754. 0);
  60755. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  60756. 0);
  60757. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  60758. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  60759. }
  60760. #endif /* HAVE_AES_KEYWRAP */
  60761. }
  60762. #endif /* WOLFSSL_AES_256 */
  60763. #endif
  60764. return EXPECT_RESULT();
  60765. }
  60766. static int test_wolfSSL_AES_cfb128_encrypt(void)
  60767. {
  60768. EXPECT_DECLS;
  60769. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  60770. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60771. AES_KEY aesEnc;
  60772. AES_KEY aesDec;
  60773. const byte msg[] = {
  60774. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60775. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60776. };
  60777. const byte exp[] = {
  60778. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  60779. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  60780. };
  60781. const byte key[] = {
  60782. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60783. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60784. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60785. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60786. };
  60787. const byte ivData[] = {
  60788. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60789. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60790. };
  60791. byte out[AES_BLOCK_SIZE];
  60792. byte iv[AES_BLOCK_SIZE];
  60793. word32 i;
  60794. int num;
  60795. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60796. XMEMCPY(iv, ivData, sizeof(iv));
  60797. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60798. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  60799. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  60800. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60801. #ifdef HAVE_AES_DECRYPT
  60802. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60803. XMEMCPY(iv, ivData, sizeof(iv));
  60804. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60805. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  60806. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  60807. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60808. #endif
  60809. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  60810. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60811. XMEMCPY(iv, ivData, sizeof(iv));
  60812. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60813. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  60814. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60815. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  60816. if (i == 0) {
  60817. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60818. }
  60819. else {
  60820. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60821. }
  60822. #ifdef HAVE_AES_DECRYPT
  60823. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60824. XMEMCPY(iv, ivData, sizeof(iv));
  60825. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60826. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  60827. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60828. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  60829. if (i == 0) {
  60830. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60831. }
  60832. else {
  60833. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60834. }
  60835. #endif
  60836. }
  60837. if (EXPECT_SUCCESS()) {
  60838. /* test bad arguments */
  60839. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60840. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60841. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  60842. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60843. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  60844. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60845. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60846. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  60847. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60848. }
  60849. #endif
  60850. return EXPECT_RESULT();
  60851. }
  60852. static int test_wolfSSL_CRYPTO_cts128(void)
  60853. {
  60854. EXPECT_DECLS;
  60855. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60856. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60857. byte tmp[64]; /* Largest vector size */
  60858. /* Test vectors taken form RFC3962 Appendix B */
  60859. const testVector vects[] = {
  60860. {
  60861. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60862. "\x20",
  60863. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  60864. "\x97",
  60865. 17, 17
  60866. },
  60867. {
  60868. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60869. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  60870. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  60871. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  60872. 31, 31
  60873. },
  60874. {
  60875. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60876. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  60877. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60878. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  60879. 32, 32
  60880. },
  60881. {
  60882. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60883. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60884. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  60885. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60886. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  60887. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  60888. 47, 47
  60889. },
  60890. {
  60891. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60892. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60893. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  60894. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60895. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  60896. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  60897. 48, 48
  60898. },
  60899. {
  60900. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60901. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60902. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  60903. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  60904. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60905. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60906. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  60907. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  60908. 64, 64
  60909. }
  60910. };
  60911. byte keyBytes[AES_128_KEY_SIZE] = {
  60912. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  60913. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  60914. };
  60915. size_t i;
  60916. AES_KEY encKey;
  60917. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  60918. XMEMSET(tmp, 0, sizeof(tmp));
  60919. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  60920. AES_KEY decKey;
  60921. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60922. &encKey), 0);
  60923. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60924. &decKey), 0);
  60925. XMEMSET(iv, 0, sizeof(iv));
  60926. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  60927. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  60928. vects[i].outLen);
  60929. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  60930. XMEMSET(iv, 0, sizeof(iv));
  60931. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  60932. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  60933. vects[i].inLen);
  60934. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  60935. }
  60936. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60937. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60938. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60939. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60940. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60941. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  60942. (cbc128_f)AES_cbc_encrypt), 0);
  60943. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  60944. (cbc128_f)AES_cbc_encrypt), 0);
  60945. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  60946. (cbc128_f)AES_cbc_encrypt), 0);
  60947. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  60948. (cbc128_f)AES_cbc_encrypt), 0);
  60949. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  60950. (cbc128_f)AES_cbc_encrypt), 0);
  60951. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60952. /* Length too small. */
  60953. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  60954. (cbc128_f)AES_cbc_encrypt), 0);
  60955. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60956. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60957. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60958. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60959. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60960. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  60961. (cbc128_f)AES_cbc_encrypt), 0);
  60962. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  60963. (cbc128_f)AES_cbc_encrypt), 0);
  60964. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  60965. (cbc128_f)AES_cbc_encrypt), 0);
  60966. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  60967. (cbc128_f)AES_cbc_encrypt), 0);
  60968. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  60969. (cbc128_f)AES_cbc_encrypt), 0);
  60970. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60971. /* Length too small. */
  60972. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  60973. (cbc128_f)AES_cbc_encrypt), 0);
  60974. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  60975. return EXPECT_RESULT();
  60976. }
  60977. static int test_wolfSSL_RC4(void)
  60978. {
  60979. EXPECT_DECLS;
  60980. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  60981. WOLFSSL_RC4_KEY rc4Key;
  60982. unsigned char key[] = {
  60983. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60984. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60985. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60986. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60987. };
  60988. unsigned char data[] = {
  60989. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60990. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60991. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60992. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60993. };
  60994. unsigned char enc[sizeof(data)];
  60995. unsigned char dec[sizeof(data)];
  60996. word32 i;
  60997. word32 j;
  60998. wolfSSL_RC4_set_key(NULL, -1, NULL);
  60999. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  61000. wolfSSL_RC4_set_key(NULL, 0, NULL);
  61001. wolfSSL_RC4_set_key(NULL, -1, key);
  61002. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  61003. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  61004. wolfSSL_RC4_set_key(NULL, 0, key);
  61005. wolfSSL_RC4(NULL, 0, NULL, NULL);
  61006. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  61007. wolfSSL_RC4(NULL, 0, data, NULL);
  61008. wolfSSL_RC4(NULL, 0, NULL, enc);
  61009. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  61010. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  61011. wolfSSL_RC4(NULL, 0, data, enc);
  61012. ExpectIntEQ(1, 1);
  61013. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  61014. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  61015. XMEMSET(enc, 0, sizeof(enc));
  61016. XMEMSET(dec, 0, sizeof(dec));
  61017. /* Encrypt */
  61018. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61019. wolfSSL_RC4(&rc4Key, j, data, enc);
  61020. /* Decrypt */
  61021. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61022. wolfSSL_RC4(&rc4Key, j, enc, dec);
  61023. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  61024. }
  61025. }
  61026. #endif
  61027. return EXPECT_RESULT();
  61028. }
  61029. static int test_wolfSSL_OBJ(void)
  61030. {
  61031. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  61032. * mode
  61033. */
  61034. EXPECT_DECLS;
  61035. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  61036. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  61037. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  61038. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  61039. ASN1_OBJECT *obj = NULL;
  61040. ASN1_OBJECT *obj2 = NULL;
  61041. char buf[50];
  61042. XFILE fp = XBADFILE;
  61043. X509 *x509 = NULL;
  61044. X509_NAME *x509Name = NULL;
  61045. X509_NAME_ENTRY *x509NameEntry = NULL;
  61046. ASN1_OBJECT *asn1Name = NULL;
  61047. int numNames = 0;
  61048. BIO *bio = NULL;
  61049. int nid;
  61050. int i, j;
  61051. const char *f[] = {
  61052. #ifndef NO_RSA
  61053. "./certs/ca-cert.der",
  61054. #endif
  61055. #ifdef HAVE_ECC
  61056. "./certs/ca-ecc-cert.der",
  61057. "./certs/ca-ecc384-cert.der",
  61058. #endif
  61059. NULL};
  61060. ASN1_OBJECT *field_name_obj = NULL;
  61061. int lastpos = -1;
  61062. int tmp = -1;
  61063. ASN1_STRING *asn1 = NULL;
  61064. unsigned char *buf_dyn = NULL;
  61065. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61066. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61067. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  61068. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  61069. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61070. ASN1_OBJECT_free(obj);
  61071. obj = NULL;
  61072. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  61073. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  61074. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  61075. #ifdef WOLFSSL_CERT_EXT
  61076. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  61077. #endif
  61078. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61079. ExpectNotNull(obj2 = OBJ_dup(obj));
  61080. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  61081. ASN1_OBJECT_free(obj);
  61082. obj = NULL;
  61083. ASN1_OBJECT_free(obj2);
  61084. obj2 = NULL;
  61085. for (i = 0; f[i] != NULL; i++)
  61086. {
  61087. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  61088. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  61089. if (fp != XBADFILE) {
  61090. XFCLOSE(fp);
  61091. fp = XBADFILE;
  61092. }
  61093. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  61094. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61095. /* Get the Common Name by using OBJ_txt2obj */
  61096. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  61097. do
  61098. {
  61099. lastpos = tmp;
  61100. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  61101. } while (tmp > -1);
  61102. ExpectIntNE(lastpos, -1);
  61103. ASN1_OBJECT_free(field_name_obj);
  61104. field_name_obj = NULL;
  61105. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  61106. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  61107. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  61108. /*
  61109. * All Common Names should be www.wolfssl.com
  61110. * This makes testing easier as we can test for the expected value.
  61111. */
  61112. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  61113. OPENSSL_free(buf_dyn);
  61114. buf_dyn = NULL;
  61115. bio = BIO_new(BIO_s_mem());
  61116. ExpectTrue(bio != NULL);
  61117. for (j = 0; j < numNames; j++)
  61118. {
  61119. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61120. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  61121. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61122. }
  61123. BIO_free(bio);
  61124. bio = NULL;
  61125. X509_free(x509);
  61126. x509 = NULL;
  61127. }
  61128. #ifdef HAVE_PKCS12
  61129. {
  61130. PKCS12 *p12 = NULL;
  61131. int boolRet;
  61132. EVP_PKEY *pkey = NULL;
  61133. const char *p12_f[] = {
  61134. #if !defined(NO_DES3) && !defined(NO_RSA)
  61135. "./certs/test-servercert.p12",
  61136. #endif
  61137. NULL};
  61138. for (i = 0; p12_f[i] != NULL; i++)
  61139. {
  61140. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  61141. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  61142. if (fp != XBADFILE) {
  61143. XFCLOSE(fp);
  61144. fp = XBADFILE;
  61145. }
  61146. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  61147. &pkey, &x509, NULL)) > 0);
  61148. wc_PKCS12_free(p12);
  61149. p12 = NULL;
  61150. EVP_PKEY_free(pkey);
  61151. x509Name = X509_get_issuer_name(x509);
  61152. ExpectNotNull(x509Name);
  61153. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61154. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  61155. for (j = 0; j < numNames; j++)
  61156. {
  61157. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61158. ExpectNotNull(asn1Name =
  61159. X509_NAME_ENTRY_get_object(x509NameEntry));
  61160. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61161. }
  61162. BIO_free(bio);
  61163. bio = NULL;
  61164. X509_free(x509);
  61165. x509 = NULL;
  61166. }
  61167. }
  61168. #endif /* HAVE_PKCS12 */
  61169. #endif
  61170. return EXPECT_RESULT();
  61171. }
  61172. static int test_wolfSSL_OBJ_cmp(void)
  61173. {
  61174. EXPECT_DECLS;
  61175. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  61176. ASN1_OBJECT *obj = NULL;
  61177. ASN1_OBJECT *obj2 = NULL;
  61178. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61179. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  61180. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61181. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61182. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61183. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61184. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  61185. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  61186. ASN1_OBJECT_free(obj);
  61187. ASN1_OBJECT_free(obj2);
  61188. #endif
  61189. return EXPECT_RESULT();
  61190. }
  61191. static int test_wolfSSL_OBJ_txt2nid(void)
  61192. {
  61193. EXPECT_DECLS;
  61194. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  61195. defined(WOLFSSL_APACHE_HTTPD)
  61196. int i;
  61197. static const struct {
  61198. const char* sn;
  61199. const char* ln;
  61200. const char* oid;
  61201. int nid;
  61202. } testVals[] = {
  61203. #ifdef WOLFSSL_APACHE_HTTPD
  61204. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  61205. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  61206. NID_id_on_dnsSRV },
  61207. { "msUPN", "Microsoft User Principal Name",
  61208. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  61209. #endif
  61210. { NULL, NULL, NULL, NID_undef }
  61211. };
  61212. /* Invalid cases */
  61213. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  61214. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  61215. /* Valid cases */
  61216. for (i = 0; testVals[i].sn != NULL; i++) {
  61217. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  61218. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  61219. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  61220. }
  61221. #endif
  61222. return EXPECT_RESULT();
  61223. }
  61224. static int test_wolfSSL_OBJ_txt2obj(void)
  61225. {
  61226. EXPECT_DECLS;
  61227. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  61228. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  61229. int i;
  61230. char buf[50];
  61231. ASN1_OBJECT* obj = NULL;
  61232. static const struct {
  61233. const char* oidStr;
  61234. const char* sn;
  61235. const char* ln;
  61236. } objs_list[] = {
  61237. #if defined(WOLFSSL_APACHE_HTTPD)
  61238. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  61239. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  61240. #endif
  61241. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  61242. { NULL, NULL, NULL }
  61243. };
  61244. static const struct {
  61245. const char* numeric;
  61246. const char* name;
  61247. } objs_named[] = {
  61248. /* In dictionary but not in normal list. */
  61249. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  61250. /* Made up OID. */
  61251. { "1.3.5.7", "1.3.5.7" },
  61252. { NULL, NULL }
  61253. };
  61254. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  61255. ASN1_OBJECT_free(obj);
  61256. obj = NULL;
  61257. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  61258. ASN1_OBJECT_free(obj);
  61259. obj = NULL;
  61260. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  61261. /* Test numerical value of oid (oidStr) */
  61262. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  61263. /* Convert object back to text to confirm oid is correct */
  61264. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61265. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61266. ASN1_OBJECT_free(obj);
  61267. obj = NULL;
  61268. XMEMSET(buf, 0, sizeof(buf));
  61269. /* Test short name (sn) */
  61270. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  61271. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  61272. /* Convert object back to text to confirm oid is correct */
  61273. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61274. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61275. ASN1_OBJECT_free(obj);
  61276. obj = NULL;
  61277. XMEMSET(buf, 0, sizeof(buf));
  61278. /* Test long name (ln) - should fail when no_name = 1 */
  61279. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  61280. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  61281. /* Convert object back to text to confirm oid is correct */
  61282. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61283. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61284. ASN1_OBJECT_free(obj);
  61285. obj = NULL;
  61286. XMEMSET(buf, 0, sizeof(buf));
  61287. }
  61288. for (i = 0; objs_named[i].numeric != NULL; i++) {
  61289. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  61290. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  61291. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  61292. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61293. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  61294. ASN1_OBJECT_free(obj);
  61295. obj = NULL;
  61296. }
  61297. #endif
  61298. return EXPECT_RESULT();
  61299. }
  61300. static int test_wolfSSL_PEM_write_bio_X509(void)
  61301. {
  61302. EXPECT_DECLS;
  61303. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  61304. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  61305. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  61306. !defined(NO_FILESYSTEM)
  61307. /* This test contains the hard coded expected
  61308. * lengths. Update if necessary */
  61309. XFILE fp = XBADFILE;
  61310. WOLFSSL_EVP_PKEY *priv = NULL;
  61311. BIO* input = NULL;
  61312. BIO* output = NULL;
  61313. X509* x509a = NULL;
  61314. X509* x509b = NULL;
  61315. ASN1_TIME* notBeforeA = NULL;
  61316. ASN1_TIME* notAfterA = NULL;
  61317. #ifndef NO_ASN_TIME
  61318. ASN1_TIME* notBeforeB = NULL;
  61319. ASN1_TIME* notAfterB = NULL;
  61320. #endif
  61321. int expectedLen;
  61322. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  61323. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  61324. if (fp != XBADFILE) {
  61325. XFCLOSE(fp);
  61326. fp = XBADFILE;
  61327. }
  61328. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  61329. "rb"));
  61330. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  61331. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  61332. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61333. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  61334. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  61335. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  61336. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61337. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61338. /* compare length against expected */
  61339. expectedLen = 2000;
  61340. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61341. #ifndef NO_ASN_TIME
  61342. /* read exported X509 PEM back into struct, sanity check on export,
  61343. * make sure notBefore/notAfter are the same and certs are identical. */
  61344. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61345. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  61346. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  61347. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  61348. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  61349. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61350. X509_free(x509b);
  61351. x509b = NULL;
  61352. #endif
  61353. /* Reset output buffer */
  61354. BIO_free(output);
  61355. output = NULL;
  61356. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61357. /* Test forcing the AKID to be generated just from KeyIdentifier */
  61358. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  61359. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  61360. x509a->authKeyId = x509a->authKeyIdSrc;
  61361. x509a->authKeyIdSrc = NULL;
  61362. x509a->authKeyIdSrcSz = 0;
  61363. }
  61364. /* Resign to re-generate the der */
  61365. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  61366. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61367. /* Check that we generate a smaller output since the AKID will
  61368. * only contain the KeyIdentifier without any additional
  61369. * information */
  61370. /* Here we copy the validity struct from the original */
  61371. expectedLen = 1688;
  61372. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61373. /* Reset buffers and x509 */
  61374. BIO_free(input);
  61375. input = NULL;
  61376. BIO_free(output);
  61377. output = NULL;
  61378. X509_free(x509a);
  61379. x509a = NULL;
  61380. /* test CA and basicConstSet values are encoded when
  61381. * the cert is a CA */
  61382. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  61383. /* read PEM into X509 struct */
  61384. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61385. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61386. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61387. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61388. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  61389. * values are maintained and certs are identical.*/
  61390. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61391. ExpectIntEQ(x509b->isCa, 1);
  61392. ExpectIntEQ(x509b->basicConstSet, 1);
  61393. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61394. X509_free(x509a);
  61395. x509a = NULL;
  61396. X509_free(x509b);
  61397. x509b = NULL;
  61398. BIO_free(input);
  61399. input = NULL;
  61400. BIO_free(output);
  61401. output = NULL;
  61402. /* test CA and basicConstSet values are encoded when
  61403. * the cert is not CA */
  61404. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  61405. /* read PEM into X509 struct */
  61406. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61407. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61408. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61409. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61410. /* read exported X509 PEM back into struct, ensure isCa and
  61411. * basicConstSet values are maintained and certs are identical */
  61412. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61413. ExpectIntEQ(x509b->isCa, 0);
  61414. ExpectIntEQ(x509b->basicConstSet, 1);
  61415. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61416. wolfSSL_EVP_PKEY_free(priv);
  61417. X509_free(x509a);
  61418. X509_free(x509b);
  61419. BIO_free(input);
  61420. BIO_free(output);
  61421. #endif
  61422. return EXPECT_RESULT();
  61423. }
  61424. static int test_wolfSSL_X509_NAME_ENTRY(void)
  61425. {
  61426. EXPECT_DECLS;
  61427. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  61428. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  61429. X509* x509 = NULL;
  61430. #ifndef NO_BIO
  61431. BIO* bio = NULL;
  61432. #endif
  61433. X509_NAME* nm = NULL;
  61434. X509_NAME_ENTRY* entry = NULL;
  61435. unsigned char cn[] = "another name to add";
  61436. #ifdef OPENSSL_ALL
  61437. int i;
  61438. int names_len = 0;
  61439. #endif
  61440. ExpectNotNull(x509 =
  61441. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61442. #ifndef NO_BIO
  61443. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61444. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  61445. #endif
  61446. #ifdef WOLFSSL_CERT_REQ
  61447. {
  61448. X509_REQ* req = NULL;
  61449. #ifndef NO_BIO
  61450. BIO* bReq = NULL;
  61451. #endif
  61452. ExpectNotNull(req =
  61453. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61454. #ifndef NO_BIO
  61455. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  61456. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  61457. BIO_free(bReq);
  61458. #endif
  61459. X509_free(req);
  61460. }
  61461. #endif
  61462. ExpectNotNull(nm = X509_get_subject_name(x509));
  61463. /* Test add entry */
  61464. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  61465. 0x0c, cn, (int)sizeof(cn)));
  61466. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61467. #ifdef WOLFSSL_CERT_EXT
  61468. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  61469. (byte*)"support@wolfssl.com", 19, -1,
  61470. 1), WOLFSSL_SUCCESS);
  61471. #endif
  61472. X509_NAME_ENTRY_free(entry);
  61473. entry = NULL;
  61474. #ifdef WOLFSSL_CERT_REQ
  61475. {
  61476. unsigned char srv_pkcs9p[] = "Server";
  61477. unsigned char fvrtDrnk[] = "tequila";
  61478. unsigned char* der = NULL;
  61479. char* subject = NULL;
  61480. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  61481. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  61482. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  61483. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  61484. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  61485. ExpectNotNull(der);
  61486. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  61487. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  61488. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  61489. #ifdef DEBUG_WOLFSSL
  61490. if (subject != NULL) {
  61491. fprintf(stderr, "\n\t%s\n", subject);
  61492. }
  61493. #endif
  61494. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  61495. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  61496. }
  61497. #endif
  61498. /* Test add entry by text */
  61499. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  61500. 0x0c, cn, (int)sizeof(cn)));
  61501. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  61502. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  61503. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  61504. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  61505. #endif
  61506. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61507. X509_NAME_ENTRY_free(entry);
  61508. entry = NULL;
  61509. /* Test add entry by NID */
  61510. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  61511. cn, -1, -1, 0), SSL_SUCCESS);
  61512. #ifdef OPENSSL_ALL
  61513. /* stack of name entry */
  61514. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  61515. for (i = 0; i < names_len; i++) {
  61516. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  61517. }
  61518. #endif
  61519. #ifndef NO_BIO
  61520. BIO_free(bio);
  61521. #endif
  61522. X509_free(x509); /* free's nm */
  61523. #endif
  61524. return EXPECT_RESULT();
  61525. }
  61526. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61527. static int test_GENERAL_NAME_set0_othername(void) {
  61528. EXPECT_DECLS;
  61529. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61530. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61531. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61532. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61533. defined(WOLFSSL_FPKI)
  61534. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61535. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61536. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61537. const char * cert_fname = "./certs/server-cert.der";
  61538. const char * key_fname = "./certs/server-key.der";
  61539. X509* x509 = NULL;
  61540. GENERAL_NAME* gn = NULL;
  61541. GENERAL_NAMES* gns = NULL;
  61542. ASN1_OBJECT* upn_oid = NULL;
  61543. ASN1_UTF8STRING *utf8str = NULL;
  61544. ASN1_TYPE *value = NULL;
  61545. X509_EXTENSION * ext = NULL;
  61546. byte* pt = NULL;
  61547. byte der[4096];
  61548. int derSz = 0;
  61549. EVP_PKEY* priv = NULL;
  61550. XFILE f = XBADFILE;
  61551. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  61552. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  61553. if (f != XBADFILE) {
  61554. XFCLOSE(f);
  61555. f = XBADFILE;
  61556. }
  61557. ExpectNotNull(gn = GENERAL_NAME_new());
  61558. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61559. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61560. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61561. ExpectNotNull(value = ASN1_TYPE_new());
  61562. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61563. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  61564. wolfSSL_ASN1_STRING_free(utf8str);
  61565. }
  61566. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61567. if (EXPECT_FAIL()) {
  61568. ASN1_TYPE_free(value);
  61569. }
  61570. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61571. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61572. if (EXPECT_FAIL()) {
  61573. GENERAL_NAME_free(gn);
  61574. gn = NULL;
  61575. }
  61576. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61577. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  61578. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61579. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61580. if (f != XBADFILE) {
  61581. XFCLOSE(f);
  61582. f = XBADFILE;
  61583. }
  61584. pt = der;
  61585. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61586. (const unsigned char**)&pt, derSz));
  61587. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  61588. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61589. gns = NULL;
  61590. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61591. NID_subject_alt_name, NULL, NULL));
  61592. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  61593. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  61594. ExpectIntEQ(gn->type, 0);
  61595. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61596. ASN1_OBJECT_free(upn_oid);
  61597. X509_EXTENSION_free(ext);
  61598. X509_free(x509);
  61599. EVP_PKEY_free(priv);
  61600. #endif
  61601. return EXPECT_RESULT();
  61602. }
  61603. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61604. static int test_othername_and_SID_ext(void) {
  61605. EXPECT_DECLS;
  61606. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61607. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61608. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61609. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61610. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  61611. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61612. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61613. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61614. const char* csr_fname = "./certs/csr.signed.der";
  61615. const char* key_fname = "./certs/server-key.der";
  61616. byte der[4096];
  61617. int derSz = 0;
  61618. X509_REQ* x509 = NULL;
  61619. STACK_OF(X509_EXTENSION) *exts = NULL;
  61620. X509_EXTENSION * san_ext = NULL;
  61621. X509_EXTENSION * ext = NULL;
  61622. GENERAL_NAME* gn = NULL;
  61623. GENERAL_NAMES* gns = NULL;
  61624. ASN1_OBJECT* upn_oid = NULL;
  61625. ASN1_UTF8STRING *utf8str = NULL;
  61626. ASN1_TYPE *value = NULL;
  61627. ASN1_STRING *extval = NULL;
  61628. /* SID extension. SID data format explained here:
  61629. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  61630. */
  61631. byte SidExtension[] = {
  61632. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  61633. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  61634. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  61635. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  61636. byte expectedAltName[] = {
  61637. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  61638. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  61639. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  61640. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  61641. X509_EXTENSION *sid_ext = NULL;
  61642. ASN1_OBJECT* sid_oid = NULL;
  61643. ASN1_OCTET_STRING *sid_data = NULL;
  61644. ASN1_OBJECT* alt_names_oid = NULL;
  61645. EVP_PKEY* priv = NULL;
  61646. XFILE f = XBADFILE;
  61647. byte* pt = NULL;
  61648. BIO* bio = NULL;
  61649. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  61650. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  61651. if (f != XBADFILE) {
  61652. XFCLOSE(f);
  61653. f = XBADFILE;
  61654. }
  61655. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  61656. ExpectNotNull(gn = GENERAL_NAME_new());
  61657. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61658. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61659. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61660. ExpectNotNull(value = ASN1_TYPE_new());
  61661. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61662. if (EXPECT_FAIL()) {
  61663. ASN1_UTF8STRING_free(utf8str);
  61664. }
  61665. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61666. if (EXPECT_FAIL()) {
  61667. ASN1_TYPE_free(value);
  61668. GENERAL_NAME_free(gn);
  61669. gn = NULL;
  61670. }
  61671. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61672. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61673. if (EXPECT_FAIL()) {
  61674. GENERAL_NAME_free(gn);
  61675. }
  61676. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61677. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61678. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  61679. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  61680. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  61681. sid_data));
  61682. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  61683. /* Ensure an empty stack doesn't raise an error. */
  61684. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61685. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  61686. if (EXPECT_FAIL()) {
  61687. X509_EXTENSION_free(san_ext);
  61688. }
  61689. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  61690. if (EXPECT_FAIL()) {
  61691. X509_EXTENSION_free(sid_ext);
  61692. }
  61693. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61694. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61695. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61696. if (f != XBADFILE)
  61697. XFCLOSE(f);
  61698. pt = der;
  61699. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61700. (const unsigned char**)&pt, derSz));
  61701. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  61702. pt = der;
  61703. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  61704. X509_REQ_free(x509);
  61705. x509 = NULL;
  61706. pt = der;
  61707. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  61708. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61709. gns = NULL;
  61710. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61711. exts = NULL;
  61712. ASN1_OBJECT_free(upn_oid);
  61713. ASN1_OBJECT_free(sid_oid);
  61714. ASN1_OCTET_STRING_free(sid_data);
  61715. X509_REQ_free(x509);
  61716. EVP_PKEY_free(priv);
  61717. /* At this point everything used to generate what is in der is cleaned up.
  61718. * We now read back from der to confirm the extensions were inserted
  61719. * correctly. */
  61720. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  61721. ExpectNotNull(bio);
  61722. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  61723. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  61724. ExpectNotNull(x509);
  61725. BIO_free(bio);
  61726. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  61727. x509));
  61728. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  61729. /* Check the SID extension. */
  61730. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61731. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61732. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  61733. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61734. ExpectIntEQ(extval->length, sizeof(SidExtension));
  61735. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  61736. ASN1_OBJECT_free(sid_oid);
  61737. /* Check the AltNames extension. */
  61738. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  61739. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61740. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  61741. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61742. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  61743. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  61744. 0);
  61745. ASN1_OBJECT_free(alt_names_oid);
  61746. /* Cleanup */
  61747. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61748. NID_subject_alt_name, NULL, NULL));
  61749. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  61750. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  61751. ExpectIntEQ(gn->type, 0);
  61752. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61753. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61754. X509_REQ_free(x509);
  61755. #endif
  61756. return EXPECT_RESULT();
  61757. }
  61758. static int test_wolfSSL_X509_set_name(void)
  61759. {
  61760. EXPECT_DECLS;
  61761. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61762. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61763. X509* x509 = NULL;
  61764. X509_NAME* name = NULL;
  61765. ExpectNotNull(name = X509_NAME_new());
  61766. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  61767. (byte*)"wolfssl.com", 11, 0, 1),
  61768. WOLFSSL_SUCCESS);
  61769. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  61770. (byte*)"support@wolfssl.com", 19, -1,
  61771. 1), WOLFSSL_SUCCESS);
  61772. ExpectNotNull(x509 = X509_new());
  61773. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61774. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61775. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61776. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  61777. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61778. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61779. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61780. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  61781. X509_free(x509);
  61782. X509_NAME_free(name);
  61783. #endif /* OPENSSL_ALL && !NO_CERTS */
  61784. return EXPECT_RESULT();
  61785. }
  61786. static int test_wolfSSL_X509_set_notAfter(void)
  61787. {
  61788. EXPECT_DECLS;
  61789. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61790. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61791. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61792. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  61793. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  61794. /* Generalized time will overflow time_t if not long */
  61795. X509* x = NULL;
  61796. BIO* bio = NULL;
  61797. ASN1_TIME *asn_time = NULL;
  61798. ASN1_TIME *time_check = NULL;
  61799. const int year = 365*24*60*60;
  61800. const int day = 24*60*60;
  61801. const int hour = 60*60;
  61802. const int mini = 60;
  61803. int offset_day;
  61804. unsigned char buf[25];
  61805. time_t t;
  61806. /*
  61807. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61808. */
  61809. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  61810. offset_day = 7;
  61811. /*
  61812. * Free these.
  61813. */
  61814. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61815. ExpectNotNull(asn_time);
  61816. ExpectNotNull(x = X509_new());
  61817. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61818. /*
  61819. * Tests
  61820. */
  61821. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  61822. /* time_check is simply (ANS1_TIME*)x->notAfter */
  61823. ExpectNotNull(time_check = X509_get_notAfter(x));
  61824. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61825. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61826. /* Convert to human readable format and compare to intended date */
  61827. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61828. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61829. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  61830. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  61831. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  61832. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  61833. /*
  61834. * Cleanup
  61835. */
  61836. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61837. X509_free(x);
  61838. BIO_free(bio);
  61839. #endif
  61840. return EXPECT_RESULT();
  61841. }
  61842. static int test_wolfSSL_X509_set_notBefore(void)
  61843. {
  61844. EXPECT_DECLS;
  61845. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61846. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61847. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61848. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  61849. X509* x = NULL;
  61850. BIO* bio = NULL;
  61851. ASN1_TIME *asn_time = NULL;
  61852. ASN1_TIME *time_check = NULL;
  61853. const int year = 365*24*60*60;
  61854. const int day = 24*60*60;
  61855. const int hour = 60*60;
  61856. const int mini = 60;
  61857. int offset_day;
  61858. unsigned char buf[25];
  61859. time_t t;
  61860. /*
  61861. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61862. */
  61863. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  61864. offset_day = 7;
  61865. /*
  61866. * Free these.
  61867. */
  61868. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61869. ExpectNotNull(asn_time);
  61870. ExpectNotNull(x = X509_new());
  61871. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61872. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  61873. /*
  61874. * Main Tests
  61875. */
  61876. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  61877. /* time_check == (ANS1_TIME*)x->notBefore */
  61878. ExpectNotNull(time_check = X509_get_notBefore(x));
  61879. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61880. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61881. /* Convert to human readable format and compare to intended date */
  61882. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61883. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61884. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  61885. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  61886. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  61887. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  61888. /*
  61889. * Cleanup
  61890. */
  61891. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61892. X509_free(x);
  61893. BIO_free(bio);
  61894. #endif
  61895. return EXPECT_RESULT();
  61896. }
  61897. static int test_wolfSSL_X509_set_version(void)
  61898. {
  61899. EXPECT_DECLS;
  61900. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  61901. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61902. X509* x509 = NULL;
  61903. long v = 2L;
  61904. long maxInt = INT_MAX;
  61905. ExpectNotNull(x509 = X509_new());
  61906. /* These should pass. */
  61907. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  61908. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  61909. /* Fail Case: When v(long) is greater than x509->version(int). */
  61910. v = maxInt+1;
  61911. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  61912. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  61913. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  61914. /* Cleanup */
  61915. X509_free(x509);
  61916. #endif
  61917. return EXPECT_RESULT();
  61918. }
  61919. #ifndef NO_BIO
  61920. static int test_wolfSSL_BIO_gets(void)
  61921. {
  61922. EXPECT_DECLS;
  61923. #if defined(OPENSSL_EXTRA)
  61924. BIO* bio = NULL;
  61925. BIO* bio2 = NULL;
  61926. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  61927. char emp[] = "";
  61928. char bio_buffer[20];
  61929. int bufferSz = 20;
  61930. #ifdef OPENSSL_ALL
  61931. BUF_MEM* emp_bm = NULL;
  61932. BUF_MEM* msg_bm = NULL;
  61933. #endif
  61934. /* try with bad args */
  61935. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  61936. #ifdef OPENSSL_ALL
  61937. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  61938. #endif
  61939. /* try with real msg */
  61940. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61941. XMEMSET(bio_buffer, 0, bufferSz);
  61942. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  61943. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  61944. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  61945. ExpectFalse(bio2 != BIO_next(bio));
  61946. /* make buffer filled with no terminating characters */
  61947. XMEMSET(bio_buffer, 1, bufferSz);
  61948. /* BIO_gets reads a line of data */
  61949. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61950. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61951. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61952. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61953. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61954. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61955. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61956. #ifdef OPENSSL_ALL
  61957. /* test setting the mem_buf manually */
  61958. BIO_free(bio);
  61959. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61960. ExpectNotNull(emp_bm = BUF_MEM_new());
  61961. ExpectNotNull(msg_bm = BUF_MEM_new());
  61962. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  61963. if (EXPECT_SUCCESS()) {
  61964. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61965. msg_bm->data = NULL;
  61966. }
  61967. /* emp size is 1 for terminator */
  61968. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  61969. if (EXPECT_SUCCESS()) {
  61970. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61971. emp_bm->data = emp;
  61972. msg_bm->data = msg;
  61973. }
  61974. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  61975. /* check reading an empty string */
  61976. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61977. ExpectStrEQ(emp, bio_buffer);
  61978. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61979. /* BIO_gets reads a line of data */
  61980. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  61981. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61982. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61983. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61984. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61985. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61986. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61987. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61988. if (EXPECT_SUCCESS())
  61989. emp_bm->data = NULL;
  61990. BUF_MEM_free(emp_bm);
  61991. if (EXPECT_SUCCESS())
  61992. msg_bm->data = NULL;
  61993. BUF_MEM_free(msg_bm);
  61994. #endif
  61995. /* check not null terminated string */
  61996. BIO_free(bio);
  61997. bio = NULL;
  61998. msg[0] = 0x33;
  61999. msg[1] = 0x33;
  62000. msg[2] = 0x33;
  62001. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  62002. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  62003. ExpectIntEQ(bio_buffer[0], msg[0]);
  62004. ExpectIntEQ(bio_buffer[1], msg[1]);
  62005. ExpectIntNE(bio_buffer[2], msg[2]);
  62006. BIO_free(bio);
  62007. bio = NULL;
  62008. msg[3] = 0x33;
  62009. bio_buffer[3] = 0x33;
  62010. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  62011. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  62012. ExpectIntEQ(bio_buffer[0], msg[0]);
  62013. ExpectIntEQ(bio_buffer[1], msg[1]);
  62014. ExpectIntEQ(bio_buffer[2], msg[2]);
  62015. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  62016. /* check reading an empty string */
  62017. BIO_free(bio);
  62018. bio = NULL;
  62019. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  62020. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  62021. ExpectStrEQ(emp, bio_buffer);
  62022. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62023. /* check error cases */
  62024. BIO_free(bio);
  62025. bio = NULL;
  62026. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62027. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62028. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62029. #if !defined(NO_FILESYSTEM)
  62030. {
  62031. BIO* f_bio = NULL;
  62032. XFILE f = XBADFILE;
  62033. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  62034. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62035. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  62036. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  62037. if (EXPECT_FAIL() && (f != XBADFILE)) {
  62038. XFCLOSE(f);
  62039. }
  62040. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62041. BIO_free(f_bio);
  62042. f_bio = NULL;
  62043. }
  62044. #endif /* NO_FILESYSTEM */
  62045. BIO_free(bio);
  62046. bio = NULL;
  62047. BIO_free(bio2);
  62048. bio2 = NULL;
  62049. /* try with type BIO */
  62050. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  62051. sizeof(msg));
  62052. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62053. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62054. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  62055. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  62056. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  62057. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  62058. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  62059. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62060. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62061. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62062. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62063. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62064. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62065. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62066. BIO_free(bio);
  62067. bio = NULL;
  62068. BIO_free(bio2);
  62069. bio2 = NULL;
  62070. /* check reading an empty string */
  62071. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62072. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  62073. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62074. ExpectStrEQ(emp, bio_buffer);
  62075. BIO_free(bio);
  62076. bio = NULL;
  62077. #endif
  62078. return EXPECT_RESULT();
  62079. }
  62080. static int test_wolfSSL_BIO_puts(void)
  62081. {
  62082. EXPECT_DECLS;
  62083. #if defined(OPENSSL_EXTRA)
  62084. BIO* bio = NULL;
  62085. char input[] = "hello\0world\n.....ok\n\0";
  62086. char output[128];
  62087. XMEMSET(output, 0, sizeof(output));
  62088. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62089. ExpectIntEQ(BIO_puts(bio, input), 5);
  62090. ExpectIntEQ(BIO_pending(bio), 5);
  62091. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  62092. ExpectIntEQ(BIO_pending(bio), 19);
  62093. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  62094. ExpectStrEQ(output, "helloworld\n");
  62095. ExpectIntEQ(BIO_pending(bio), 8);
  62096. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  62097. ExpectStrEQ(output, ".....ok\n");
  62098. ExpectIntEQ(BIO_pending(bio), 0);
  62099. ExpectIntEQ(BIO_puts(bio, ""), -1);
  62100. BIO_free(bio);
  62101. #endif
  62102. return EXPECT_RESULT();
  62103. }
  62104. static int test_wolfSSL_BIO_dump(void)
  62105. {
  62106. EXPECT_DECLS;
  62107. #if defined(OPENSSL_EXTRA)
  62108. BIO* bio;
  62109. static const unsigned char data[] = {
  62110. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  62111. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  62112. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  62113. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  62114. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  62115. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  62116. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  62117. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  62118. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  62119. 0xB4
  62120. };
  62121. /* Generated with OpenSSL. */
  62122. static const char expected[] =
  62123. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  62124. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  62125. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  62126. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  62127. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  62128. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  62129. static const char expectedAll[] =
  62130. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  62131. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  62132. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  62133. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  62134. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  62135. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  62136. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  62137. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  62138. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  62139. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  62140. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  62141. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  62142. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  62143. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  62144. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  62145. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  62146. char output[16 * 80];
  62147. int i;
  62148. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62149. /* Example key dumped. */
  62150. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  62151. sizeof(expected) - 1);
  62152. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  62153. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  62154. /* Try every possible value for a character. */
  62155. for (i = 0; i < 256; i++)
  62156. output[i] = i;
  62157. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  62158. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  62159. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  62160. BIO_free(bio);
  62161. #endif
  62162. return EXPECT_RESULT();
  62163. }
  62164. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62165. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62166. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62167. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  62168. {
  62169. (void)ssl;
  62170. (void)buf;
  62171. (void)sz;
  62172. (void)ctx;
  62173. return WOLFSSL_CBIO_ERR_WANT_READ;
  62174. }
  62175. #endif
  62176. static int test_wolfSSL_BIO_should_retry(void)
  62177. {
  62178. EXPECT_DECLS;
  62179. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62180. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62181. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62182. tcp_ready ready;
  62183. func_args server_args;
  62184. THREAD_TYPE serverThread;
  62185. SOCKET_T sockfd = 0;
  62186. WOLFSSL_CTX* ctx = NULL;
  62187. WOLFSSL* ssl = NULL;
  62188. char msg[64] = "hello wolfssl!";
  62189. char reply[1024];
  62190. int msgSz = (int)XSTRLEN(msg);
  62191. int ret;
  62192. BIO* bio = NULL;
  62193. XMEMSET(&server_args, 0, sizeof(func_args));
  62194. #ifdef WOLFSSL_TIRTOS
  62195. fdOpenSession(Task_self());
  62196. #endif
  62197. StartTCP();
  62198. InitTcpReady(&ready);
  62199. #if defined(USE_WINDOWS_API)
  62200. /* use RNG to get random port if using windows */
  62201. ready.port = GetRandomPort();
  62202. #endif
  62203. server_args.signal = &ready;
  62204. start_thread(test_server_nofail, &server_args, &serverThread);
  62205. wait_tcp_ready(&server_args);
  62206. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62207. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  62208. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  62209. #endif
  62210. ExpectIntEQ(WOLFSSL_SUCCESS,
  62211. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  62212. ExpectIntEQ(WOLFSSL_SUCCESS,
  62213. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  62214. ExpectIntEQ(WOLFSSL_SUCCESS,
  62215. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  62216. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  62217. /* force retry */
  62218. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  62219. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  62220. ExpectNotNull(ssl);
  62221. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  62222. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  62223. if (EXPECT_FAIL()) {
  62224. wolfSSL_free(ssl);
  62225. ssl = NULL;
  62226. }
  62227. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  62228. ExpectIntNE(BIO_should_retry(bio), 0);
  62229. ExpectIntEQ(BIO_should_read(bio), 0);
  62230. ExpectIntEQ(BIO_should_write(bio), 0);
  62231. /* now perform successful connection */
  62232. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  62233. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  62234. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  62235. ret = wolfSSL_get_error(ssl, -1);
  62236. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  62237. ExpectIntNE(BIO_should_retry(bio), 0);
  62238. if (ret == WOLFSSL_ERROR_WANT_READ)
  62239. ExpectIntEQ(BIO_should_read(bio), 1);
  62240. else
  62241. ExpectIntEQ(BIO_should_read(bio), 0);
  62242. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  62243. ExpectIntEQ(BIO_should_write(bio), 1);
  62244. else
  62245. ExpectIntEQ(BIO_should_write(bio), 0);
  62246. }
  62247. else {
  62248. ExpectIntEQ(BIO_should_retry(bio), 0);
  62249. ExpectIntEQ(BIO_should_read(bio), 0);
  62250. ExpectIntEQ(BIO_should_write(bio), 0);
  62251. }
  62252. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  62253. XSTRLEN("I hear you fa shizzle!")), 0);
  62254. BIO_free(bio);
  62255. wolfSSL_CTX_free(ctx);
  62256. CloseSocket(sockfd);
  62257. join_thread(serverThread);
  62258. FreeTcpReady(&ready);
  62259. #ifdef WOLFSSL_TIRTOS
  62260. fdOpenSession(Task_self());
  62261. #endif
  62262. #endif
  62263. return EXPECT_RESULT();
  62264. }
  62265. static int test_wolfSSL_BIO_connect(void)
  62266. {
  62267. EXPECT_DECLS;
  62268. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62269. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  62270. tcp_ready ready;
  62271. func_args server_args;
  62272. THREAD_TYPE serverThread;
  62273. BIO *tcpBio = NULL;
  62274. BIO *sslBio = NULL;
  62275. SSL_CTX* ctx = NULL;
  62276. SSL *ssl = NULL;
  62277. SSL *sslPtr;
  62278. char msg[] = "hello wolfssl!";
  62279. char reply[30];
  62280. char buff[10] = {0};
  62281. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62282. ExpectIntEQ(WOLFSSL_SUCCESS,
  62283. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  62284. ExpectIntEQ(WOLFSSL_SUCCESS,
  62285. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  62286. ExpectIntEQ(WOLFSSL_SUCCESS,
  62287. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  62288. /* Setup server */
  62289. XMEMSET(&server_args, 0, sizeof(func_args));
  62290. StartTCP();
  62291. InitTcpReady(&ready);
  62292. #if defined(USE_WINDOWS_API)
  62293. /* use RNG to get random port if using windows */
  62294. ready.port = GetRandomPort();
  62295. #endif
  62296. server_args.signal = &ready;
  62297. start_thread(test_server_nofail, &server_args, &serverThread);
  62298. wait_tcp_ready(&server_args);
  62299. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62300. /* Start the test proper */
  62301. /* Setup the TCP BIO */
  62302. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  62303. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  62304. /* Setup the SSL object */
  62305. ExpectNotNull(ssl = SSL_new(ctx));
  62306. SSL_set_connect_state(ssl);
  62307. /* Setup the SSL BIO */
  62308. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  62309. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  62310. if (EXPECT_FAIL()) {
  62311. wolfSSL_free(ssl);
  62312. }
  62313. /* Verify that BIO_get_ssl works. */
  62314. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  62315. ExpectPtrEq(ssl, sslPtr);
  62316. /* Link BIO's so that sslBio uses tcpBio for IO */
  62317. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  62318. /* Do TCP connect */
  62319. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62320. /* Do TLS handshake */
  62321. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62322. /* Test writing */
  62323. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62324. /* Expect length of default wolfSSL reply */
  62325. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62326. /* Clean it all up */
  62327. BIO_free_all(sslBio);
  62328. /* Server clean up */
  62329. join_thread(serverThread);
  62330. FreeTcpReady(&ready);
  62331. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  62332. * after. */
  62333. XMEMSET(&server_args, 0, sizeof(func_args));
  62334. StartTCP();
  62335. InitTcpReady(&ready);
  62336. #if defined(USE_WINDOWS_API)
  62337. /* use RNG to get random port if using windows */
  62338. ready.port = GetRandomPort();
  62339. #endif
  62340. server_args.signal = &ready;
  62341. start_thread(test_server_nofail, &server_args, &serverThread);
  62342. wait_tcp_ready(&server_args);
  62343. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62344. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  62345. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  62346. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  62347. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62348. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62349. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62350. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62351. /* Attempt to close the TLS connection gracefully. */
  62352. BIO_ssl_shutdown(sslBio);
  62353. BIO_free_all(sslBio);
  62354. join_thread(serverThread);
  62355. FreeTcpReady(&ready);
  62356. SSL_CTX_free(ctx);
  62357. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62358. wc_ecc_fp_free(); /* free per thread cache */
  62359. #endif
  62360. #endif
  62361. return EXPECT_RESULT();
  62362. }
  62363. static int test_wolfSSL_BIO_tls(void)
  62364. {
  62365. EXPECT_DECLS;
  62366. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  62367. SSL_CTX* ctx = NULL;
  62368. SSL *ssl = NULL;
  62369. BIO *readBio = NULL;
  62370. BIO *writeBio = NULL;
  62371. int ret;
  62372. int err = 0;
  62373. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62374. ExpectNotNull(ssl = SSL_new(ctx));
  62375. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  62376. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  62377. /* Qt reads data from write-bio,
  62378. * then writes the read data into plain packet.
  62379. * Qt reads data from plain packet,
  62380. * then writes the read data into read-bio.
  62381. */
  62382. SSL_set_bio(ssl, readBio, writeBio);
  62383. do {
  62384. #ifdef WOLFSSL_ASYNC_CRYPT
  62385. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62386. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62387. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62388. }
  62389. #endif
  62390. ret = SSL_connect(ssl);
  62391. err = SSL_get_error(ssl, 0);
  62392. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62393. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62394. /* in this use case, should return WANT READ
  62395. * so that Qt will read the data from plain packet for next state.
  62396. */
  62397. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  62398. SSL_free(ssl);
  62399. SSL_CTX_free(ctx);
  62400. #endif
  62401. return EXPECT_RESULT();
  62402. }
  62403. static int test_wolfSSL_BIO_datagram(void)
  62404. {
  62405. EXPECT_DECLS;
  62406. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  62407. int ret;
  62408. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  62409. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  62410. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  62411. SOCKADDR_IN sin1, sin2;
  62412. socklen_t slen;
  62413. static const char test_msg[] = "I am a datagram, short and stout.";
  62414. char test_msg_recvd[sizeof(test_msg) + 10];
  62415. #ifdef USE_WINDOWS_API
  62416. static const DWORD timeout = 250; /* ms */
  62417. #else
  62418. static const struct timeval timeout = { 0, 250000 };
  62419. #endif
  62420. StartTCP();
  62421. if (EXPECT_SUCCESS()) {
  62422. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62423. ExpectIntNE(fd1, SOCKET_INVALID);
  62424. }
  62425. if (EXPECT_SUCCESS()) {
  62426. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62427. ExpectIntNE(fd2, SOCKET_INVALID);
  62428. }
  62429. if (EXPECT_SUCCESS()) {
  62430. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  62431. ExpectNotNull(bio1);
  62432. }
  62433. if (EXPECT_SUCCESS()) {
  62434. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  62435. ExpectNotNull(bio2);
  62436. }
  62437. if (EXPECT_SUCCESS()) {
  62438. sin1.sin_family = AF_INET;
  62439. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62440. sin1.sin_port = 0;
  62441. slen = (socklen_t)sizeof(sin1);
  62442. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  62443. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62444. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  62445. }
  62446. if (EXPECT_SUCCESS()) {
  62447. sin2.sin_family = AF_INET;
  62448. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62449. sin2.sin_port = 0;
  62450. slen = (socklen_t)sizeof(sin2);
  62451. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  62452. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62453. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  62454. }
  62455. if (EXPECT_SUCCESS()) {
  62456. bio_addr1 = wolfSSL_BIO_ADDR_new();
  62457. ExpectNotNull(bio_addr1);
  62458. }
  62459. if (EXPECT_SUCCESS()) {
  62460. bio_addr2 = wolfSSL_BIO_ADDR_new();
  62461. ExpectNotNull(bio_addr2);
  62462. }
  62463. if (EXPECT_SUCCESS()) {
  62464. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  62465. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62466. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62467. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62468. }
  62469. test_msg_recvd[0] = 0;
  62470. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62471. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62472. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62473. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  62474. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  62475. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  62476. #endif
  62477. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  62478. * BIOs aren't "connected" yet. use it to send a reply.
  62479. */
  62480. test_msg_recvd[0] = 0;
  62481. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62482. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62483. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62484. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62485. ExpectIntNE(BIO_should_retry(bio1), 0);
  62486. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62487. ExpectIntNE(BIO_should_retry(bio2), 0);
  62488. /* now "connect" the sockets. */
  62489. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  62490. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62491. if (EXPECT_SUCCESS()) {
  62492. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62493. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  62494. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62495. }
  62496. if (EXPECT_SUCCESS()) {
  62497. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  62498. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  62499. wolfSSL_BIO_ADDR_clear(bio_addr1);
  62500. }
  62501. test_msg_recvd[0] = 0;
  62502. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62503. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62504. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62505. test_msg_recvd[0] = 0;
  62506. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62507. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62508. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62509. #ifdef __linux__
  62510. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  62511. sin1.sin_family = AF_UNSPEC;
  62512. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62513. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62514. sin1.sin_family = AF_INET;
  62515. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62516. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62517. if (EXPECT_SUCCESS()) {
  62518. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  62519. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62520. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62521. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62522. }
  62523. test_msg_recvd[0] = 0;
  62524. errno = 0;
  62525. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  62526. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  62527. #endif /* __linux__ */
  62528. if (bio1) {
  62529. ret = wolfSSL_BIO_free(bio1);
  62530. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62531. } else if (fd1 != SOCKET_INVALID)
  62532. CloseSocket(fd1);
  62533. if (bio2) {
  62534. ret = wolfSSL_BIO_free(bio2);
  62535. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62536. } else if (fd2 != SOCKET_INVALID)
  62537. CloseSocket(fd2);
  62538. if (bio_addr1)
  62539. wolfSSL_BIO_ADDR_free(bio_addr1);
  62540. if (bio_addr2)
  62541. wolfSSL_BIO_ADDR_free(bio_addr2);
  62542. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  62543. return EXPECT_RESULT();
  62544. }
  62545. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62546. defined(HAVE_HTTP_CLIENT)
  62547. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  62548. {
  62549. BIO* clientBio;
  62550. SSL* sslClient;
  62551. SSL_CTX* ctx;
  62552. char connectAddr[20]; /* IP + port */;
  62553. (void)args;
  62554. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  62555. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  62556. AssertIntEQ(BIO_do_connect(clientBio), 1);
  62557. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62558. AssertNotNull(sslClient = SSL_new(ctx));
  62559. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  62560. SSL_set_bio(sslClient, clientBio, clientBio);
  62561. AssertIntEQ(SSL_connect(sslClient), 1);
  62562. SSL_free(sslClient);
  62563. SSL_CTX_free(ctx);
  62564. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62565. wc_ecc_fp_free(); /* free per thread cache */
  62566. #endif
  62567. WOLFSSL_RETURN_FROM_THREAD(0);
  62568. }
  62569. #endif
  62570. static int test_wolfSSL_BIO_accept(void)
  62571. {
  62572. EXPECT_DECLS;
  62573. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62574. defined(HAVE_HTTP_CLIENT)
  62575. BIO* serverBindBio = NULL;
  62576. BIO* serverAcceptBio = NULL;
  62577. SSL* sslServer = NULL;
  62578. SSL_CTX* ctx = NULL;
  62579. func_args args;
  62580. THREAD_TYPE thread;
  62581. char port[10]; /* 10 bytes should be enough to store the string
  62582. * representation of the port */
  62583. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  62584. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  62585. /* First BIO_do_accept binds the port */
  62586. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62587. XMEMSET(&args, 0, sizeof(func_args));
  62588. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  62589. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62590. /* Let's plug it into SSL to test */
  62591. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62592. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  62593. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62594. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  62595. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62596. ExpectNotNull(sslServer = SSL_new(ctx));
  62597. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  62598. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  62599. ExpectIntEQ(SSL_accept(sslServer), 1);
  62600. join_thread(thread);
  62601. BIO_free(serverBindBio);
  62602. SSL_free(sslServer);
  62603. SSL_CTX_free(ctx);
  62604. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62605. wc_ecc_fp_free(); /* free per thread cache */
  62606. #endif
  62607. #endif
  62608. return EXPECT_RESULT();
  62609. }
  62610. static int test_wolfSSL_BIO_write(void)
  62611. {
  62612. EXPECT_DECLS;
  62613. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  62614. BIO* bio = NULL;
  62615. BIO* bio64 = NULL;
  62616. BIO* bio_mem = NULL;
  62617. BIO* ptr = NULL;
  62618. int sz;
  62619. char msg[] = "conversion test";
  62620. char out[40];
  62621. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  62622. void* bufPtr = NULL;
  62623. BUF_MEM* buf = NULL;
  62624. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62625. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  62626. if (EXPECT_FAIL()) {
  62627. BIO_free(bio64);
  62628. }
  62629. /* now should convert to base64 then write to memory */
  62630. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62631. BIO_flush(bio);
  62632. /* test BIO chain */
  62633. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  62634. ExpectNotNull(buf);
  62635. ExpectIntEQ(buf->length, 25);
  62636. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  62637. ExpectPtrEq(buf->data, bufPtr);
  62638. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  62639. sz = sizeof(out);
  62640. XMEMSET(out, 0, sz);
  62641. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  62642. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62643. /* write then read should return the same message */
  62644. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62645. sz = sizeof(out);
  62646. XMEMSET(out, 0, sz);
  62647. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  62648. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62649. /* now try encoding with no line ending */
  62650. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  62651. #ifdef HAVE_EX_DATA
  62652. BIO_set_ex_data(bio64, 0, (void*) "data");
  62653. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  62654. #endif
  62655. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62656. BIO_flush(bio);
  62657. sz = sizeof(out);
  62658. XMEMSET(out, 0, sz);
  62659. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  62660. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62661. BIO_free_all(bio); /* frees bio64 also */
  62662. bio = NULL;
  62663. /* test with more than one bio64 in list */
  62664. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62665. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  62666. if (EXPECT_FAIL()) {
  62667. BIO_free(bio64);
  62668. bio64 = NULL;
  62669. }
  62670. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  62671. ExpectNotNull(BIO_push(bio64, bio_mem));
  62672. if (EXPECT_FAIL()) {
  62673. BIO_free(bio_mem);
  62674. }
  62675. /* now should convert to base64 when stored and then decode with read */
  62676. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  62677. BIO_flush(bio);
  62678. sz = sizeof(out);
  62679. XMEMSET(out, 0, sz);
  62680. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  62681. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  62682. BIO_clear_flags(bio64, ~0);
  62683. BIO_set_retry_read(bio);
  62684. BIO_free_all(bio); /* frees bio64s also */
  62685. bio = NULL;
  62686. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  62687. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62688. BIO_free(bio);
  62689. #endif
  62690. return EXPECT_RESULT();
  62691. }
  62692. static int test_wolfSSL_BIO_printf(void)
  62693. {
  62694. EXPECT_DECLS;
  62695. #if defined(OPENSSL_ALL)
  62696. BIO* bio = NULL;
  62697. int sz = 7;
  62698. char msg[] = "TLS 1.3 for the world";
  62699. char out[60];
  62700. char expected[] = "TLS 1.3 for the world : sz = 7";
  62701. XMEMSET(out, 0, sizeof(out));
  62702. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62703. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  62704. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62705. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  62706. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  62707. BIO_free(bio);
  62708. #endif
  62709. return EXPECT_RESULT();
  62710. }
  62711. static int test_wolfSSL_BIO_f_md(void)
  62712. {
  62713. EXPECT_DECLS;
  62714. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  62715. BIO* bio = NULL;
  62716. BIO* mem = NULL;
  62717. char msg[] = "message to hash";
  62718. char out[60];
  62719. EVP_MD_CTX* ctx = NULL;
  62720. const unsigned char testKey[] =
  62721. {
  62722. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62723. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62724. 0x0b, 0x0b, 0x0b, 0x0b
  62725. };
  62726. const char testData[] = "Hi There";
  62727. const unsigned char testResult[] =
  62728. {
  62729. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  62730. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  62731. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  62732. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  62733. };
  62734. const unsigned char expectedHash[] =
  62735. {
  62736. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  62737. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  62738. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  62739. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  62740. };
  62741. const unsigned char emptyHash[] =
  62742. {
  62743. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  62744. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  62745. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  62746. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  62747. };
  62748. unsigned char check[sizeof(testResult) + 1];
  62749. size_t checkSz = -1;
  62750. EVP_PKEY* key = NULL;
  62751. XMEMSET(out, 0, sizeof(out));
  62752. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62753. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62754. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  62755. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  62756. /* should not be able to write/read yet since just digest wrapper and no
  62757. * data is passing through the bio */
  62758. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  62759. ExpectIntEQ(BIO_pending(bio), 0);
  62760. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  62761. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  62762. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62763. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  62764. BIO_reset(bio);
  62765. /* append BIO mem to bio in order to read/write */
  62766. ExpectNotNull(bio = BIO_push(bio, mem));
  62767. XMEMSET(out, 0, sizeof(out));
  62768. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  62769. ExpectIntEQ(BIO_pending(bio), 16);
  62770. /* this just reads the message and does not hash it (gets calls final) */
  62771. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  62772. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62773. /* create a message digest using BIO */
  62774. XMEMSET(out, 0, sizeof(out));
  62775. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  62776. ExpectIntEQ(BIO_pending(mem), 16);
  62777. ExpectIntEQ(BIO_pending(bio), 16);
  62778. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62779. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  62780. BIO_free(bio);
  62781. bio = NULL;
  62782. BIO_free(mem);
  62783. mem = NULL;
  62784. /* test with HMAC */
  62785. XMEMSET(out, 0, sizeof(out));
  62786. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62787. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62788. BIO_get_md_ctx(bio, &ctx);
  62789. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  62790. (int)sizeof(testKey)));
  62791. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  62792. ExpectNotNull(bio = BIO_push(bio, mem));
  62793. BIO_write(bio, testData, (int)strlen(testData));
  62794. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  62795. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  62796. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  62797. EVP_PKEY_free(key);
  62798. BIO_free(bio);
  62799. BIO_free(mem);
  62800. #endif
  62801. return EXPECT_RESULT();
  62802. }
  62803. static int test_wolfSSL_BIO_up_ref(void)
  62804. {
  62805. EXPECT_DECLS;
  62806. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62807. BIO* bio = NULL;
  62808. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62809. ExpectIntEQ(BIO_up_ref(NULL), 0);
  62810. ExpectIntEQ(BIO_up_ref(bio), 1);
  62811. BIO_free(bio);
  62812. ExpectIntEQ(BIO_up_ref(bio), 1);
  62813. BIO_free(bio);
  62814. BIO_free(bio);
  62815. #endif
  62816. return EXPECT_RESULT();
  62817. }
  62818. static int test_wolfSSL_BIO_reset(void)
  62819. {
  62820. EXPECT_DECLS;
  62821. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62822. BIO* bio = NULL;
  62823. byte buf[16];
  62824. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  62825. (word32)XSTRLEN("secure your data")));
  62826. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  62827. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  62828. XMEMSET(buf, 0, 16);
  62829. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  62830. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  62831. /* You cannot write to MEM BIO with read-only mode. */
  62832. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  62833. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  62834. XMEMSET(buf, 0, 16);
  62835. ExpectIntEQ(BIO_reset(bio), 1);
  62836. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  62837. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  62838. BIO_free(bio);
  62839. #endif
  62840. return EXPECT_RESULT();
  62841. }
  62842. #endif /* !NO_BIO */
  62843. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62844. /* test that the callback arg is correct */
  62845. static int certCbArg = 0;
  62846. static int certCb(WOLFSSL* ssl, void* arg)
  62847. {
  62848. if (ssl == NULL || arg != &certCbArg)
  62849. return 0;
  62850. if (wolfSSL_is_server(ssl)) {
  62851. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  62852. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62853. return 0;
  62854. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  62855. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62856. return 0;
  62857. }
  62858. else {
  62859. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  62860. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62861. return 0;
  62862. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  62863. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62864. return 0;
  62865. }
  62866. return 1;
  62867. }
  62868. static int certSetupCb(WOLFSSL_CTX* ctx)
  62869. {
  62870. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  62871. return TEST_SUCCESS;
  62872. }
  62873. /**
  62874. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  62875. * to stop certificate and key loading
  62876. */
  62877. static int certClearCb(WOLFSSL* ssl)
  62878. {
  62879. /* Clear the loaded certs to force the callbacks to set them up */
  62880. SSL_certs_clear(ssl);
  62881. return TEST_SUCCESS;
  62882. }
  62883. #endif
  62884. static int test_wolfSSL_cert_cb(void)
  62885. {
  62886. EXPECT_DECLS;
  62887. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62888. test_ssl_cbf func_cb_client;
  62889. test_ssl_cbf func_cb_server;
  62890. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62891. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62892. func_cb_client.ctx_ready = certSetupCb;
  62893. func_cb_client.ssl_ready = certClearCb;
  62894. func_cb_server.ctx_ready = certSetupCb;
  62895. func_cb_server.ssl_ready = certClearCb;
  62896. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62897. &func_cb_server, NULL), TEST_SUCCESS);
  62898. #endif
  62899. return EXPECT_RESULT();
  62900. }
  62901. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62902. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  62903. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  62904. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  62905. {
  62906. EXPECT_DECLS;
  62907. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  62908. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  62909. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  62910. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  62911. return EXPECT_RESULT();
  62912. }
  62913. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  62914. {
  62915. const byte* suites = NULL;
  62916. word16 suiteSz = 0;
  62917. const byte* hashSigAlgo = NULL;
  62918. word16 hashSigAlgoSz = 0;
  62919. word16 idx = 0;
  62920. int haveRSA = 0;
  62921. int haveECC = 0;
  62922. (void)arg;
  62923. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  62924. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  62925. return 0;
  62926. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  62927. hashSigAlgoSz == 0)
  62928. return 0;
  62929. for (idx = 0; idx < suiteSz; idx += 2) {
  62930. WOLFSSL_CIPHERSUITE_INFO info =
  62931. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  62932. if (info.rsaAuth)
  62933. haveRSA = 1;
  62934. else if (info.eccAuth)
  62935. haveECC = 1;
  62936. }
  62937. if (hashSigAlgoSz > 0) {
  62938. /* sigalgs extension takes precedence over ciphersuites */
  62939. haveRSA = 0;
  62940. haveECC = 0;
  62941. }
  62942. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  62943. int hashAlgo = 0;
  62944. int sigAlgo = 0;
  62945. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  62946. &hashAlgo, &sigAlgo) != 0)
  62947. return 0;
  62948. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  62949. haveRSA = 1;
  62950. else if (sigAlgo == ECDSAk)
  62951. haveECC = 1;
  62952. }
  62953. if (haveRSA) {
  62954. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  62955. != WOLFSSL_SUCCESS)
  62956. return 0;
  62957. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  62958. != WOLFSSL_SUCCESS)
  62959. return 0;
  62960. }
  62961. else if (haveECC) {
  62962. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  62963. != WOLFSSL_SUCCESS)
  62964. return 0;
  62965. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  62966. != WOLFSSL_SUCCESS)
  62967. return 0;
  62968. }
  62969. return 1;
  62970. }
  62971. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  62972. {
  62973. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  62974. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  62975. return TEST_SUCCESS;
  62976. }
  62977. #endif
  62978. /* Testing dynamic ciphers offered by client */
  62979. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  62980. {
  62981. EXPECT_DECLS;
  62982. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62983. test_ssl_cbf func_cb_client;
  62984. test_ssl_cbf func_cb_server;
  62985. struct {
  62986. method_provider client_meth;
  62987. const char* client_ciphers;
  62988. const char* client_sigalgs;
  62989. const char* client_ca;
  62990. method_provider server_meth;
  62991. } test_params[] = {
  62992. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  62993. #ifdef WOLFSSL_TLS13
  62994. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  62995. {wolfTLSv1_3_client_method,
  62996. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62997. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  62998. #endif
  62999. #ifdef HAVE_ECC
  63000. {wolfTLSv1_3_client_method,
  63001. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  63002. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  63003. #endif
  63004. #endif
  63005. #ifndef WOLFSSL_NO_TLS12
  63006. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  63007. {wolfTLSv1_2_client_method,
  63008. "DHE-RSA-AES128-GCM-SHA256",
  63009. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  63010. #endif
  63011. #ifdef HAVE_ECC
  63012. {wolfTLSv1_2_client_method,
  63013. "ECDHE-ECDSA-AES128-GCM-SHA256",
  63014. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  63015. #endif
  63016. #endif
  63017. #endif
  63018. };
  63019. size_t i;
  63020. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  63021. if (testCount > 0) {
  63022. for (i = 0; i < testCount; i++) {
  63023. printf("\tTesting %s ciphers with %s sigalgs\n",
  63024. test_params[i].client_ciphers,
  63025. test_params[i].client_sigalgs);
  63026. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  63027. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  63028. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  63029. test_params[i].client_ciphers;
  63030. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  63031. test_params[i].client_sigalgs;
  63032. func_cb_client.method = test_params[i].client_meth;
  63033. func_cb_client.caPemFile = test_params[i].client_ca;
  63034. func_cb_client.ctx_ready =
  63035. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  63036. func_cb_server.ctx_ready =
  63037. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  63038. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  63039. func_cb_server.method = test_params[i].server_meth;
  63040. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  63041. &func_cb_server, NULL), TEST_SUCCESS);
  63042. }
  63043. }
  63044. #endif
  63045. return EXPECT_RESULT();
  63046. }
  63047. static int test_wolfSSL_ciphersuite_auth(void)
  63048. {
  63049. EXPECT_DECLS;
  63050. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63051. WOLFSSL_CIPHERSUITE_INFO info;
  63052. (void)info;
  63053. #ifndef WOLFSSL_NO_TLS12
  63054. #ifdef HAVE_CHACHA
  63055. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63056. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  63057. ExpectIntEQ(info.rsaAuth, 1);
  63058. ExpectIntEQ(info.eccAuth, 0);
  63059. ExpectIntEQ(info.eccStatic, 0);
  63060. ExpectIntEQ(info.psk, 0);
  63061. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63062. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  63063. ExpectIntEQ(info.rsaAuth, 0);
  63064. ExpectIntEQ(info.eccAuth, 1);
  63065. ExpectIntEQ(info.eccStatic, 0);
  63066. ExpectIntEQ(info.psk, 0);
  63067. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63068. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  63069. ExpectIntEQ(info.rsaAuth, 0);
  63070. ExpectIntEQ(info.eccAuth, 0);
  63071. ExpectIntEQ(info.eccStatic, 0);
  63072. ExpectIntEQ(info.psk, 1);
  63073. #endif
  63074. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  63075. #ifndef NO_RSA
  63076. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63077. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  63078. ExpectIntEQ(info.rsaAuth, 1);
  63079. ExpectIntEQ(info.eccAuth, 0);
  63080. ExpectIntEQ(info.eccStatic, 0);
  63081. ExpectIntEQ(info.psk, 0);
  63082. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63083. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  63084. ExpectIntEQ(info.rsaAuth, 1);
  63085. ExpectIntEQ(info.eccAuth, 0);
  63086. ExpectIntEQ(info.eccStatic, 1);
  63087. ExpectIntEQ(info.psk, 0);
  63088. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63089. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  63090. ExpectIntEQ(info.rsaAuth, 1);
  63091. ExpectIntEQ(info.eccAuth, 0);
  63092. ExpectIntEQ(info.eccStatic, 1);
  63093. ExpectIntEQ(info.psk, 0);
  63094. #endif
  63095. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63096. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  63097. ExpectIntEQ(info.rsaAuth, 0);
  63098. ExpectIntEQ(info.eccAuth, 1);
  63099. ExpectIntEQ(info.eccStatic, 0);
  63100. ExpectIntEQ(info.psk, 0);
  63101. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63102. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  63103. ExpectIntEQ(info.rsaAuth, 0);
  63104. ExpectIntEQ(info.eccAuth, 1);
  63105. ExpectIntEQ(info.eccStatic, 1);
  63106. ExpectIntEQ(info.psk, 0);
  63107. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  63108. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  63109. ExpectIntEQ(info.rsaAuth, 0);
  63110. ExpectIntEQ(info.eccAuth, 0);
  63111. ExpectIntEQ(info.eccStatic, 0);
  63112. ExpectIntEQ(info.psk, 1);
  63113. #endif
  63114. #endif
  63115. #ifdef WOLFSSL_TLS13
  63116. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  63117. TLS_AES_128_GCM_SHA256);
  63118. ExpectIntEQ(info.rsaAuth, 0);
  63119. ExpectIntEQ(info.eccAuth, 0);
  63120. ExpectIntEQ(info.eccStatic, 0);
  63121. ExpectIntEQ(info.psk, 0);
  63122. #endif
  63123. #endif
  63124. return EXPECT_RESULT();
  63125. }
  63126. static int test_wolfSSL_sigalg_info(void)
  63127. {
  63128. EXPECT_DECLS;
  63129. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63130. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  63131. word16 len = 0;
  63132. word16 idx = 0;
  63133. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  63134. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  63135. for (idx = 0; idx < len; idx += 2) {
  63136. int hashAlgo = 0;
  63137. int sigAlgo = 0;
  63138. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63139. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63140. ExpectIntNE(hashAlgo, 0);
  63141. ExpectIntNE(sigAlgo, 0);
  63142. }
  63143. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  63144. 0xFFFFFFFF, &len);
  63145. for (idx = 0; idx < len; idx += 2) {
  63146. int hashAlgo = 0;
  63147. int sigAlgo = 0;
  63148. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63149. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63150. ExpectIntNE(hashAlgo, 0);
  63151. }
  63152. #endif
  63153. return EXPECT_RESULT();
  63154. }
  63155. static int test_wolfSSL_SESSION(void)
  63156. {
  63157. EXPECT_DECLS;
  63158. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63159. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63160. !defined(NO_SESSION_CACHE)
  63161. WOLFSSL* ssl = NULL;
  63162. WOLFSSL_CTX* ctx = NULL;
  63163. WOLFSSL_SESSION* sess = NULL;
  63164. WOLFSSL_SESSION* sess_copy = NULL;
  63165. #ifdef OPENSSL_EXTRA
  63166. #ifdef HAVE_EXT_CACHE
  63167. unsigned char* sessDer = NULL;
  63168. unsigned char* ptr = NULL;
  63169. int sz = 0;
  63170. #endif
  63171. const unsigned char context[] = "user app context";
  63172. unsigned int contextSz = (unsigned int)sizeof(context);
  63173. #endif
  63174. int ret = 0, err = 0;
  63175. SOCKET_T sockfd;
  63176. tcp_ready ready;
  63177. func_args server_args;
  63178. THREAD_TYPE serverThread;
  63179. char msg[80];
  63180. const char* sendGET = "GET";
  63181. /* TLS v1.3 requires session tickets */
  63182. /* CHACHA and POLY1305 required for myTicketEncCb */
  63183. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  63184. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  63185. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  63186. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  63187. #else
  63188. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63189. #endif
  63190. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  63191. WOLFSSL_FILETYPE_PEM));
  63192. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  63193. WOLFSSL_FILETYPE_PEM));
  63194. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  63195. WOLFSSL_SUCCESS);
  63196. #ifdef WOLFSSL_ENCRYPTED_KEYS
  63197. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  63198. #endif
  63199. #ifdef HAVE_SESSION_TICKET
  63200. /* Use session tickets, for ticket tests below */
  63201. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  63202. #endif
  63203. XMEMSET(&server_args, 0, sizeof(func_args));
  63204. #ifdef WOLFSSL_TIRTOS
  63205. fdOpenSession(Task_self());
  63206. #endif
  63207. StartTCP();
  63208. InitTcpReady(&ready);
  63209. #if defined(USE_WINDOWS_API)
  63210. /* use RNG to get random port if using windows */
  63211. ready.port = GetRandomPort();
  63212. #endif
  63213. server_args.signal = &ready;
  63214. start_thread(test_server_nofail, &server_args, &serverThread);
  63215. wait_tcp_ready(&server_args);
  63216. /* client connection */
  63217. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63218. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  63219. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  63220. #ifdef WOLFSSL_ASYNC_CRYPT
  63221. err = 0; /* Reset error */
  63222. #endif
  63223. do {
  63224. #ifdef WOLFSSL_ASYNC_CRYPT
  63225. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63226. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63227. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63228. }
  63229. #endif
  63230. ret = wolfSSL_connect(ssl);
  63231. err = wolfSSL_get_error(ssl, 0);
  63232. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63233. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63234. #ifdef WOLFSSL_ASYNC_CRYPT
  63235. err = 0; /* Reset error */
  63236. #endif
  63237. do {
  63238. #ifdef WOLFSSL_ASYNC_CRYPT
  63239. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63240. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63241. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63242. }
  63243. #endif
  63244. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  63245. err = wolfSSL_get_error(ssl, 0);
  63246. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63247. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  63248. #ifdef WOLFSSL_ASYNC_CRYPT
  63249. err = 0; /* Reset error */
  63250. #endif
  63251. do {
  63252. #ifdef WOLFSSL_ASYNC_CRYPT
  63253. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63254. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63255. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63256. }
  63257. #endif
  63258. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  63259. err = wolfSSL_get_error(ssl, 0);
  63260. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63261. ExpectIntEQ(ret, 23);
  63262. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  63263. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  63264. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  63265. #ifdef HAVE_EXT_CACHE
  63266. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  63267. * HAVE_EXT_CACHE we get new objects each time */
  63268. #endif
  63269. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63270. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  63271. sess = wolfSSL_get_session(ssl);
  63272. #ifdef OPENSSL_EXTRA
  63273. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  63274. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  63275. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  63276. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  63277. #ifdef HAVE_SESSION_TICKET
  63278. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  63279. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  63280. SESSION_TICKET_HINT_DEFAULT);
  63281. #else
  63282. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  63283. #endif
  63284. #else
  63285. (void)sess;
  63286. #endif /* OPENSSL_EXTRA */
  63287. /* Retain copy of the session for later testing */
  63288. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  63289. wolfSSL_shutdown(ssl);
  63290. wolfSSL_free(ssl); ssl = NULL;
  63291. CloseSocket(sockfd);
  63292. join_thread(serverThread);
  63293. FreeTcpReady(&ready);
  63294. #ifdef WOLFSSL_TIRTOS
  63295. fdOpenSession(Task_self());
  63296. #endif
  63297. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  63298. {
  63299. X509 *x509 = NULL;
  63300. char buf[30];
  63301. int bufSz = 0;
  63302. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  63303. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  63304. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  63305. sizeof(buf))), 0);
  63306. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  63307. if (bufSz == 7) {
  63308. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  63309. }
  63310. if (bufSz == 16) {
  63311. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  63312. }
  63313. }
  63314. #endif
  63315. #ifdef HAVE_EXT_CACHE
  63316. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  63317. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63318. sess_copy = NULL;
  63319. #endif
  63320. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  63321. /* get session from DER and update the timeout */
  63322. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63323. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  63324. wolfSSL_SESSION_free(sess); sess = NULL;
  63325. sess = NULL;
  63326. ptr = sessDer;
  63327. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  63328. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  63329. (const unsigned char**)&ptr, sz));
  63330. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  63331. sessDer = NULL;
  63332. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  63333. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63334. #endif
  63335. /* successful set session test */
  63336. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63337. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  63338. #ifdef HAVE_SESSION_TICKET
  63339. /* Test set/get session ticket */
  63340. {
  63341. const char* ticket = "This is a session ticket";
  63342. char buf[64] = {0};
  63343. word32 bufSz = (word32)sizeof(buf);
  63344. ExpectIntEQ(SSL_SUCCESS,
  63345. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  63346. (word32)XSTRLEN(ticket)));
  63347. ExpectIntEQ(SSL_SUCCESS,
  63348. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  63349. ExpectStrEQ(ticket, buf);
  63350. }
  63351. #endif
  63352. #ifdef OPENSSL_EXTRA
  63353. /* session timeout case */
  63354. /* make the session to be expired */
  63355. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  63356. XSLEEP_MS(1200);
  63357. /* SSL_set_session should reject specified session but return success
  63358. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  63359. */
  63360. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63361. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  63362. #else
  63363. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63364. #endif
  63365. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63366. #ifdef WOLFSSL_SESSION_ID_CTX
  63367. /* fail case with miss match session context IDs (use compatibility API) */
  63368. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  63369. SSL_SUCCESS);
  63370. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63371. wolfSSL_free(ssl); ssl = NULL;
  63372. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  63373. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63374. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  63375. SSL_SUCCESS);
  63376. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63377. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63378. #endif
  63379. #endif /* OPENSSL_EXTRA */
  63380. wolfSSL_free(ssl);
  63381. wolfSSL_SESSION_free(sess);
  63382. wolfSSL_CTX_free(ctx);
  63383. #endif
  63384. return EXPECT_RESULT();
  63385. }
  63386. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63387. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63388. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63389. !defined(WOLFSSL_NO_TLS12)
  63390. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  63391. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  63392. {
  63393. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  63394. /* returns previous timeout value */
  63395. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  63396. #else
  63397. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  63398. #endif
  63399. }
  63400. /* set the session to timeout in a second */
  63401. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  63402. {
  63403. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  63404. }
  63405. /* store the client side session from the first successful connection */
  63406. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  63407. {
  63408. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  63409. NULL); /* ref count 1 */
  63410. }
  63411. /* wait till session is expired then set it in the WOLFSSL struct for use */
  63412. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  63413. {
  63414. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  63415. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63416. WOLFSSL_SUCCESS);
  63417. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  63418. }
  63419. /* set expired session in the WOLFSSL struct for use */
  63420. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  63421. {
  63422. XSLEEP_MS(1200); /* wait a second for session to expire */
  63423. /* set the expired session, call to set session fails but continuing on
  63424. after failure should be handled here */
  63425. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63426. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63427. WOLFSSL_SUCCESS);
  63428. #else
  63429. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63430. WOLFSSL_SUCCESS);
  63431. #endif
  63432. }
  63433. /* check that the expired session was not reused */
  63434. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  63435. {
  63436. /* since the session has expired it should not have been reused */
  63437. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  63438. }
  63439. #endif
  63440. static int test_wolfSSL_SESSION_expire_downgrade(void)
  63441. {
  63442. EXPECT_DECLS;
  63443. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63444. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63445. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63446. !defined(WOLFSSL_NO_TLS12)
  63447. WOLFSSL_CTX* ctx = NULL;
  63448. callback_functions server_cbf, client_cbf;
  63449. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  63450. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  63451. /* force server side to use TLS 1.2 */
  63452. server_cbf.ctx = ctx;
  63453. server_cbf.method = wolfTLSv1_2_server_method;
  63454. client_cbf.method = wolfSSLv23_client_method;
  63455. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63456. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  63457. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  63458. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63459. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63460. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63461. /* set the previously created session and wait till expired */
  63462. server_cbf.ctx = ctx;
  63463. client_cbf.method = wolfSSLv23_client_method;
  63464. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63465. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  63466. client_cbf.on_result =
  63467. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63468. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63469. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63470. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63471. /* set the previously created expired session */
  63472. server_cbf.ctx = ctx;
  63473. client_cbf.method = wolfSSLv23_client_method;
  63474. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63475. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  63476. client_cbf.on_result =
  63477. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63478. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63479. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63480. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63481. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  63482. wolfSSL_CTX_free(ctx);
  63483. #endif
  63484. return EXPECT_RESULT();
  63485. }
  63486. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63487. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63488. #ifdef WOLFSSL_ATOMIC_OPS
  63489. typedef wolfSSL_Atomic_Int SessRemCounter_t;
  63490. #else
  63491. typedef int SessRemCounter_t;
  63492. #endif
  63493. static SessRemCounter_t clientSessRemCountMalloc;
  63494. static SessRemCounter_t serverSessRemCountMalloc;
  63495. static SessRemCounter_t clientSessRemCountFree;
  63496. static SessRemCounter_t serverSessRemCountFree;
  63497. static WOLFSSL_CTX* serverSessCtx = NULL;
  63498. static WOLFSSL_SESSION* serverSess = NULL;
  63499. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63500. !defined(NO_SESSION_CACHE_REF)
  63501. static WOLFSSL_CTX* clientSessCtx = NULL;
  63502. static WOLFSSL_SESSION* clientSess = NULL;
  63503. #endif
  63504. static int serverSessRemIdx = 3;
  63505. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  63506. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  63507. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  63508. {
  63509. int* side;
  63510. (void)ctx;
  63511. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  63512. if (side != NULL) {
  63513. if (*side == WOLFSSL_CLIENT_END)
  63514. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1);
  63515. else
  63516. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1);
  63517. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  63518. }
  63519. }
  63520. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  63521. {
  63522. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  63523. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  63524. !defined(NO_SESSION_CACHE_REF)
  63525. {
  63526. EXPECT_DECLS;
  63527. /* Allow downgrade, set min version, and disable TLS 1.3.
  63528. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  63529. * reference to the session cache. But with WOLFSSL_TLS13 and without
  63530. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  63531. * the session in the cache. In this case we need to downgrade to
  63532. * previous versions to just use the legacy session ID field. */
  63533. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  63534. SSL_SUCCESS);
  63535. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  63536. SSL_SUCCESS);
  63537. return EXPECT_RESULT();
  63538. }
  63539. #else
  63540. return TEST_SUCCESS;
  63541. #endif
  63542. }
  63543. static int SessRemSslSetupCb(WOLFSSL* ssl)
  63544. {
  63545. EXPECT_DECLS;
  63546. int* side;
  63547. if (SSL_is_server(ssl)) {
  63548. side = &sessRemCtx_Server;
  63549. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1);
  63550. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  63551. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  63552. SSL_SUCCESS);
  63553. }
  63554. else {
  63555. side = &sessRemCtx_Client;
  63556. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1);
  63557. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63558. !defined(NO_SESSION_CACHE_REF)
  63559. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  63560. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  63561. SSL_SUCCESS);
  63562. #endif
  63563. }
  63564. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  63565. serverSessRemIdx, side), SSL_SUCCESS);
  63566. return EXPECT_RESULT();
  63567. }
  63568. #endif
  63569. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  63570. {
  63571. EXPECT_DECLS;
  63572. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63573. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63574. /* Check that the remove callback gets called for external data in a
  63575. * session object */
  63576. test_ssl_cbf func_cb;
  63577. wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0);
  63578. wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0);
  63579. wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0);
  63580. wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0);
  63581. XMEMSET(&func_cb, 0, sizeof(func_cb));
  63582. func_cb.ctx_ready = SessRemCtxSetupCb;
  63583. func_cb.on_result = SessRemSslSetupCb;
  63584. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  63585. NULL), TEST_SUCCESS);
  63586. /* Both should have been allocated */
  63587. ExpectIntEQ(clientSessRemCountMalloc, 1);
  63588. ExpectIntEQ(serverSessRemCountMalloc, 1);
  63589. /* This should not be called yet. Session wasn't evicted from cache yet. */
  63590. ExpectIntEQ(clientSessRemCountFree, 0);
  63591. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63592. !defined(NO_SESSION_CACHE_REF)
  63593. /* Force a cache lookup */
  63594. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63595. /* Force a cache update */
  63596. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  63597. /* This should set the timeout to 0 and call the remove callback from within
  63598. * the session cache. */
  63599. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  63600. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63601. ExpectIntEQ(clientSessRemCountFree, 1);
  63602. #endif
  63603. /* Server session is in the cache so ex_data isn't free'd with the SSL
  63604. * object */
  63605. ExpectIntEQ(serverSessRemCountFree, 0);
  63606. /* Force a cache lookup */
  63607. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63608. /* Force a cache update */
  63609. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  63610. /* This should set the timeout to 0 and call the remove callback from within
  63611. * the session cache. */
  63612. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  63613. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63614. ExpectIntEQ(serverSessRemCountFree, 1);
  63615. /* Need to free the references that we kept */
  63616. SSL_CTX_free(serverSessCtx);
  63617. SSL_SESSION_free(serverSess);
  63618. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63619. !defined(NO_SESSION_CACHE_REF)
  63620. SSL_CTX_free(clientSessCtx);
  63621. SSL_SESSION_free(clientSess);
  63622. #endif
  63623. #endif
  63624. return EXPECT_RESULT();
  63625. }
  63626. static int test_wolfSSL_ticket_keys(void)
  63627. {
  63628. EXPECT_DECLS;
  63629. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  63630. !defined(NO_WOLFSSL_SERVER)
  63631. WOLFSSL_CTX* ctx = NULL;
  63632. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  63633. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  63634. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  63635. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63636. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  63637. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63638. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  63639. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63640. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  63641. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63642. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63643. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63644. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63645. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63646. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63647. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63648. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  63649. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63650. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  63651. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63652. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  63653. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63654. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  63655. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63656. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63657. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63658. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63659. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63660. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63661. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63662. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63663. WOLFSSL_SUCCESS);
  63664. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63665. WOLFSSL_SUCCESS);
  63666. wolfSSL_CTX_free(ctx);
  63667. #endif
  63668. return EXPECT_RESULT();
  63669. }
  63670. #ifndef NO_BIO
  63671. static int test_wolfSSL_d2i_PUBKEY(void)
  63672. {
  63673. EXPECT_DECLS;
  63674. #if defined(OPENSSL_EXTRA)
  63675. BIO* bio = NULL;
  63676. EVP_PKEY* pkey = NULL;
  63677. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63678. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  63679. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  63680. /* RSA PUBKEY test */
  63681. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  63682. sizeof_client_keypub_der_2048), 0);
  63683. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63684. EVP_PKEY_free(pkey);
  63685. pkey = NULL;
  63686. #endif
  63687. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  63688. /* ECC PUBKEY test */
  63689. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  63690. sizeof_ecc_clikeypub_der_256), 0);
  63691. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63692. EVP_PKEY_free(pkey);
  63693. pkey = NULL;
  63694. #endif
  63695. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  63696. /* DSA PUBKEY test */
  63697. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  63698. sizeof_dsa_pub_key_der_2048), 0);
  63699. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63700. EVP_PKEY_free(pkey);
  63701. pkey = NULL;
  63702. #endif
  63703. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  63704. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  63705. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  63706. (HAVE_FIPS_VERSION > 2))
  63707. /* DH PUBKEY test */
  63708. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  63709. sizeof_dh_pub_key_der_2048), 0);
  63710. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63711. EVP_PKEY_free(pkey);
  63712. pkey = NULL;
  63713. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  63714. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  63715. BIO_free(bio);
  63716. (void)pkey;
  63717. #endif
  63718. return EXPECT_RESULT();
  63719. }
  63720. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  63721. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  63722. {
  63723. EXPECT_DECLS;
  63724. BIO* bio = NULL;
  63725. EVP_PKEY* pkey = NULL;
  63726. WOLFSSL_CTX* ctx = NULL;
  63727. #if defined(WOLFSSL_KEY_GEN)
  63728. unsigned char buff[4096];
  63729. unsigned char* bufPtr = buff;
  63730. #endif
  63731. /* test creating new EVP_PKEY with bad arg */
  63732. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  63733. /* test loading RSA key using BIO */
  63734. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  63735. {
  63736. XFILE file = XBADFILE;
  63737. const char* fname = "./certs/server-key.der";
  63738. size_t sz = 0;
  63739. byte* buf = NULL;
  63740. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63741. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63742. ExpectTrue((sz = XFTELL(file)) != 0);
  63743. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63744. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63745. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63746. if (file != XBADFILE) {
  63747. XFCLOSE(file);
  63748. }
  63749. /* Test using BIO new mem and loading DER private key */
  63750. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63751. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63752. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63753. BIO_free(bio);
  63754. bio = NULL;
  63755. EVP_PKEY_free(pkey);
  63756. pkey = NULL;
  63757. }
  63758. #endif
  63759. /* test loading ECC key using BIO */
  63760. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  63761. {
  63762. XFILE file = XBADFILE;
  63763. const char* fname = "./certs/ecc-key.der";
  63764. size_t sz = 0;
  63765. byte* buf = NULL;
  63766. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63767. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63768. ExpectTrue((sz = XFTELL(file)) != 0);
  63769. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63770. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63771. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63772. if (file != XBADFILE)
  63773. XFCLOSE(file);
  63774. /* Test using BIO new mem and loading DER private key */
  63775. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63776. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63777. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63778. BIO_free(bio);
  63779. bio = NULL;
  63780. EVP_PKEY_free(pkey);
  63781. pkey = NULL;
  63782. }
  63783. #endif
  63784. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63785. #ifndef NO_WOLFSSL_SERVER
  63786. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  63787. #else
  63788. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  63789. #endif
  63790. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  63791. {
  63792. RSA* rsa = NULL;
  63793. /* Tests bad parameters */
  63794. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  63795. /* RSA not set yet, expecting to fail*/
  63796. rsa = wolfSSL_RSA_new();
  63797. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63798. wolfSSL_RSA_free(rsa);
  63799. rsa = NULL;
  63800. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  63801. /* set RSA using bio*/
  63802. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63803. sizeof_client_key_der_2048), 0);
  63804. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  63805. ExpectNotNull(rsa);
  63806. /* Tests bad parameters */
  63807. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63808. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63809. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63810. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  63811. /* i2d RSAprivate key tests */
  63812. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63813. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  63814. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63815. sizeof_client_key_der_2048);
  63816. bufPtr -= sizeof_client_key_der_2048;
  63817. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63818. sizeof_client_key_der_2048), 0);
  63819. bufPtr = NULL;
  63820. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63821. sizeof_client_key_der_2048);
  63822. ExpectNotNull(bufPtr);
  63823. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63824. sizeof_client_key_der_2048), 0);
  63825. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  63826. RSA_free(rsa);
  63827. rsa = NULL;
  63828. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63829. sizeof_client_key_der_2048), 0);
  63830. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  63831. (void)BIO_reset(bio);
  63832. RSA_free(rsa);
  63833. rsa = RSA_new();
  63834. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  63835. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  63836. RSA_free(rsa);
  63837. }
  63838. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  63839. SSL_CTX_free(ctx);
  63840. ctx = NULL;
  63841. BIO_free(bio);
  63842. bio = NULL;
  63843. return EXPECT_RESULT();
  63844. }
  63845. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  63846. #endif /* !NO_BIO */
  63847. static int test_wolfSSL_sk_GENERAL_NAME(void)
  63848. {
  63849. EXPECT_DECLS;
  63850. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63851. !defined(NO_RSA)
  63852. X509* x509 = NULL;
  63853. GENERAL_NAME* gn = NULL;
  63854. unsigned char buf[4096];
  63855. const unsigned char* bufPt = NULL;
  63856. int bytes = 0;
  63857. int i;
  63858. int j;
  63859. XFILE f = XBADFILE;
  63860. STACK_OF(GENERAL_NAME)* sk = NULL;
  63861. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63862. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63863. if (f != XBADFILE)
  63864. XFCLOSE(f);
  63865. for (j = 0; j < 2; ++j) {
  63866. bufPt = buf;
  63867. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63868. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63869. NID_subject_alt_name, NULL, NULL));
  63870. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  63871. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  63872. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  63873. if (gn != NULL) {
  63874. switch (gn->type) {
  63875. case GEN_DNS:
  63876. fprintf(stderr, "found type GEN_DNS\n");
  63877. break;
  63878. case GEN_EMAIL:
  63879. fprintf(stderr, "found type GEN_EMAIL\n");
  63880. break;
  63881. case GEN_URI:
  63882. fprintf(stderr, "found type GEN_URI\n");
  63883. break;
  63884. }
  63885. }
  63886. }
  63887. X509_free(x509);
  63888. x509 = NULL;
  63889. if (j == 0) {
  63890. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63891. }
  63892. else {
  63893. /*
  63894. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  63895. * it was supposed to. This is a regression test for that bug.
  63896. */
  63897. GENERAL_NAMES_free(sk);
  63898. }
  63899. sk = NULL;
  63900. }
  63901. #endif
  63902. return EXPECT_RESULT();
  63903. }
  63904. static int test_wolfSSL_GENERAL_NAME_print(void)
  63905. {
  63906. EXPECT_DECLS;
  63907. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  63908. X509* x509 = NULL;
  63909. GENERAL_NAME* gn = NULL;
  63910. unsigned char buf[4096];
  63911. const unsigned char* bufPt = NULL;
  63912. int bytes = 0;
  63913. XFILE f = XBADFILE;
  63914. STACK_OF(GENERAL_NAME)* sk = NULL;
  63915. BIO* out = NULL;
  63916. unsigned char outbuf[128];
  63917. X509_EXTENSION* ext = NULL;
  63918. AUTHORITY_INFO_ACCESS* aia = NULL;
  63919. ACCESS_DESCRIPTION* ad = NULL;
  63920. ASN1_IA5STRING *dnsname = NULL;
  63921. const unsigned char v4Addr[] = {192,168,53,1};
  63922. const unsigned char v6Addr[] =
  63923. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  63924. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  63925. const unsigned char email[] =
  63926. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  63927. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  63928. const char* dnsStr = "DNS:example.com";
  63929. const char* uriStr = "URI:http://127.0.0.1:22220";
  63930. const char* v4addStr = "IP Address:192.168.53.1";
  63931. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  63932. const char* emailStr = "email:info@wolfssl.com";
  63933. const char* othrStr = "othername:<unsupported>";
  63934. const char* x400Str = "X400Name:<unsupported>";
  63935. const char* ediStr = "EdiPartyName:<unsupported>";
  63936. /* BIO to output */
  63937. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  63938. /* test for NULL param */
  63939. gn = NULL;
  63940. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  63941. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  63942. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  63943. /* test for GEN_DNS */
  63944. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63945. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63946. if (f != XBADFILE) {
  63947. XFCLOSE(f);
  63948. f = XBADFILE;
  63949. }
  63950. bufPt = buf;
  63951. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63952. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63953. NID_subject_alt_name, NULL, NULL));
  63954. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  63955. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63956. XMEMSET(outbuf, 0, sizeof(outbuf));
  63957. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63958. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63959. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63960. gn = NULL;
  63961. sk = NULL;
  63962. X509_free(x509);
  63963. x509 = NULL;
  63964. /* Lets test for setting as well. */
  63965. ExpectNotNull(gn = GENERAL_NAME_new());
  63966. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  63967. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  63968. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  63969. dnsname = NULL;
  63970. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63971. XMEMSET(outbuf, 0, sizeof(outbuf));
  63972. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63973. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63974. GENERAL_NAME_free(gn);
  63975. /* test for GEN_URI */
  63976. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  63977. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  63978. if (f != XBADFILE) {
  63979. XFCLOSE(f);
  63980. f = XBADFILE;
  63981. }
  63982. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  63983. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  63984. ext));
  63985. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  63986. if (ad != NULL) {
  63987. gn = ad->location;
  63988. }
  63989. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63990. gn = NULL;
  63991. XMEMSET(outbuf,0,sizeof(outbuf));
  63992. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63993. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  63994. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  63995. aia = NULL;
  63996. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  63997. ExpectNotNull(aia);
  63998. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  63999. aia = NULL;
  64000. X509_free(x509);
  64001. x509 = NULL;
  64002. /* test for GEN_IPADD */
  64003. /* ip v4 address */
  64004. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64005. if (gn != NULL) {
  64006. gn->type = GEN_IPADD;
  64007. if (gn->d.iPAddress != NULL) {
  64008. gn->d.iPAddress->length = sizeof(v4Addr);
  64009. }
  64010. }
  64011. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  64012. sizeof(v4Addr)), 1);
  64013. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64014. XMEMSET(outbuf,0,sizeof(outbuf));
  64015. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64016. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  64017. GENERAL_NAME_free(gn);
  64018. gn = NULL;
  64019. /* ip v6 address */
  64020. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64021. if (gn != NULL) {
  64022. gn->type = GEN_IPADD;
  64023. if (gn->d.iPAddress != NULL) {
  64024. gn->d.iPAddress->length = sizeof(v6Addr);
  64025. }
  64026. }
  64027. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  64028. sizeof(v6Addr)), 1);
  64029. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64030. XMEMSET(outbuf,0,sizeof(outbuf));
  64031. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64032. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  64033. GENERAL_NAME_free(gn);
  64034. gn = NULL;
  64035. /* test for GEN_EMAIL */
  64036. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64037. if (gn != NULL) {
  64038. gn->type = GEN_EMAIL;
  64039. if (gn->d.rfc822Name != NULL) {
  64040. gn->d.rfc822Name->length = sizeof(email);
  64041. }
  64042. }
  64043. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  64044. 1);
  64045. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64046. XMEMSET(outbuf,0,sizeof(outbuf));
  64047. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64048. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  64049. GENERAL_NAME_free(gn);
  64050. gn = NULL;
  64051. /* test for GEN_OTHERNAME */
  64052. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64053. if (gn != NULL) {
  64054. gn->type = GEN_OTHERNAME;
  64055. }
  64056. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64057. XMEMSET(outbuf,0,sizeof(outbuf));
  64058. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64059. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  64060. GENERAL_NAME_free(gn);
  64061. gn = NULL;
  64062. /* test for GEN_X400 */
  64063. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64064. if (gn != NULL) {
  64065. gn->type = GEN_X400;
  64066. }
  64067. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64068. XMEMSET(outbuf,0,sizeof(outbuf));
  64069. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64070. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  64071. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64072. if (gn != NULL) {
  64073. gn->type = GEN_IA5;
  64074. }
  64075. GENERAL_NAME_free(gn);
  64076. gn = NULL;
  64077. /* test for GEN_EDIPARTY */
  64078. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64079. if (gn != NULL) {
  64080. gn->type = GEN_EDIPARTY;
  64081. }
  64082. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64083. XMEMSET(outbuf,0,sizeof(outbuf));
  64084. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64085. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  64086. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64087. if (gn != NULL) {
  64088. gn->type = GEN_IA5;
  64089. }
  64090. GENERAL_NAME_free(gn);
  64091. gn = NULL;
  64092. BIO_free(out);
  64093. #endif /* OPENSSL_ALL */
  64094. return EXPECT_RESULT();
  64095. }
  64096. static int test_wolfSSL_sk_DIST_POINT(void)
  64097. {
  64098. EXPECT_DECLS;
  64099. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64100. !defined(NO_RSA)
  64101. X509* x509 = NULL;
  64102. unsigned char buf[4096];
  64103. const unsigned char* bufPt;
  64104. int bytes = 0;
  64105. int i = 0;
  64106. int j = 0;
  64107. XFILE f = XBADFILE;
  64108. DIST_POINT* dp = NULL;
  64109. DIST_POINT_NAME* dpn = NULL;
  64110. GENERAL_NAME* gn = NULL;
  64111. ASN1_IA5STRING* uri = NULL;
  64112. STACK_OF(DIST_POINT)* dps = NULL;
  64113. STACK_OF(GENERAL_NAME)* gns = NULL;
  64114. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  64115. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  64116. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64117. if (f != XBADFILE)
  64118. XFCLOSE(f);
  64119. bufPt = buf;
  64120. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64121. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  64122. NID_crl_distribution_points, NULL, NULL));
  64123. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  64124. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  64125. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  64126. ExpectNotNull(dpn = dp->distpoint);
  64127. /* this should be type 0, fullname */
  64128. ExpectIntEQ(dpn->type, 0);
  64129. ExpectNotNull(gns = dp->distpoint->name.fullname);
  64130. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  64131. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  64132. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  64133. ExpectIntEQ(gn->type, GEN_URI);
  64134. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  64135. ExpectNotNull(uri->data);
  64136. ExpectIntGT(uri->length, 0);
  64137. }
  64138. }
  64139. X509_free(x509);
  64140. CRL_DIST_POINTS_free(dps);
  64141. #endif
  64142. return EXPECT_RESULT();
  64143. }
  64144. static int test_wolfSSL_verify_mode(void)
  64145. {
  64146. EXPECT_DECLS;
  64147. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  64148. WOLFSSL* ssl = NULL;
  64149. WOLFSSL_CTX* ctx = NULL;
  64150. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64151. ExpectNotNull(ssl = SSL_new(ctx));
  64152. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64153. SSL_free(ssl);
  64154. ssl = NULL;
  64155. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64156. ExpectNotNull(ssl = SSL_new(ctx));
  64157. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64158. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64159. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64160. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  64161. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64162. SSL_free(ssl);
  64163. ssl = NULL;
  64164. wolfSSL_CTX_set_verify(ctx,
  64165. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64166. ExpectNotNull(ssl = SSL_new(ctx));
  64167. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64168. ExpectIntEQ(SSL_get_verify_mode(ssl),
  64169. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64170. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  64171. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64172. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64173. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64174. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64175. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64176. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64177. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64178. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  64179. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  64180. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  64181. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  64182. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  64183. #endif
  64184. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64185. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64186. SSL_free(ssl);
  64187. SSL_CTX_free(ctx);
  64188. #endif
  64189. return EXPECT_RESULT();
  64190. }
  64191. static int test_wolfSSL_verify_depth(void)
  64192. {
  64193. EXPECT_DECLS;
  64194. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64195. WOLFSSL* ssl = NULL;
  64196. WOLFSSL_CTX* ctx = NULL;
  64197. long depth = 0;
  64198. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64199. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  64200. ExpectNotNull(ssl = SSL_new(ctx));
  64201. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  64202. SSL_free(ssl);
  64203. ssl = NULL;
  64204. SSL_CTX_set_verify_depth(ctx, -1);
  64205. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  64206. SSL_CTX_set_verify_depth(ctx, 2);
  64207. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  64208. ExpectNotNull(ssl = SSL_new(ctx));
  64209. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  64210. SSL_free(ssl);
  64211. SSL_CTX_free(ctx);
  64212. #endif
  64213. return EXPECT_RESULT();
  64214. }
  64215. static int test_wolfSSL_verify_result(void)
  64216. {
  64217. EXPECT_DECLS;
  64218. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  64219. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  64220. WOLFSSL* ssl = NULL;
  64221. WOLFSSL_CTX* ctx = NULL;
  64222. long result = 0xDEADBEEF;
  64223. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  64224. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64225. ExpectNotNull(ssl = SSL_new(ctx));
  64226. wolfSSL_set_verify_result(ssl, result);
  64227. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  64228. SSL_free(ssl);
  64229. SSL_CTX_free(ctx);
  64230. #endif
  64231. return EXPECT_RESULT();
  64232. }
  64233. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64234. static void sslMsgCb(int w, int version, int type, const void* buf,
  64235. size_t sz, SSL* ssl, void* arg)
  64236. {
  64237. int i;
  64238. unsigned char* pt = (unsigned char*)buf;
  64239. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  64240. (w)?"Writing":"Reading", (int)sz, version, type);
  64241. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  64242. fprintf(stderr, "\n");
  64243. (void)ssl;
  64244. (void)arg;
  64245. }
  64246. #endif /* OPENSSL_EXTRA */
  64247. static int test_wolfSSL_msg_callback(void)
  64248. {
  64249. EXPECT_DECLS;
  64250. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64251. WOLFSSL* ssl = NULL;
  64252. WOLFSSL_CTX* ctx = NULL;
  64253. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64254. ExpectNotNull(ssl = SSL_new(ctx));
  64255. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  64256. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  64257. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64258. SSL_free(ssl);
  64259. SSL_CTX_free(ctx);
  64260. #endif
  64261. return EXPECT_RESULT();
  64262. }
  64263. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  64264. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  64265. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  64266. static void binary_dump(void *ptr, int size)
  64267. {
  64268. #ifdef WOLFSSL_EVP_PRINT
  64269. int i = 0;
  64270. unsigned char *p = (unsigned char *) ptr;
  64271. fprintf(stderr, "{");
  64272. while ((p != NULL) && (i < size)) {
  64273. if ((i % 8) == 0) {
  64274. fprintf(stderr, "\n");
  64275. fprintf(stderr, " ");
  64276. }
  64277. fprintf(stderr, "0x%02x, ", p[i]);
  64278. i++;
  64279. }
  64280. fprintf(stderr, "\n};\n");
  64281. #else
  64282. (void) ptr;
  64283. (void) size;
  64284. #endif
  64285. }
  64286. static int last_val = 0x0f;
  64287. static int check_result(unsigned char *data, int len)
  64288. {
  64289. int i;
  64290. for ( ; len; ) {
  64291. last_val = (last_val + 1) % 16;
  64292. for (i = 0; i < 16; len--, i++, data++)
  64293. if (*data != last_val) {
  64294. return -1;
  64295. }
  64296. }
  64297. return 0;
  64298. }
  64299. static int r_offset;
  64300. static int w_offset;
  64301. static void init_offset(void)
  64302. {
  64303. r_offset = 0;
  64304. w_offset = 0;
  64305. }
  64306. static void get_record(unsigned char *data, unsigned char *buf, int len)
  64307. {
  64308. XMEMCPY(buf, data+r_offset, len);
  64309. r_offset += len;
  64310. }
  64311. static void set_record(unsigned char *data, unsigned char *buf, int len)
  64312. {
  64313. XMEMCPY(data+w_offset, buf, len);
  64314. w_offset += len;
  64315. }
  64316. static void set_plain(unsigned char *plain, int rec)
  64317. {
  64318. int i, j;
  64319. unsigned char *p = plain;
  64320. #define BLOCKSZ 16
  64321. for (i=0; i<(rec/BLOCKSZ); i++) {
  64322. for (j=0; j<BLOCKSZ; j++)
  64323. *p++ = (i % 16);
  64324. }
  64325. }
  64326. #endif
  64327. static int test_wolfSSL_EVP_Cipher_extra(void)
  64328. {
  64329. EXPECT_DECLS;
  64330. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  64331. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  64332. /* aes128-cbc, keylen=16, ivlen=16 */
  64333. byte aes128_cbc_key[] = {
  64334. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64335. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64336. };
  64337. byte aes128_cbc_iv[] = {
  64338. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  64339. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  64340. };
  64341. /* teset data size table */
  64342. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  64343. int test_drive2[] = {8, 3, 8, 512, 0};
  64344. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  64345. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  64346. int test_drive_len[100];
  64347. int ret = 0;
  64348. EVP_CIPHER_CTX *evp = NULL;
  64349. int ilen = 0;
  64350. int klen = 0;
  64351. int i, j;
  64352. const EVP_CIPHER *type;
  64353. byte *iv;
  64354. byte *key;
  64355. int ivlen;
  64356. int keylen;
  64357. #define RECORDS 16
  64358. #define BUFFSZ 512
  64359. byte plain [BUFFSZ * RECORDS];
  64360. byte cipher[BUFFSZ * RECORDS];
  64361. byte inb[BUFFSZ];
  64362. byte outb[BUFFSZ+16];
  64363. int outl = 0;
  64364. int inl;
  64365. iv = aes128_cbc_iv;
  64366. ivlen = sizeof(aes128_cbc_iv);
  64367. key = aes128_cbc_key;
  64368. keylen = sizeof(aes128_cbc_key);
  64369. type = EVP_aes_128_cbc();
  64370. set_plain(plain, BUFFSZ * RECORDS);
  64371. SSL_library_init();
  64372. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64373. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64374. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64375. klen = EVP_CIPHER_CTX_key_length(evp);
  64376. if (klen > 0 && keylen != klen) {
  64377. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64378. }
  64379. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64380. if (ilen > 0 && ivlen != ilen) {
  64381. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64382. }
  64383. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64384. for (j = 0; j<RECORDS; j++)
  64385. {
  64386. inl = BUFFSZ;
  64387. get_record(plain, inb, inl);
  64388. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  64389. set_record(cipher, outb, outl);
  64390. }
  64391. for (i = 0; test_drive[i]; i++) {
  64392. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64393. init_offset();
  64394. test_drive_len[i] = 0;
  64395. for (j = 0; test_drive[i][j]; j++)
  64396. {
  64397. inl = test_drive[i][j];
  64398. test_drive_len[i] += inl;
  64399. get_record(plain, inb, inl);
  64400. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  64401. 0);
  64402. /* output to cipher buffer, so that following Dec test can detect
  64403. if any error */
  64404. set_record(cipher, outb, outl);
  64405. }
  64406. EVP_CipherFinal(evp, outb, &outl);
  64407. if (outl > 0)
  64408. set_record(cipher, outb, outl);
  64409. }
  64410. for (i = 0; test_drive[i]; i++) {
  64411. last_val = 0x0f;
  64412. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  64413. init_offset();
  64414. for (j = 0; test_drive[i][j]; j++) {
  64415. inl = test_drive[i][j];
  64416. get_record(cipher, inb, inl);
  64417. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  64418. 0);
  64419. binary_dump(outb, outl);
  64420. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  64421. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  64422. }
  64423. ret = EVP_CipherFinal(evp, outb, &outl);
  64424. binary_dump(outb, outl);
  64425. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  64426. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  64427. ExpectTrue(ret);
  64428. }
  64429. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  64430. EVP_CIPHER_CTX_free(evp);
  64431. evp = NULL;
  64432. /* Do an extra test to verify correct behavior with empty input. */
  64433. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64434. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64435. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64436. klen = EVP_CIPHER_CTX_key_length(evp);
  64437. if (klen > 0 && keylen != klen) {
  64438. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64439. }
  64440. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64441. if (ilen > 0 && ivlen != ilen) {
  64442. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64443. }
  64444. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64445. /* outl should be set to 0 after passing NULL, 0 for input args. */
  64446. outl = -1;
  64447. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  64448. ExpectIntEQ(outl, 0);
  64449. EVP_CIPHER_CTX_free(evp);
  64450. #endif /* test_EVP_Cipher */
  64451. return EXPECT_RESULT();
  64452. }
  64453. static int test_wolfSSL_PEM_read_DHparams(void)
  64454. {
  64455. EXPECT_DECLS;
  64456. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  64457. !defined(NO_FILESYSTEM)
  64458. DH* dh = NULL;
  64459. XFILE fp = XBADFILE;
  64460. unsigned char derOut[300];
  64461. unsigned char* derOutBuf = derOut;
  64462. int derOutSz = 0;
  64463. unsigned char derExpected[300];
  64464. int derExpectedSz = 0;
  64465. XMEMSET(derOut, 0, sizeof(derOut));
  64466. XMEMSET(derExpected, 0, sizeof(derExpected));
  64467. /* open DH param file, read into DH struct */
  64468. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  64469. /* bad args */
  64470. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  64471. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  64472. /* good args */
  64473. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64474. if (fp != XBADFILE) {
  64475. XFCLOSE(fp);
  64476. fp = XBADFILE;
  64477. }
  64478. /* read in certs/dh2048.der for comparison against exported params */
  64479. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  64480. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  64481. fp), 0);
  64482. if (fp != XBADFILE) {
  64483. XFCLOSE(fp);
  64484. fp = XBADFILE;
  64485. }
  64486. /* export DH back to DER and compare */
  64487. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  64488. ExpectIntEQ(derOutSz, derExpectedSz);
  64489. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  64490. DH_free(dh);
  64491. dh = NULL;
  64492. /* Test parsing with X9.42 header */
  64493. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  64494. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64495. if (fp != XBADFILE)
  64496. XFCLOSE(fp);
  64497. DH_free(dh);
  64498. dh = NULL;
  64499. #endif
  64500. return EXPECT_RESULT();
  64501. }
  64502. static int test_wolfSSL_X509_get_serialNumber(void)
  64503. {
  64504. EXPECT_DECLS;
  64505. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  64506. ASN1_INTEGER* a = NULL;
  64507. BIGNUM* bn = NULL;
  64508. X509* x509 = NULL;
  64509. char *serialHex = NULL;
  64510. byte serial[3];
  64511. int serialSz;
  64512. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64513. SSL_FILETYPE_PEM));
  64514. ExpectNotNull(a = X509_get_serialNumber(x509));
  64515. /* check on value of ASN1 Integer */
  64516. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  64517. a = NULL;
  64518. /* test setting serial number and then retrieving it */
  64519. ExpectNotNull(a = ASN1_INTEGER_new());
  64520. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  64521. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64522. serialSz = sizeof(serial);
  64523. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64524. WOLFSSL_SUCCESS);
  64525. ExpectIntEQ(serialSz, 1);
  64526. ExpectIntEQ(serial[0], 3);
  64527. ASN1_INTEGER_free(a);
  64528. a = NULL;
  64529. /* test setting serial number with 0's in it */
  64530. serial[0] = 0x01;
  64531. serial[1] = 0x00;
  64532. serial[2] = 0x02;
  64533. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  64534. if (a != NULL) {
  64535. a->data[0] = ASN_INTEGER;
  64536. a->data[1] = sizeof(serial);
  64537. XMEMCPY(&a->data[2], serial, sizeof(serial));
  64538. a->length = sizeof(serial) + 2;
  64539. }
  64540. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64541. XMEMSET(serial, 0, sizeof(serial));
  64542. serialSz = sizeof(serial);
  64543. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64544. WOLFSSL_SUCCESS);
  64545. ExpectIntEQ(serialSz, 3);
  64546. ExpectIntEQ(serial[0], 0x01);
  64547. ExpectIntEQ(serial[1], 0x00);
  64548. ExpectIntEQ(serial[2], 0x02);
  64549. ASN1_INTEGER_free(a);
  64550. a = NULL;
  64551. X509_free(x509); /* free's a */
  64552. ExpectNotNull(serialHex = BN_bn2hex(bn));
  64553. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  64554. ExpectStrEQ(serialHex, "01");
  64555. #else
  64556. ExpectStrEQ(serialHex, "1");
  64557. #endif
  64558. OPENSSL_free(serialHex);
  64559. ExpectIntEQ(BN_get_word(bn), 1);
  64560. BN_free(bn);
  64561. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  64562. ExpectNotNull(a = ASN1_INTEGER_new());
  64563. if (a != NULL) {
  64564. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  64565. DYNAMIC_TYPE_OPENSSL));
  64566. a->isDynamic = 1;
  64567. ASN1_INTEGER_free(a);
  64568. }
  64569. #endif
  64570. return EXPECT_RESULT();
  64571. }
  64572. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  64573. {
  64574. EXPECT_DECLS;
  64575. #if defined(OPENSSL_EXTRA)
  64576. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  64577. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  64578. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  64579. #endif
  64580. return EXPECT_RESULT();
  64581. }
  64582. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  64583. {
  64584. EXPECT_DECLS;
  64585. #if defined(OPENSSL_EXTRA)
  64586. #define MAX_HEXSTR_BUFSZ 9
  64587. #define NUM_CASES 5
  64588. struct Output {
  64589. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  64590. long ret;
  64591. };
  64592. int i;
  64593. int j;
  64594. const char* inputs[NUM_CASES] = {
  64595. "aabcd1357e",
  64596. "01:12:23:34:a5:b6:c7:d8:e9",
  64597. ":01:02",
  64598. "012",
  64599. ":ab:ac:d"
  64600. };
  64601. struct Output expectedOutputs[NUM_CASES] = {
  64602. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  64603. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  64604. {{0x01, 0x02}, 2},
  64605. {{0x00}, 0},
  64606. {{0x00}, 0}
  64607. };
  64608. long len = 0;
  64609. unsigned char* returnedBuf = NULL;
  64610. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  64611. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  64612. if (returnedBuf == NULL) {
  64613. ExpectIntEQ(expectedOutputs[i].ret, 0);
  64614. continue;
  64615. }
  64616. ExpectIntEQ(expectedOutputs[i].ret, len);
  64617. for (j = 0; j < len; ++j) {
  64618. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  64619. }
  64620. OPENSSL_free(returnedBuf);
  64621. returnedBuf = NULL;
  64622. }
  64623. #endif
  64624. return EXPECT_RESULT();
  64625. }
  64626. static int test_wolfSSL_X509_CA_num(void)
  64627. {
  64628. EXPECT_DECLS;
  64629. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  64630. defined(HAVE_ECC) && !defined(NO_RSA)
  64631. WOLFSSL_X509_STORE *store = NULL;
  64632. WOLFSSL_X509 *x509_1 = NULL;
  64633. WOLFSSL_X509 *x509_2 = NULL;
  64634. int ca_num = 0;
  64635. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  64636. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64637. WOLFSSL_FILETYPE_PEM));
  64638. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  64639. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  64640. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  64641. WOLFSSL_FILETYPE_PEM));
  64642. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  64643. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  64644. wolfSSL_X509_free(x509_1);
  64645. wolfSSL_X509_free(x509_2);
  64646. wolfSSL_X509_STORE_free(store);
  64647. #endif
  64648. return EXPECT_RESULT();
  64649. }
  64650. static int test_wolfSSL_X509_check_ca(void)
  64651. {
  64652. EXPECT_DECLS;
  64653. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64654. WOLFSSL_X509 *x509 = NULL;
  64655. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64656. WOLFSSL_FILETYPE_PEM));
  64657. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  64658. wolfSSL_X509_free(x509);
  64659. #endif
  64660. return EXPECT_RESULT();
  64661. }
  64662. static int test_wolfSSL_X509_check_ip_asc(void)
  64663. {
  64664. EXPECT_DECLS;
  64665. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64666. WOLFSSL_X509 *x509 = NULL;
  64667. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  64668. WOLFSSL_FILETYPE_PEM));
  64669. #if 0
  64670. /* TODO: add cert gen for testing positive case */
  64671. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  64672. #endif
  64673. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  64674. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  64675. wolfSSL_X509_free(x509);
  64676. #endif
  64677. return EXPECT_RESULT();
  64678. }
  64679. static int test_wolfSSL_make_cert(void)
  64680. {
  64681. EXPECT_DECLS;
  64682. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  64683. defined(WOLFSSL_CERT_EXT)
  64684. int ret = 0;
  64685. Cert cert;
  64686. CertName name;
  64687. RsaKey key;
  64688. WC_RNG rng;
  64689. byte der[FOURK_BUF];
  64690. word32 idx = 0;
  64691. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  64692. #ifdef OPENSSL_EXTRA
  64693. const unsigned char* pt = NULL;
  64694. int certSz = 0;
  64695. X509* x509 = NULL;
  64696. X509_NAME* x509name = NULL;
  64697. X509_NAME_ENTRY* entry = NULL;
  64698. ASN1_STRING* entryValue = NULL;
  64699. #endif
  64700. XMEMSET(&name, 0, sizeof(CertName));
  64701. /* set up cert name */
  64702. XMEMCPY(name.country, "US", sizeof("US"));
  64703. name.countryEnc = CTC_PRINTABLE;
  64704. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  64705. name.stateEnc = CTC_UTF8;
  64706. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  64707. name.localityEnc = CTC_UTF8;
  64708. XMEMCPY(name.sur, "Test", sizeof("Test"));
  64709. name.surEnc = CTC_UTF8;
  64710. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  64711. name.orgEnc = CTC_UTF8;
  64712. XMEMCPY(name.unit, "Development", sizeof("Development"));
  64713. name.unitEnc = CTC_UTF8;
  64714. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  64715. name.commonNameEnc = CTC_UTF8;
  64716. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  64717. name.serialDevEnc = CTC_PRINTABLE;
  64718. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  64719. name.userIdEnc = CTC_PRINTABLE;
  64720. #ifdef WOLFSSL_MULTI_ATTRIB
  64721. #if CTC_MAX_ATTRIB > 2
  64722. {
  64723. NameAttrib* n;
  64724. n = &name.name[0];
  64725. n->id = ASN_DOMAIN_COMPONENT;
  64726. n->type = CTC_UTF8;
  64727. n->sz = sizeof("com");
  64728. XMEMCPY(n->value, "com", sizeof("com"));
  64729. n = &name.name[1];
  64730. n->id = ASN_DOMAIN_COMPONENT;
  64731. n->type = CTC_UTF8;
  64732. n->sz = sizeof("wolfssl");
  64733. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  64734. }
  64735. #endif
  64736. #endif /* WOLFSSL_MULTI_ATTRIB */
  64737. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  64738. #ifndef HAVE_FIPS
  64739. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  64740. #else
  64741. ExpectIntEQ(wc_InitRng(&rng), 0);
  64742. #endif
  64743. /* load test RSA key */
  64744. idx = 0;
  64745. #if defined(USE_CERT_BUFFERS_1024)
  64746. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  64747. sizeof_server_key_der_1024), 0);
  64748. #elif defined(USE_CERT_BUFFERS_2048)
  64749. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  64750. sizeof_server_key_der_2048), 0);
  64751. #else
  64752. /* error case, no RSA key loaded, happens later */
  64753. (void)idx;
  64754. #endif
  64755. XMEMSET(&cert, 0 , sizeof(Cert));
  64756. ExpectIntEQ(wc_InitCert(&cert), 0);
  64757. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  64758. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  64759. cert.serialSz = (int)sizeof(mySerial);
  64760. cert.isCA = 1;
  64761. #ifndef NO_SHA256
  64762. cert.sigType = CTC_SHA256wRSA;
  64763. #else
  64764. cert.sigType = CTC_SHAwRSA;
  64765. #endif
  64766. /* add SKID from the Public Key */
  64767. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64768. /* add AKID from the Public Key */
  64769. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64770. ret = 0;
  64771. do {
  64772. #if defined(WOLFSSL_ASYNC_CRYPT)
  64773. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  64774. #endif
  64775. if (ret >= 0) {
  64776. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  64777. }
  64778. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  64779. ExpectIntGT(ret, 0);
  64780. #ifdef OPENSSL_EXTRA
  64781. /* der holds a certificate with DC's now check X509 parsing of it */
  64782. certSz = ret;
  64783. pt = der;
  64784. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  64785. ExpectNotNull(x509name = X509_get_subject_name(x509));
  64786. #ifdef WOLFSSL_MULTI_ATTRIB
  64787. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64788. -1)), 5);
  64789. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64790. (int)idx)), 6);
  64791. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64792. (int)idx)), -1);
  64793. #endif /* WOLFSSL_MULTI_ATTRIB */
  64794. /* compare DN at index 0 */
  64795. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  64796. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64797. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  64798. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  64799. #ifndef WOLFSSL_MULTI_ATTRIB
  64800. /* compare Serial Number */
  64801. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  64802. -1)), 7);
  64803. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  64804. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64805. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  64806. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  64807. #endif
  64808. #ifdef WOLFSSL_MULTI_ATTRIB
  64809. /* get first and second DC and compare result */
  64810. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64811. -1)), 5);
  64812. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64813. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64814. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  64815. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64816. (int)idx)), 6);
  64817. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64818. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64819. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  64820. #endif /* WOLFSSL_MULTI_ATTRIB */
  64821. /* try invalid index locations for regression test and sanity check */
  64822. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  64823. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  64824. X509_free(x509);
  64825. #endif /* OPENSSL_EXTRA */
  64826. wc_FreeRsaKey(&key);
  64827. wc_FreeRng(&rng);
  64828. #endif
  64829. return EXPECT_RESULT();
  64830. }
  64831. static int test_x509_get_key_id(void)
  64832. {
  64833. EXPECT_DECLS;
  64834. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64835. X509 *x509 = NULL;
  64836. const ASN1_STRING* str = NULL;
  64837. byte* keyId = NULL;
  64838. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  64839. WOLFSSL_FILETYPE_PEM));
  64840. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  64841. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  64842. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  64843. ASN1_STRING_length(str));
  64844. X509_free(x509);
  64845. #endif
  64846. return EXPECT_RESULT();
  64847. }
  64848. static int test_wolfSSL_X509_get_version(void)
  64849. {
  64850. EXPECT_DECLS;
  64851. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64852. WOLFSSL_X509 *x509 = NULL;
  64853. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64854. WOLFSSL_FILETYPE_PEM));
  64855. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  64856. wolfSSL_X509_free(x509);
  64857. #endif
  64858. return EXPECT_RESULT();
  64859. }
  64860. #if defined(OPENSSL_ALL)
  64861. static int test_wolfSSL_sk_CIPHER_description(void)
  64862. {
  64863. EXPECT_DECLS;
  64864. #if !defined(NO_RSA)
  64865. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64866. int i;
  64867. int numCiphers = 0;
  64868. const SSL_METHOD *method = NULL;
  64869. const SSL_CIPHER *cipher = NULL;
  64870. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64871. SSL_CTX *ctx = NULL;
  64872. SSL *ssl = NULL;
  64873. char buf[256];
  64874. char test_str[9] = "0000000";
  64875. const char badStr[] = "unknown";
  64876. const char certPath[] = "./certs/client-cert.pem";
  64877. XMEMSET(buf, 0, sizeof(buf));
  64878. ExpectNotNull(method = TLSv1_2_client_method());
  64879. ExpectNotNull(ctx = SSL_CTX_new(method));
  64880. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64881. SSL_CTX_set_verify_depth(ctx, 4);
  64882. SSL_CTX_set_options(ctx, flags);
  64883. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64884. WOLFSSL_SUCCESS);
  64885. ExpectNotNull(ssl = SSL_new(ctx));
  64886. /* SSL_get_ciphers returns a stack of all configured ciphers
  64887. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  64888. */
  64889. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64890. /* loop through the amount of supportedCiphers */
  64891. numCiphers = sk_num(supportedCiphers);
  64892. for (i = 0; i < numCiphers; ++i) {
  64893. int j;
  64894. /* sk_value increments "sk->data.cipher->cipherOffset".
  64895. * wolfSSL_sk_CIPHER_description sets the description for
  64896. * the cipher based on the provided offset.
  64897. */
  64898. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  64899. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  64900. }
  64901. /* Search cipher description string for "unknown" descriptor */
  64902. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  64903. int k = 0;
  64904. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  64905. test_str[k] = badStr[k];
  64906. j++;
  64907. k++;
  64908. }
  64909. }
  64910. /* Fail if test_str == badStr == "unknown" */
  64911. ExpectStrNE(test_str,badStr);
  64912. }
  64913. SSL_free(ssl);
  64914. SSL_CTX_free(ctx);
  64915. #endif
  64916. return EXPECT_RESULT();
  64917. }
  64918. static int test_wolfSSL_get_ciphers_compat(void)
  64919. {
  64920. EXPECT_DECLS;
  64921. #if !defined(NO_RSA)
  64922. const SSL_METHOD *method = NULL;
  64923. const char certPath[] = "./certs/client-cert.pem";
  64924. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64925. SSL_CTX *ctx = NULL;
  64926. WOLFSSL *ssl = NULL;
  64927. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64928. ExpectNotNull(method = SSLv23_client_method());
  64929. ExpectNotNull(ctx = SSL_CTX_new(method));
  64930. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64931. SSL_CTX_set_verify_depth(ctx, 4);
  64932. SSL_CTX_set_options(ctx, flags);
  64933. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64934. WOLFSSL_SUCCESS);
  64935. ExpectNotNull(ssl = SSL_new(ctx));
  64936. /* Test Bad NULL input */
  64937. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  64938. /* Test for Good input */
  64939. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64940. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  64941. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  64942. SSL_free(ssl);
  64943. SSL_CTX_free(ctx);
  64944. #endif
  64945. return EXPECT_RESULT();
  64946. }
  64947. static int test_wolfSSL_X509_PUBKEY_get(void)
  64948. {
  64949. EXPECT_DECLS;
  64950. WOLFSSL_X509_PUBKEY pubkey;
  64951. WOLFSSL_X509_PUBKEY* key;
  64952. WOLFSSL_EVP_PKEY evpkey ;
  64953. WOLFSSL_EVP_PKEY* evpPkey;
  64954. WOLFSSL_EVP_PKEY* retEvpPkey;
  64955. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  64956. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  64957. key = &pubkey;
  64958. evpPkey = &evpkey;
  64959. evpPkey->type = WOLFSSL_SUCCESS;
  64960. key->pkey = evpPkey;
  64961. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64962. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  64963. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  64964. key->pkey = NULL;
  64965. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64966. return EXPECT_RESULT();
  64967. }
  64968. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  64969. {
  64970. EXPECT_DECLS;
  64971. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  64972. DSA *dsa = NULL;
  64973. DSA *setDsa = NULL;
  64974. EVP_PKEY *pkey = NULL;
  64975. EVP_PKEY *set1Pkey = NULL;
  64976. SHA_CTX sha;
  64977. byte signature[DSA_SIG_SIZE];
  64978. byte hash[WC_SHA_DIGEST_SIZE];
  64979. word32 bytes;
  64980. int answer;
  64981. #ifdef USE_CERT_BUFFERS_1024
  64982. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  64983. int dsaKeySz = sizeof_dsa_key_der_1024;
  64984. byte tmp[ONEK_BUF];
  64985. XMEMSET(tmp, 0, sizeof(tmp));
  64986. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64987. bytes = dsaKeySz;
  64988. #elif defined(USE_CERT_BUFFERS_2048)
  64989. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  64990. int dsaKeySz = sizeof_dsa_key_der_2048;
  64991. byte tmp[TWOK_BUF];
  64992. XMEMSET(tmp, 0, sizeof(tmp));
  64993. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64994. bytes = (word32)dsaKeySz;
  64995. #else
  64996. byte tmp[TWOK_BUF];
  64997. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  64998. int dsaKeySz;
  64999. XFILE fp = XBADFILE;
  65000. XMEMSET(tmp, 0, sizeof(tmp));
  65001. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  65002. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  65003. if (fp != XBADFILE)
  65004. XFCLOSE(fp);
  65005. #endif /* END USE_CERT_BUFFERS_1024 */
  65006. /* Create hash to later Sign and Verify */
  65007. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  65008. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  65009. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  65010. /* Initialize pkey with der format dsa key */
  65011. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  65012. (long)dsaKeySz));
  65013. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  65014. /* Should Fail: NULL argument */
  65015. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  65016. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  65017. /* Should Pass: Initialized pkey argument */
  65018. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  65019. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  65020. #ifdef USE_CERT_BUFFERS_1024
  65021. ExpectIntEQ(DSA_bits(dsa), 1024);
  65022. #else
  65023. ExpectIntEQ(DSA_bits(dsa), 2048);
  65024. #endif
  65025. /* Sign */
  65026. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  65027. /* Verify. */
  65028. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  65029. WOLFSSL_SUCCESS);
  65030. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  65031. /* Should Fail: set1Pkey not initialized */
  65032. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65033. /* Initialize set1Pkey */
  65034. set1Pkey = EVP_PKEY_new();
  65035. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  65036. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  65037. WOLFSSL_SUCCESS);
  65038. /* Should Pass: set dsa into set1Pkey */
  65039. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65040. DSA_free(dsa);
  65041. DSA_free(setDsa);
  65042. EVP_PKEY_free(pkey);
  65043. EVP_PKEY_free(set1Pkey);
  65044. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  65045. return EXPECT_RESULT();
  65046. } /* END test_EVP_PKEY_set1_get1_DSA */
  65047. static int test_wolfSSL_DSA_generate_parameters(void)
  65048. {
  65049. EXPECT_DECLS;
  65050. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65051. !defined(HAVE_FIPS)
  65052. DSA *dsa = NULL;
  65053. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  65054. NULL));
  65055. DSA_free(dsa);
  65056. #endif
  65057. return EXPECT_RESULT();
  65058. }
  65059. static int test_wolfSSL_DSA_SIG(void)
  65060. {
  65061. EXPECT_DECLS;
  65062. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65063. !defined(HAVE_FIPS)
  65064. DSA *dsa = NULL;
  65065. DSA *dsa2 = NULL;
  65066. DSA_SIG *sig = NULL;
  65067. const BIGNUM *p = NULL;
  65068. const BIGNUM *q = NULL;
  65069. const BIGNUM *g = NULL;
  65070. const BIGNUM *pub = NULL;
  65071. const BIGNUM *priv = NULL;
  65072. BIGNUM *dup_p = NULL;
  65073. BIGNUM *dup_q = NULL;
  65074. BIGNUM *dup_g = NULL;
  65075. BIGNUM *dup_pub = NULL;
  65076. BIGNUM *dup_priv = NULL;
  65077. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  65078. ExpectNotNull(dsa = DSA_new());
  65079. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  65080. NULL), 1);
  65081. ExpectIntEQ(DSA_generate_key(dsa), 1);
  65082. DSA_get0_pqg(dsa, &p, &q, &g);
  65083. DSA_get0_key(dsa, &pub, &priv);
  65084. ExpectNotNull(dup_p = BN_dup(p));
  65085. ExpectNotNull(dup_q = BN_dup(q));
  65086. ExpectNotNull(dup_g = BN_dup(g));
  65087. ExpectNotNull(dup_pub = BN_dup(pub));
  65088. ExpectNotNull(dup_priv = BN_dup(priv));
  65089. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  65090. ExpectNotNull(dsa2 = DSA_new());
  65091. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  65092. if (EXPECT_FAIL()) {
  65093. BN_free(dup_p);
  65094. BN_free(dup_q);
  65095. BN_free(dup_g);
  65096. }
  65097. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  65098. if (EXPECT_FAIL()) {
  65099. BN_free(dup_pub);
  65100. BN_free(dup_priv);
  65101. }
  65102. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  65103. DSA_free(dsa);
  65104. DSA_free(dsa2);
  65105. DSA_SIG_free(sig);
  65106. #endif
  65107. return EXPECT_RESULT();
  65108. }
  65109. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  65110. {
  65111. EXPECT_DECLS;
  65112. #ifdef HAVE_ECC
  65113. WOLFSSL_EC_KEY* ecKey = NULL;
  65114. WOLFSSL_EC_KEY* ecGet1 = NULL;
  65115. EVP_PKEY* pkey = NULL;
  65116. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65117. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65118. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  65119. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65120. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65121. /* Should fail since ecKey is empty */
  65122. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65123. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65124. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  65125. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  65126. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  65127. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  65128. wolfSSL_EC_KEY_free(ecKey);
  65129. wolfSSL_EC_KEY_free(ecGet1);
  65130. EVP_PKEY_free(pkey);
  65131. #endif /* HAVE_ECC */
  65132. return EXPECT_RESULT();
  65133. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  65134. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  65135. {
  65136. EXPECT_DECLS;
  65137. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  65138. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  65139. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  65140. DH *dh = NULL;
  65141. DH *setDh = NULL;
  65142. EVP_PKEY *pkey = NULL;
  65143. XFILE f = XBADFILE;
  65144. unsigned char buf[4096];
  65145. const unsigned char* pt = buf;
  65146. const char* dh2048 = "./certs/dh2048.der";
  65147. long len = 0;
  65148. int code = -1;
  65149. XMEMSET(buf, 0, sizeof(buf));
  65150. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  65151. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65152. if (f != XBADFILE)
  65153. XFCLOSE(f);
  65154. /* Load dh2048.der into DH with internal format */
  65155. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65156. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  65157. ExpectIntEQ(code, 0);
  65158. code = -1;
  65159. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65160. /* Set DH into PKEY */
  65161. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  65162. /* Get DH from PKEY */
  65163. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  65164. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  65165. ExpectIntEQ(code, 0);
  65166. EVP_PKEY_free(pkey);
  65167. DH_free(setDh);
  65168. setDh = NULL;
  65169. DH_free(dh);
  65170. dh = NULL;
  65171. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  65172. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  65173. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  65174. return EXPECT_RESULT();
  65175. } /* END test_EVP_PKEY_set1_get1_DH */
  65176. static int test_wolfSSL_CTX_ctrl(void)
  65177. {
  65178. EXPECT_DECLS;
  65179. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65180. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65181. char caFile[] = "./certs/client-ca.pem";
  65182. char clientFile[] = "./certs/client-cert.pem";
  65183. SSL_CTX* ctx = NULL;
  65184. X509* x509 = NULL;
  65185. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65186. byte buf[6000];
  65187. char file[] = "./certs/dsaparams.pem";
  65188. XFILE f = XBADFILE;
  65189. int bytes = 0;
  65190. BIO* bio = NULL;
  65191. DSA* dsa = NULL;
  65192. DH* dh = NULL;
  65193. #endif
  65194. #ifdef HAVE_ECC
  65195. WOLFSSL_EC_KEY* ecKey = NULL;
  65196. #endif
  65197. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  65198. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  65199. WOLFSSL_FILETYPE_PEM));
  65200. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  65201. if (EXPECT_FAIL()) {
  65202. wolfSSL_X509_free(x509);
  65203. }
  65204. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  65205. WOLFSSL_FILETYPE_PEM));
  65206. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65207. /* Initialize DH */
  65208. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  65209. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  65210. if (f != XBADFILE)
  65211. XFCLOSE(f);
  65212. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  65213. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  65214. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  65215. #endif
  65216. #ifdef HAVE_ECC
  65217. /* Initialize WOLFSSL_EC_KEY */
  65218. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65219. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65220. #endif
  65221. /* additional test of getting EVP_PKEY key size from X509
  65222. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  65223. * allowed with user RSA */
  65224. {
  65225. EVP_PKEY* pkey = NULL;
  65226. #if defined(HAVE_ECC)
  65227. X509* ecX509 = NULL;
  65228. #endif /* HAVE_ECC */
  65229. ExpectNotNull(pkey = X509_get_pubkey(x509));
  65230. /* current RSA key is 2048 bit (256 bytes) */
  65231. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  65232. EVP_PKEY_free(pkey);
  65233. pkey = NULL;
  65234. #if defined(HAVE_ECC)
  65235. #if defined(USE_CERT_BUFFERS_256)
  65236. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  65237. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  65238. SSL_FILETYPE_ASN1));
  65239. #else
  65240. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  65241. cliEccCertFile, SSL_FILETYPE_PEM));
  65242. #endif
  65243. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  65244. /* current ECC key is 256 bit (32 bytes) */
  65245. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  65246. X509_free(ecX509);
  65247. EVP_PKEY_free(pkey);
  65248. #endif /* HAVE_ECC */
  65249. }
  65250. /* Tests should fail with passed in NULL pointer */
  65251. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  65252. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65253. #if !defined(NO_DH) && !defined(NO_DSA)
  65254. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  65255. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65256. #endif
  65257. #ifdef HAVE_ECC
  65258. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  65259. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65260. #endif
  65261. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  65262. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  65263. */
  65264. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  65265. SSL_SUCCESS);
  65266. if (EXPECT_FAIL()) {
  65267. wolfSSL_X509_free(x509);
  65268. }
  65269. /* Test with SSL_CTRL_OPTIONS
  65270. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  65271. */
  65272. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  65273. NULL) == SSL_OP_NO_TLSv1);
  65274. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  65275. /* Test with SSL_CTRL_SET_TMP_DH
  65276. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  65277. */
  65278. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65279. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  65280. SSL_SUCCESS);
  65281. #endif
  65282. /* Test with SSL_CTRL_SET_TMP_ECDH
  65283. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  65284. */
  65285. #ifdef HAVE_ECC
  65286. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  65287. SSL_SUCCESS);
  65288. #endif
  65289. #ifdef WOLFSSL_ENCRYPTED_KEYS
  65290. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  65291. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  65292. #endif
  65293. /* Test for min/max proto */
  65294. #ifndef WOLFSSL_NO_TLS12
  65295. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65296. 0, NULL), SSL_SUCCESS);
  65297. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65298. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65299. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  65300. #endif
  65301. #ifdef WOLFSSL_TLS13
  65302. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65303. 0, NULL), SSL_SUCCESS);
  65304. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65305. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  65306. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  65307. #ifndef WOLFSSL_NO_TLS12
  65308. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65309. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65310. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  65311. #endif
  65312. #endif
  65313. /* Cleanup and Pass */
  65314. #if !defined(NO_DH) && !defined(NO_DSA)
  65315. #ifndef NO_BIO
  65316. BIO_free(bio);
  65317. DSA_free(dsa);
  65318. DH_free(dh);
  65319. dh = NULL;
  65320. #endif
  65321. #endif
  65322. #ifdef HAVE_ECC
  65323. wolfSSL_EC_KEY_free(ecKey);
  65324. #endif
  65325. SSL_CTX_free(ctx);
  65326. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65327. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  65328. return EXPECT_RESULT();
  65329. }
  65330. static int test_wolfSSL_EVP_PKEY_assign(void)
  65331. {
  65332. EXPECT_DECLS;
  65333. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  65334. int type;
  65335. WOLFSSL_EVP_PKEY* pkey = NULL;
  65336. #ifndef NO_RSA
  65337. WOLFSSL_RSA* rsa = NULL;
  65338. #endif
  65339. #ifndef NO_DSA
  65340. WOLFSSL_DSA* dsa = NULL;
  65341. #endif
  65342. #ifdef HAVE_ECC
  65343. WOLFSSL_EC_KEY* ecKey = NULL;
  65344. #endif
  65345. #ifndef NO_RSA
  65346. type = EVP_PKEY_RSA;
  65347. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65348. ExpectNotNull(rsa = wolfSSL_RSA_new());
  65349. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65350. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65351. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65352. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  65353. if (EXPECT_FAIL()) {
  65354. wolfSSL_RSA_free(rsa);
  65355. }
  65356. wolfSSL_EVP_PKEY_free(pkey);
  65357. pkey = NULL;
  65358. #endif /* NO_RSA */
  65359. #ifndef NO_DSA
  65360. type = EVP_PKEY_DSA;
  65361. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65362. ExpectNotNull(dsa = wolfSSL_DSA_new());
  65363. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65364. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65365. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65366. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  65367. if (EXPECT_FAIL()) {
  65368. wolfSSL_DSA_free(dsa);
  65369. }
  65370. wolfSSL_EVP_PKEY_free(pkey);
  65371. pkey = NULL;
  65372. #endif /* NO_DSA */
  65373. #ifdef HAVE_ECC
  65374. type = EVP_PKEY_EC;
  65375. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65376. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65377. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65378. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65379. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65380. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65381. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65382. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  65383. if (EXPECT_FAIL()) {
  65384. wolfSSL_EC_KEY_free(ecKey);
  65385. }
  65386. wolfSSL_EVP_PKEY_free(pkey);
  65387. pkey = NULL;
  65388. #endif /* HAVE_ECC */
  65389. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  65390. return EXPECT_RESULT();
  65391. }
  65392. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  65393. {
  65394. EXPECT_DECLS;
  65395. #if !defined(NO_DH) && \
  65396. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65397. XFILE f = XBADFILE;
  65398. unsigned char buf[4096];
  65399. const unsigned char* pt = buf;
  65400. const char* params1 = "./certs/dh2048.der";
  65401. long len = 0;
  65402. WOLFSSL_DH* dh = NULL;
  65403. WOLFSSL_EVP_PKEY* pkey = NULL;
  65404. XMEMSET(buf, 0, sizeof(buf));
  65405. /* Load DH parameters DER. */
  65406. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  65407. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65408. if (f != XBADFILE)
  65409. XFCLOSE(f);
  65410. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65411. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  65412. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65413. /* Bad cases */
  65414. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65415. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65416. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65417. /* Good case */
  65418. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  65419. if (EXPECT_FAIL()) {
  65420. wolfSSL_DH_free(dh);
  65421. }
  65422. EVP_PKEY_free(pkey);
  65423. #endif
  65424. return EXPECT_RESULT();
  65425. }
  65426. static int test_wolfSSL_EVP_PKEY_base_id(void)
  65427. {
  65428. EXPECT_DECLS;
  65429. WOLFSSL_EVP_PKEY* pkey = NULL;
  65430. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65431. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  65432. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  65433. EVP_PKEY_free(pkey);
  65434. return EXPECT_RESULT();
  65435. }
  65436. static int test_wolfSSL_EVP_PKEY_id(void)
  65437. {
  65438. EXPECT_DECLS;
  65439. WOLFSSL_EVP_PKEY* pkey = NULL;
  65440. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65441. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  65442. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  65443. EVP_PKEY_free(pkey);
  65444. return EXPECT_RESULT();
  65445. }
  65446. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  65447. {
  65448. EXPECT_DECLS;
  65449. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  65450. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  65451. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  65452. ECC_MIN_KEY_SZ <= 256)
  65453. EVP_PKEY_CTX* ctx = NULL;
  65454. EVP_PKEY* pkey = NULL;
  65455. /* Test error conditions. */
  65456. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65457. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65458. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65459. #ifndef NO_RSA
  65460. EVP_PKEY_CTX_free(ctx);
  65461. /* Parameter generation for RSA not supported yet. */
  65462. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  65463. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65464. #endif
  65465. #ifdef HAVE_ECC
  65466. EVP_PKEY_CTX_free(ctx);
  65467. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65468. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  65469. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  65470. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  65471. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  65472. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  65473. WOLFSSL_SUCCESS);
  65474. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65475. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65476. #endif
  65477. EVP_PKEY_CTX_free(ctx);
  65478. EVP_PKEY_free(pkey);
  65479. #endif
  65480. return EXPECT_RESULT();
  65481. }
  65482. static int test_wolfSSL_EVP_PKEY_keygen(void)
  65483. {
  65484. EXPECT_DECLS;
  65485. WOLFSSL_EVP_PKEY* pkey = NULL;
  65486. EVP_PKEY_CTX* ctx = NULL;
  65487. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65488. WOLFSSL_EVP_PKEY* params = NULL;
  65489. DH* dh = NULL;
  65490. const BIGNUM* pubkey = NULL;
  65491. const BIGNUM* privkey = NULL;
  65492. ASN1_INTEGER* asn1int = NULL;
  65493. unsigned int length = 0;
  65494. byte* derBuffer = NULL;
  65495. #endif
  65496. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65497. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65498. /* Bad cases */
  65499. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  65500. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  65501. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  65502. /* Good case */
  65503. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  65504. EVP_PKEY_CTX_free(ctx);
  65505. ctx = NULL;
  65506. EVP_PKEY_free(pkey);
  65507. pkey = NULL;
  65508. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65509. /* Test DH keygen */
  65510. {
  65511. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65512. ExpectNotNull(dh = DH_get_2048_256());
  65513. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65514. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  65515. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65516. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65517. DH_free(dh);
  65518. dh = NULL;
  65519. EVP_PKEY_CTX_free(ctx);
  65520. EVP_PKEY_free(params);
  65521. /* try exporting generated key to DER, to verify */
  65522. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  65523. DH_get0_key(dh, &pubkey, &privkey);
  65524. ExpectNotNull(pubkey);
  65525. ExpectNotNull(privkey);
  65526. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  65527. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  65528. ASN1_INTEGER_free(asn1int);
  65529. DH_free(dh);
  65530. dh = NULL;
  65531. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  65532. EVP_PKEY_free(pkey);
  65533. }
  65534. #endif
  65535. return EXPECT_RESULT();
  65536. }
  65537. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  65538. {
  65539. EXPECT_DECLS;
  65540. WOLFSSL_EVP_PKEY* pkey = NULL;
  65541. EVP_PKEY_CTX *ctx = NULL;
  65542. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65543. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65544. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65545. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  65546. EVP_PKEY_CTX_free(ctx);
  65547. EVP_PKEY_free(pkey);
  65548. return EXPECT_RESULT();
  65549. }
  65550. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  65551. {
  65552. EXPECT_DECLS;
  65553. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  65554. WOLFSSL_EVP_PKEY* pkey = NULL;
  65555. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65556. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  65557. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  65558. EVP_PKEY_free(pkey);
  65559. #endif
  65560. return EXPECT_RESULT();
  65561. }
  65562. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  65563. {
  65564. EXPECT_DECLS;
  65565. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  65566. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  65567. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  65568. !defined(NO_FILESYSTEM)
  65569. WOLFSSL_EVP_PKEY* params = NULL;
  65570. WOLFSSL_EVP_PKEY* copy = NULL;
  65571. DH* dh = NULL;
  65572. BIGNUM* p1;
  65573. BIGNUM* g1;
  65574. BIGNUM* q1;
  65575. BIGNUM* p2;
  65576. BIGNUM* g2;
  65577. BIGNUM* q2;
  65578. /* create DH with DH_get_2048_256 params */
  65579. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65580. ExpectNotNull(dh = DH_get_2048_256());
  65581. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65582. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  65583. (const BIGNUM**)&q1,
  65584. (const BIGNUM**)&g1);
  65585. DH_free(dh);
  65586. dh = NULL;
  65587. /* create DH with random generated DH params */
  65588. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  65589. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  65590. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  65591. DH_free(dh);
  65592. dh = NULL;
  65593. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  65594. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  65595. ExpectNotNull(dh->p);
  65596. ExpectNotNull(dh->g);
  65597. ExpectNotNull(dh->q);
  65598. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  65599. (const BIGNUM**)&q2,
  65600. (const BIGNUM**)&g2);
  65601. ExpectIntEQ(BN_cmp(p1, p2), 0);
  65602. ExpectIntEQ(BN_cmp(q1, q2), 0);
  65603. ExpectIntEQ(BN_cmp(g1, g2), 0);
  65604. DH_free(dh);
  65605. dh = NULL;
  65606. EVP_PKEY_free(copy);
  65607. EVP_PKEY_free(params);
  65608. #endif
  65609. return EXPECT_RESULT();
  65610. }
  65611. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  65612. {
  65613. EXPECT_DECLS;
  65614. WOLFSSL_EVP_PKEY* pkey = NULL;
  65615. EVP_PKEY_CTX* ctx = NULL;
  65616. int bits = 2048;
  65617. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65618. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65619. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  65620. WOLFSSL_SUCCESS);
  65621. EVP_PKEY_CTX_free(ctx);
  65622. EVP_PKEY_free(pkey);
  65623. return EXPECT_RESULT();
  65624. }
  65625. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  65626. {
  65627. EXPECT_DECLS;
  65628. /* This is large enough to be used for all key sizes */
  65629. byte key[AES_256_KEY_SIZE] = {0};
  65630. byte iv[AES_BLOCK_SIZE] = {0};
  65631. int i;
  65632. int nids[] = {
  65633. #ifdef HAVE_AES_CBC
  65634. NID_aes_128_cbc,
  65635. #endif
  65636. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65637. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65638. #ifdef HAVE_AESGCM
  65639. NID_aes_128_gcm,
  65640. #endif
  65641. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65642. #ifdef WOLFSSL_AES_COUNTER
  65643. NID_aes_128_ctr,
  65644. #endif
  65645. #ifndef NO_DES3
  65646. NID_des_cbc,
  65647. NID_des_ede3_cbc,
  65648. #endif
  65649. };
  65650. int iv_lengths[] = {
  65651. #ifdef HAVE_AES_CBC
  65652. AES_BLOCK_SIZE,
  65653. #endif
  65654. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65655. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65656. #ifdef HAVE_AESGCM
  65657. GCM_NONCE_MID_SZ,
  65658. #endif
  65659. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65660. #ifdef WOLFSSL_AES_COUNTER
  65661. AES_BLOCK_SIZE,
  65662. #endif
  65663. #ifndef NO_DES3
  65664. DES_BLOCK_SIZE,
  65665. DES_BLOCK_SIZE,
  65666. #endif
  65667. };
  65668. int nidsLen = (sizeof(nids)/sizeof(int));
  65669. for (i = 0; i < nidsLen; i++) {
  65670. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65671. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65672. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65673. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65674. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  65675. EVP_CIPHER_CTX_free(ctx);
  65676. }
  65677. return EXPECT_RESULT();
  65678. }
  65679. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  65680. {
  65681. EXPECT_DECLS;
  65682. byte key[AES_256_KEY_SIZE] = {0};
  65683. byte iv[AES_BLOCK_SIZE] = {0};
  65684. int i;
  65685. int nids[] = {
  65686. #ifdef HAVE_AES_CBC
  65687. NID_aes_128_cbc,
  65688. NID_aes_256_cbc,
  65689. #endif
  65690. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65691. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65692. #ifdef HAVE_AESGCM
  65693. NID_aes_128_gcm,
  65694. NID_aes_256_gcm,
  65695. #endif
  65696. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65697. #ifdef WOLFSSL_AES_COUNTER
  65698. NID_aes_128_ctr,
  65699. NID_aes_256_ctr,
  65700. #endif
  65701. #ifndef NO_DES3
  65702. NID_des_cbc,
  65703. NID_des_ede3_cbc,
  65704. #endif
  65705. };
  65706. int key_lengths[] = {
  65707. #ifdef HAVE_AES_CBC
  65708. AES_128_KEY_SIZE,
  65709. AES_256_KEY_SIZE,
  65710. #endif
  65711. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65712. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65713. #ifdef HAVE_AESGCM
  65714. AES_128_KEY_SIZE,
  65715. AES_256_KEY_SIZE,
  65716. #endif
  65717. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65718. #ifdef WOLFSSL_AES_COUNTER
  65719. AES_128_KEY_SIZE,
  65720. AES_256_KEY_SIZE,
  65721. #endif
  65722. #ifndef NO_DES3
  65723. DES_KEY_SIZE,
  65724. DES3_KEY_SIZE,
  65725. #endif
  65726. };
  65727. int nidsLen = (sizeof(nids)/sizeof(int));
  65728. for (i = 0; i < nidsLen; i++) {
  65729. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65730. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65731. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65732. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65733. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  65734. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  65735. WOLFSSL_SUCCESS);
  65736. EVP_CIPHER_CTX_free(ctx);
  65737. }
  65738. return EXPECT_RESULT();
  65739. }
  65740. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  65741. {
  65742. EXPECT_DECLS;
  65743. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  65744. int ivLen, keyLen;
  65745. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  65746. #ifdef HAVE_AESGCM
  65747. byte key[AES_128_KEY_SIZE] = {0};
  65748. byte iv[AES_BLOCK_SIZE] = {0};
  65749. const EVP_CIPHER *init = EVP_aes_128_gcm();
  65750. #else
  65751. byte key[DES3_KEY_SIZE] = {0};
  65752. byte iv[DES_BLOCK_SIZE] = {0};
  65753. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  65754. #endif
  65755. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65756. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65757. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  65758. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  65759. /* Bad cases */
  65760. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  65761. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65762. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  65763. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65764. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65765. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65766. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  65767. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65768. /* Good case */
  65769. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  65770. EVP_CIPHER_CTX_free(ctx);
  65771. #endif
  65772. return EXPECT_RESULT();
  65773. }
  65774. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  65775. {
  65776. EXPECT_DECLS;
  65777. WOLFSSL_ENGINE* e = NULL;
  65778. int id = 0;
  65779. EVP_PKEY_CTX *ctx = NULL;
  65780. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  65781. EVP_PKEY_CTX_free(ctx);
  65782. return EXPECT_RESULT();
  65783. }
  65784. static int test_wolfSSL_EVP_rc4(void)
  65785. {
  65786. EXPECT_DECLS;
  65787. #if !defined(NO_RC4)
  65788. ExpectNotNull(wolfSSL_EVP_rc4());
  65789. #endif
  65790. return EXPECT_RESULT();
  65791. }
  65792. static int test_wolfSSL_EVP_enc_null(void)
  65793. {
  65794. EXPECT_DECLS;
  65795. ExpectNotNull(wolfSSL_EVP_enc_null());
  65796. return EXPECT_RESULT();
  65797. }
  65798. static int test_wolfSSL_EVP_rc2_cbc(void)
  65799. {
  65800. EXPECT_DECLS;
  65801. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  65802. ExpectNull(wolfSSL_EVP_rc2_cbc());
  65803. #endif
  65804. return EXPECT_RESULT();
  65805. }
  65806. static int test_wolfSSL_EVP_mdc2(void)
  65807. {
  65808. EXPECT_DECLS;
  65809. #if !defined(NO_WOLFSSL_STUB)
  65810. ExpectNull(wolfSSL_EVP_mdc2());
  65811. #endif
  65812. return EXPECT_RESULT();
  65813. }
  65814. static int test_wolfSSL_EVP_md4(void)
  65815. {
  65816. EXPECT_DECLS;
  65817. #if !defined(NO_MD4)
  65818. ExpectNotNull(wolfSSL_EVP_md4());
  65819. #endif
  65820. return EXPECT_RESULT();
  65821. }
  65822. static int test_wolfSSL_EVP_aes_256_gcm(void)
  65823. {
  65824. EXPECT_DECLS;
  65825. #ifdef HAVE_AESGCM
  65826. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  65827. #endif
  65828. return EXPECT_RESULT();
  65829. }
  65830. static int test_wolfSSL_EVP_aes_192_gcm(void)
  65831. {
  65832. EXPECT_DECLS;
  65833. #ifdef HAVE_AESGCM
  65834. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  65835. #endif
  65836. return EXPECT_RESULT();
  65837. }
  65838. static int test_wolfSSL_EVP_aes_256_ccm(void)
  65839. {
  65840. EXPECT_DECLS;
  65841. #ifdef HAVE_AESCCM
  65842. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  65843. #endif
  65844. return EXPECT_RESULT();
  65845. }
  65846. static int test_wolfSSL_EVP_aes_192_ccm(void)
  65847. {
  65848. EXPECT_DECLS;
  65849. #ifdef HAVE_AESCCM
  65850. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  65851. #endif
  65852. return EXPECT_RESULT();
  65853. }
  65854. static int test_wolfSSL_EVP_aes_128_ccm(void)
  65855. {
  65856. EXPECT_DECLS;
  65857. #ifdef HAVE_AESCCM
  65858. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  65859. #endif
  65860. return EXPECT_RESULT();
  65861. }
  65862. static int test_wolfSSL_EVP_ripemd160(void)
  65863. {
  65864. EXPECT_DECLS;
  65865. #if !defined(NO_WOLFSSL_STUB)
  65866. ExpectNull(wolfSSL_EVP_ripemd160());
  65867. #endif
  65868. return EXPECT_RESULT();
  65869. }
  65870. static int test_wolfSSL_EVP_get_digestbynid(void)
  65871. {
  65872. EXPECT_DECLS;
  65873. #ifndef NO_MD5
  65874. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  65875. #endif
  65876. #ifndef NO_SHA
  65877. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  65878. #endif
  65879. #ifndef NO_SHA256
  65880. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  65881. #endif
  65882. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  65883. return EXPECT_RESULT();
  65884. }
  65885. static int test_wolfSSL_EVP_MD_nid(void)
  65886. {
  65887. EXPECT_DECLS;
  65888. #ifndef NO_MD5
  65889. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  65890. #endif
  65891. #ifndef NO_SHA
  65892. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  65893. #endif
  65894. #ifndef NO_SHA256
  65895. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  65896. #endif
  65897. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  65898. return EXPECT_RESULT();
  65899. }
  65900. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  65901. {
  65902. EXPECT_DECLS;
  65903. #if defined(HAVE_ECC)
  65904. WOLFSSL_EVP_PKEY* pkey = NULL;
  65905. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  65906. ExpectNotNull(pkey = EVP_PKEY_new());
  65907. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  65908. EVP_PKEY_free(pkey);
  65909. #endif
  65910. return EXPECT_RESULT();
  65911. }
  65912. static int test_wolfSSL_EVP_X_STATE(void)
  65913. {
  65914. EXPECT_DECLS;
  65915. #if !defined(NO_DES3) && !defined(NO_RC4)
  65916. byte key[DES3_KEY_SIZE] = {0};
  65917. byte iv[DES_IV_SIZE] = {0};
  65918. EVP_CIPHER_CTX *ctx = NULL;
  65919. const EVP_CIPHER *init = NULL;
  65920. /* Bad test cases */
  65921. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65922. ExpectNotNull(init = EVP_des_ede3_cbc());
  65923. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65924. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65925. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  65926. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  65927. EVP_CIPHER_CTX_free(ctx);
  65928. ctx = NULL;
  65929. /* Good test case */
  65930. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65931. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65932. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65933. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65934. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  65935. EVP_CIPHER_CTX_free(ctx);
  65936. #endif
  65937. return EXPECT_RESULT();
  65938. }
  65939. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  65940. {
  65941. EXPECT_DECLS;
  65942. #if !defined(NO_DES3) && !defined(NO_RC4)
  65943. byte key[DES3_KEY_SIZE] = {0};
  65944. byte iv[DES_IV_SIZE] = {0};
  65945. EVP_CIPHER_CTX *ctx = NULL;
  65946. const EVP_CIPHER *init = NULL;
  65947. /* Bad test cases */
  65948. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65949. ExpectNotNull(init = EVP_des_ede3_cbc());
  65950. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65951. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65952. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  65953. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  65954. EVP_CIPHER_CTX_free(ctx);
  65955. ctx = NULL;
  65956. /* Good test case */
  65957. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65958. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65959. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65960. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65961. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  65962. EVP_CIPHER_CTX_free(ctx);
  65963. #endif
  65964. return EXPECT_RESULT();
  65965. }
  65966. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  65967. {
  65968. EXPECT_DECLS;
  65969. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  65970. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  65971. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  65972. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  65973. #ifdef HAVE_AES_CBC
  65974. #ifdef WOLFSSL_AES_128
  65975. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  65976. #endif
  65977. #ifdef WOLFSSL_AES_192
  65978. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  65979. #endif
  65980. #ifdef WOLFSSL_AES_256
  65981. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  65982. #endif
  65983. #endif
  65984. #ifdef HAVE_AESGCM
  65985. #ifdef WOLFSSL_AES_128
  65986. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  65987. #endif
  65988. #ifdef WOLFSSL_AES_192
  65989. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  65990. #endif
  65991. #ifdef WOLFSSL_AES_256
  65992. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  65993. #endif
  65994. #endif
  65995. #ifdef HAVE_AESCCM
  65996. #ifdef WOLFSSL_AES_128
  65997. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  65998. #endif
  65999. #ifdef WOLFSSL_AES_192
  66000. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  66001. #endif
  66002. #ifdef WOLFSSL_AES_256
  66003. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  66004. #endif
  66005. #endif
  66006. #ifdef WOLFSSL_AES_COUNTER
  66007. #ifdef WOLFSSL_AES_128
  66008. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  66009. #endif
  66010. #ifdef WOLFSSL_AES_192
  66011. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  66012. #endif
  66013. #ifdef WOLFSSL_AES_256
  66014. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  66015. #endif
  66016. #endif
  66017. #ifdef HAVE_AES_ECB
  66018. #ifdef WOLFSSL_AES_128
  66019. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  66020. #endif
  66021. #ifdef WOLFSSL_AES_192
  66022. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  66023. #endif
  66024. #ifdef WOLFSSL_AES_256
  66025. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  66026. #endif
  66027. #endif
  66028. #ifdef WOLFSSL_AES_OFB
  66029. #ifdef WOLFSSL_AES_128
  66030. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  66031. #endif
  66032. #ifdef WOLFSSL_AES_192
  66033. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  66034. #endif
  66035. #ifdef WOLFSSL_AES_256
  66036. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  66037. #endif
  66038. #endif
  66039. #ifndef NO_RC4
  66040. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  66041. #endif
  66042. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66043. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  66044. #endif
  66045. #endif
  66046. #ifdef WOLFSSL_SM4_ECB
  66047. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  66048. #endif
  66049. #ifdef WOLFSSL_SM4_CBC
  66050. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  66051. #endif
  66052. #ifdef WOLFSSL_SM4_CTR
  66053. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  66054. #endif
  66055. #ifdef WOLFSSL_SM4_GCM
  66056. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  66057. #endif
  66058. #ifdef WOLFSSL_SM4_CCM
  66059. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  66060. #endif
  66061. return EXPECT_RESULT();
  66062. }
  66063. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  66064. {
  66065. EXPECT_DECLS;
  66066. int nids[] = {
  66067. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66068. #ifdef WOLFSSL_AES_128
  66069. NID_aes_128_cbc,
  66070. #endif
  66071. #ifdef WOLFSSL_AES_192
  66072. NID_aes_192_cbc,
  66073. #endif
  66074. #ifdef WOLFSSL_AES_256
  66075. NID_aes_256_cbc,
  66076. #endif
  66077. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66078. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66079. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66080. #ifdef HAVE_AESGCM
  66081. #ifdef WOLFSSL_AES_128
  66082. NID_aes_128_gcm,
  66083. #endif
  66084. #ifdef WOLFSSL_AES_192
  66085. NID_aes_192_gcm,
  66086. #endif
  66087. #ifdef WOLFSSL_AES_256
  66088. NID_aes_256_gcm,
  66089. #endif
  66090. #endif /* HAVE_AESGCM */
  66091. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66092. #ifdef WOLFSSL_AES_COUNTER
  66093. #ifdef WOLFSSL_AES_128
  66094. NID_aes_128_ctr,
  66095. #endif
  66096. #ifdef WOLFSSL_AES_192
  66097. NID_aes_192_ctr,
  66098. #endif
  66099. #ifdef WOLFSSL_AES_256
  66100. NID_aes_256_ctr,
  66101. #endif
  66102. #endif
  66103. #ifndef NO_DES3
  66104. NID_des_cbc,
  66105. NID_des_ede3_cbc,
  66106. #endif
  66107. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66108. NID_chacha20_poly1305,
  66109. #endif
  66110. };
  66111. int iv_lengths[] = {
  66112. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66113. #ifdef WOLFSSL_AES_128
  66114. AES_BLOCK_SIZE,
  66115. #endif
  66116. #ifdef WOLFSSL_AES_192
  66117. AES_BLOCK_SIZE,
  66118. #endif
  66119. #ifdef WOLFSSL_AES_256
  66120. AES_BLOCK_SIZE,
  66121. #endif
  66122. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66123. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66124. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66125. #ifdef HAVE_AESGCM
  66126. #ifdef WOLFSSL_AES_128
  66127. GCM_NONCE_MID_SZ,
  66128. #endif
  66129. #ifdef WOLFSSL_AES_192
  66130. GCM_NONCE_MID_SZ,
  66131. #endif
  66132. #ifdef WOLFSSL_AES_256
  66133. GCM_NONCE_MID_SZ,
  66134. #endif
  66135. #endif /* HAVE_AESGCM */
  66136. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66137. #ifdef WOLFSSL_AES_COUNTER
  66138. #ifdef WOLFSSL_AES_128
  66139. AES_BLOCK_SIZE,
  66140. #endif
  66141. #ifdef WOLFSSL_AES_192
  66142. AES_BLOCK_SIZE,
  66143. #endif
  66144. #ifdef WOLFSSL_AES_256
  66145. AES_BLOCK_SIZE,
  66146. #endif
  66147. #endif
  66148. #ifndef NO_DES3
  66149. DES_BLOCK_SIZE,
  66150. DES_BLOCK_SIZE,
  66151. #endif
  66152. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66153. CHACHA20_POLY1305_AEAD_IV_SIZE,
  66154. #endif
  66155. };
  66156. int i;
  66157. int nidsLen = (sizeof(nids)/sizeof(int));
  66158. for (i = 0; i < nidsLen; i++) {
  66159. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  66160. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  66161. }
  66162. return EXPECT_RESULT();
  66163. }
  66164. static int test_wolfSSL_EVP_SignInit_ex(void)
  66165. {
  66166. EXPECT_DECLS;
  66167. WOLFSSL_EVP_MD_CTX mdCtx;
  66168. WOLFSSL_ENGINE* e = 0;
  66169. const EVP_MD* md = EVP_sha256();
  66170. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66171. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  66172. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66173. return EXPECT_RESULT();
  66174. }
  66175. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  66176. {
  66177. EXPECT_DECLS;
  66178. #if !defined(NO_SHA256)
  66179. WOLFSSL_EVP_MD_CTX mdCtx;
  66180. unsigned int s = 0;
  66181. unsigned char md[WC_SHA256_DIGEST_SIZE];
  66182. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  66183. /* Bad Case */
  66184. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  66185. (HAVE_FIPS_VERSION > 2))
  66186. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66187. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  66188. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66189. #else
  66190. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66191. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  66192. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  66193. #endif
  66194. /* Good Case */
  66195. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66196. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  66197. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  66198. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  66199. #endif
  66200. return EXPECT_RESULT();
  66201. }
  66202. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  66203. {
  66204. EXPECT_DECLS;
  66205. #if defined(OPENSSL_EXTRA)
  66206. EVP_PKEY* pkey = NULL;
  66207. EVP_PKEY_CTX* ctx = NULL;
  66208. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66209. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66210. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  66211. /* void */
  66212. EVP_PKEY_CTX_free(ctx);
  66213. #else
  66214. /* int */
  66215. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  66216. #endif
  66217. EVP_PKEY_free(pkey);
  66218. #endif
  66219. return EXPECT_RESULT();
  66220. }
  66221. static int test_wolfSSL_EVP_PKEY_param_check(void)
  66222. {
  66223. EXPECT_DECLS;
  66224. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  66225. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  66226. DH *dh = NULL;
  66227. DH *setDh = NULL;
  66228. EVP_PKEY *pkey = NULL;
  66229. EVP_PKEY_CTX* ctx = NULL;
  66230. FILE* f = NULL;
  66231. unsigned char buf[512];
  66232. const unsigned char* pt = buf;
  66233. const char* dh2048 = "./certs/dh2048.der";
  66234. long len = 0;
  66235. int code = -1;
  66236. XMEMSET(buf, 0, sizeof(buf));
  66237. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  66238. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  66239. if (f != XBADFILE)
  66240. XFCLOSE(f);
  66241. /* Load dh2048.der into DH with internal format */
  66242. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  66243. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  66244. ExpectIntEQ(code, 0);
  66245. code = -1;
  66246. pkey = wolfSSL_EVP_PKEY_new();
  66247. /* Set DH into PKEY */
  66248. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  66249. /* create ctx from pkey */
  66250. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66251. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  66252. /* TODO: more invalid cases */
  66253. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  66254. EVP_PKEY_CTX_free(ctx);
  66255. EVP_PKEY_free(pkey);
  66256. DH_free(setDh);
  66257. setDh = NULL;
  66258. DH_free(dh);
  66259. dh = NULL;
  66260. #endif
  66261. #endif
  66262. return EXPECT_RESULT();
  66263. }
  66264. static int test_wolfSSL_EVP_BytesToKey(void)
  66265. {
  66266. EXPECT_DECLS;
  66267. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  66268. byte key[AES_BLOCK_SIZE] = {0};
  66269. byte iv[AES_BLOCK_SIZE] = {0};
  66270. int count = 0;
  66271. const EVP_MD* md = EVP_sha256();
  66272. const EVP_CIPHER *type;
  66273. const unsigned char *salt = (unsigned char *)"salt1234";
  66274. int sz = 5;
  66275. const byte data[] = {
  66276. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  66277. 0x72,0x6c,0x64
  66278. };
  66279. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  66280. /* Bad cases */
  66281. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  66282. 0);
  66283. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  66284. 16);
  66285. md = "2";
  66286. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66287. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66288. /* Good case */
  66289. md = EVP_sha256();
  66290. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66291. 16);
  66292. #endif
  66293. return EXPECT_RESULT();
  66294. }
  66295. static int test_evp_cipher_aes_gcm(void)
  66296. {
  66297. EXPECT_DECLS;
  66298. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  66299. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  66300. (HAVE_FIPS_VERSION >= 2)))
  66301. /*
  66302. * This test checks data at various points in the encrypt/decrypt process
  66303. * against known values produced using the same test with OpenSSL. This
  66304. * interop testing is critical for verifying the correctness of our
  66305. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  66306. * a flow supported by OpenSSL that uses the control command
  66307. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  66308. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  66309. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  66310. * wolfSSL OpenSSH clients because there was a bug in this flow that
  66311. * happened to "cancel out" if both sides of the connection had the bug.
  66312. */
  66313. enum {
  66314. NUM_ENCRYPTIONS = 3,
  66315. AAD_SIZE = 4
  66316. };
  66317. byte plainText1[] = {
  66318. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  66319. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  66320. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  66321. };
  66322. byte plainText2[] = {
  66323. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  66324. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  66325. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  66326. };
  66327. byte plainText3[] = {
  66328. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  66329. 0x5b, 0x57, 0x10
  66330. };
  66331. byte* plainTexts[NUM_ENCRYPTIONS] = {
  66332. plainText1,
  66333. plainText2,
  66334. plainText3
  66335. };
  66336. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  66337. sizeof(plainText1),
  66338. sizeof(plainText2),
  66339. sizeof(plainText3)
  66340. };
  66341. byte aad1[AAD_SIZE] = {
  66342. 0x00, 0x00, 0x00, 0x01
  66343. };
  66344. byte aad2[AAD_SIZE] = {
  66345. 0x00, 0x00, 0x00, 0x10
  66346. };
  66347. byte aad3[AAD_SIZE] = {
  66348. 0x00, 0x00, 0x01, 0x00
  66349. };
  66350. byte* aads[NUM_ENCRYPTIONS] = {
  66351. aad1,
  66352. aad2,
  66353. aad3
  66354. };
  66355. const byte iv[GCM_NONCE_MID_SZ] = {
  66356. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  66357. };
  66358. byte currentIv[GCM_NONCE_MID_SZ];
  66359. const byte key[] = {
  66360. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  66361. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  66362. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  66363. };
  66364. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  66365. {
  66366. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66367. 0xEF
  66368. },
  66369. {
  66370. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66371. 0xF0
  66372. },
  66373. {
  66374. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66375. 0xF1
  66376. }
  66377. };
  66378. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  66379. {
  66380. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  66381. 0x3D, 0x32, 0x18, 0x34, 0xA9
  66382. },
  66383. {
  66384. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  66385. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  66386. },
  66387. {
  66388. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  66389. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  66390. }
  66391. };
  66392. const byte expCipherText1[] = {
  66393. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  66394. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  66395. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  66396. };
  66397. const byte expCipherText2[] = {
  66398. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  66399. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  66400. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  66401. };
  66402. const byte expCipherText3[] = {
  66403. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  66404. 0x80, 0x5E, 0x6B,
  66405. };
  66406. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  66407. expCipherText1,
  66408. expCipherText2,
  66409. expCipherText3
  66410. };
  66411. byte* cipherText = NULL;
  66412. byte* calcPlainText = NULL;
  66413. byte tag[AES_BLOCK_SIZE];
  66414. EVP_CIPHER_CTX* encCtx = NULL;
  66415. EVP_CIPHER_CTX* decCtx = NULL;
  66416. int i, j, outl;
  66417. /****************************************************/
  66418. for (i = 0; i < 3; ++i) {
  66419. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  66420. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  66421. /* First iteration, set key before IV. */
  66422. if (i == 0) {
  66423. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  66424. SSL_SUCCESS);
  66425. /*
  66426. * The call to EVP_CipherInit below (with NULL key) should clear the
  66427. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  66428. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  66429. * behavior.
  66430. */
  66431. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66432. (void*)iv), SSL_SUCCESS);
  66433. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  66434. SSL_SUCCESS);
  66435. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66436. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66437. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  66438. SSL_SUCCESS);
  66439. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  66440. SSL_SUCCESS);
  66441. }
  66442. /* Second iteration, IV before key. */
  66443. else {
  66444. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  66445. SSL_SUCCESS);
  66446. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  66447. SSL_SUCCESS);
  66448. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  66449. SSL_SUCCESS);
  66450. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  66451. SSL_SUCCESS);
  66452. }
  66453. /*
  66454. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  66455. * been issued first.
  66456. */
  66457. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66458. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66459. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66460. (void*)iv), SSL_SUCCESS);
  66461. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66462. (void*)iv), SSL_SUCCESS);
  66463. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  66464. /*************** Encrypt ***************/
  66465. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66466. currentIv), SSL_SUCCESS);
  66467. /* Check current IV against expected. */
  66468. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66469. /* Add AAD. */
  66470. if (i == 2) {
  66471. /* Test streaming API. */
  66472. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  66473. AAD_SIZE), SSL_SUCCESS);
  66474. }
  66475. else {
  66476. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  66477. AAD_SIZE);
  66478. }
  66479. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66480. DYNAMIC_TYPE_TMP_BUFFER));
  66481. /* Encrypt plaintext. */
  66482. if (i == 2) {
  66483. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  66484. plainTexts[j], plainTextSzs[j]),
  66485. SSL_SUCCESS);
  66486. }
  66487. else {
  66488. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  66489. plainTextSzs[j]), plainTextSzs[j]);
  66490. }
  66491. if (i == 2) {
  66492. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  66493. SSL_SUCCESS);
  66494. }
  66495. else {
  66496. /*
  66497. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  66498. * akin to calling EVP_CipherFinal.
  66499. */
  66500. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  66501. }
  66502. /* Check ciphertext against expected. */
  66503. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  66504. 0);
  66505. /* Get and check tag against expected. */
  66506. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  66507. sizeof(tag), tag), SSL_SUCCESS);
  66508. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  66509. /*************** Decrypt ***************/
  66510. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66511. currentIv), SSL_SUCCESS);
  66512. /* Check current IV against expected. */
  66513. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66514. /* Add AAD. */
  66515. if (i == 2) {
  66516. /* Test streaming API. */
  66517. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  66518. AAD_SIZE), SSL_SUCCESS);
  66519. }
  66520. else {
  66521. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  66522. AAD_SIZE);
  66523. }
  66524. /* Set expected tag. */
  66525. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  66526. sizeof(tag), tag), SSL_SUCCESS);
  66527. /* Decrypt ciphertext. */
  66528. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66529. DYNAMIC_TYPE_TMP_BUFFER));
  66530. if (i == 2) {
  66531. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  66532. cipherText, plainTextSzs[j]),
  66533. SSL_SUCCESS);
  66534. }
  66535. else {
  66536. /* This first EVP_Cipher call will check the tag, too. */
  66537. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  66538. plainTextSzs[j]), plainTextSzs[j]);
  66539. }
  66540. if (i == 2) {
  66541. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  66542. SSL_SUCCESS);
  66543. }
  66544. else {
  66545. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  66546. }
  66547. /* Check plaintext against expected. */
  66548. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  66549. 0);
  66550. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66551. cipherText = NULL;
  66552. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66553. calcPlainText = NULL;
  66554. }
  66555. EVP_CIPHER_CTX_free(encCtx);
  66556. encCtx = NULL;
  66557. EVP_CIPHER_CTX_free(decCtx);
  66558. decCtx = NULL;
  66559. }
  66560. #endif
  66561. return EXPECT_RESULT();
  66562. }
  66563. static int test_wolfSSL_OBJ_ln(void)
  66564. {
  66565. EXPECT_DECLS;
  66566. const int nid_set[] = {
  66567. NID_commonName,
  66568. NID_serialNumber,
  66569. NID_countryName,
  66570. NID_localityName,
  66571. NID_stateOrProvinceName,
  66572. NID_organizationName,
  66573. NID_organizationalUnitName,
  66574. NID_domainComponent,
  66575. NID_businessCategory,
  66576. NID_jurisdictionCountryName,
  66577. NID_jurisdictionStateOrProvinceName,
  66578. NID_emailAddress
  66579. };
  66580. const char* ln_set[] = {
  66581. "commonName",
  66582. "serialNumber",
  66583. "countryName",
  66584. "localityName",
  66585. "stateOrProvinceName",
  66586. "organizationName",
  66587. "organizationalUnitName",
  66588. "domainComponent",
  66589. "businessCategory",
  66590. "jurisdictionCountryName",
  66591. "jurisdictionStateOrProvinceName",
  66592. "emailAddress",
  66593. };
  66594. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  66595. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  66596. #ifdef HAVE_ECC
  66597. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  66598. {
  66599. EC_builtin_curve r[27];
  66600. size_t nCurves = sizeof(r) / sizeof(r[0]);
  66601. nCurves = EC_get_builtin_curves(r, nCurves);
  66602. for (i = 0; i < nCurves; i++) {
  66603. /* skip ECC_CURVE_INVALID */
  66604. if (r[i].nid != ECC_CURVE_INVALID) {
  66605. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  66606. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  66607. }
  66608. }
  66609. }
  66610. #endif
  66611. #endif
  66612. for (i = 0; i < maxIdx; i++) {
  66613. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  66614. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  66615. }
  66616. return EXPECT_RESULT();
  66617. }
  66618. static int test_wolfSSL_OBJ_sn(void)
  66619. {
  66620. EXPECT_DECLS;
  66621. int i = 0, maxIdx = 7;
  66622. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  66623. NID_stateOrProvinceName,NID_organizationName,
  66624. NID_organizationalUnitName,NID_emailAddress};
  66625. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  66626. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  66627. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  66628. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  66629. WOLFSSL_EMAIL_ADDR};
  66630. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  66631. for (i = 0; i < maxIdx; i++) {
  66632. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  66633. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  66634. }
  66635. return EXPECT_RESULT();
  66636. }
  66637. #if !defined(NO_BIO)
  66638. static unsigned long TXT_DB_hash(const WOLFSSL_STRING *s)
  66639. {
  66640. return lh_strhash(s[3]);
  66641. }
  66642. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  66643. {
  66644. return XSTRCMP(a[3], b[3]);
  66645. }
  66646. #endif
  66647. static int test_wolfSSL_TXT_DB(void)
  66648. {
  66649. EXPECT_DECLS;
  66650. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66651. BIO *bio = NULL;
  66652. TXT_DB *db = NULL;
  66653. const int columns = 6;
  66654. const char *fields[6] = {
  66655. "V",
  66656. "320926161116Z",
  66657. "",
  66658. "12BD",
  66659. "unknown",
  66660. "/CN=rsa doe",
  66661. };
  66662. char** fields_copy = NULL;
  66663. /* Test read */
  66664. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  66665. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  66666. ExpectNotNull(db = TXT_DB_read(bio, columns));
  66667. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  66668. DYNAMIC_TYPE_OPENSSL));
  66669. if (fields_copy != NULL) {
  66670. XMEMCPY(fields_copy, fields, sizeof(fields));
  66671. }
  66672. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  66673. if (EXPECT_FAIL()) {
  66674. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  66675. }
  66676. BIO_free(bio);
  66677. bio = NULL;
  66678. /* Test write */
  66679. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  66680. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  66681. BIO_free(bio);
  66682. /* Test index */
  66683. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)TXT_DB_hash,
  66684. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  66685. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66686. fields[3] = "12DA";
  66687. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66688. fields[3] = "FFFF";
  66689. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66690. fields[3] = "";
  66691. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66692. TXT_DB_free(db);
  66693. #endif
  66694. return EXPECT_RESULT();
  66695. }
  66696. static int test_wolfSSL_NCONF(void)
  66697. {
  66698. EXPECT_DECLS;
  66699. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66700. const char* confFile = "./tests/NCONF_test.cnf";
  66701. CONF* conf = NULL;
  66702. long eline = 0;
  66703. long num = 0;
  66704. ExpectNotNull(conf = NCONF_new(NULL));
  66705. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  66706. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  66707. ExpectIntEQ(num, 1234);
  66708. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  66709. ExpectIntEQ(num, 4321);
  66710. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  66711. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  66712. "./test-dir/file1");
  66713. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  66714. "./test-dir/file1:./test-dir/file2:./section1:file2");
  66715. NCONF_free(conf);
  66716. #endif
  66717. return EXPECT_RESULT();
  66718. }
  66719. #endif /* OPENSSL_ALL */
  66720. static int test_wolfSSL_X509V3_EXT_get(void) {
  66721. EXPECT_DECLS;
  66722. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66723. XFILE f = XBADFILE;
  66724. int numOfExt =0;
  66725. int extNid = 0;
  66726. int i = 0;
  66727. WOLFSSL_X509* x509 = NULL;
  66728. WOLFSSL_X509_EXTENSION* ext = NULL;
  66729. const WOLFSSL_v3_ext_method* method = NULL;
  66730. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66731. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66732. if (f != XBADFILE)
  66733. XFCLOSE(f);
  66734. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  66735. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66736. for (i = 0; i < numOfExt; i++) {
  66737. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66738. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  66739. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66740. ExpectIntEQ(method->ext_nid, extNid);
  66741. }
  66742. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  66743. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  66744. wolfSSL_X509_free(x509);
  66745. #endif
  66746. return EXPECT_RESULT();
  66747. }
  66748. static int test_wolfSSL_X509V3_EXT_nconf(void)
  66749. {
  66750. EXPECT_DECLS;
  66751. #ifdef OPENSSL_ALL
  66752. const char *ext_names[] = {
  66753. "subjectKeyIdentifier",
  66754. "authorityKeyIdentifier",
  66755. "subjectAltName",
  66756. "keyUsage",
  66757. "extendedKeyUsage",
  66758. };
  66759. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  66760. int ext_nids[] = {
  66761. NID_subject_key_identifier,
  66762. NID_authority_key_identifier,
  66763. NID_subject_alt_name,
  66764. NID_key_usage,
  66765. NID_ext_key_usage,
  66766. };
  66767. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  66768. const char *ext_values[] = {
  66769. "hash",
  66770. "hash",
  66771. "DNS:example.com, IP:127.0.0.1",
  66772. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  66773. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  66774. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  66775. "OCSPSigning",
  66776. };
  66777. size_t i;
  66778. X509_EXTENSION* ext = NULL;
  66779. X509* x509 = NULL;
  66780. unsigned int keyUsageFlags;
  66781. unsigned int extKeyUsageFlags;
  66782. ExpectNotNull(x509 = X509_new());
  66783. /* keyUsage / extKeyUsage should match string above */
  66784. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66785. | KU_NON_REPUDIATION
  66786. | KU_KEY_ENCIPHERMENT
  66787. | KU_DATA_ENCIPHERMENT
  66788. | KU_KEY_AGREEMENT
  66789. | KU_KEY_CERT_SIGN
  66790. | KU_CRL_SIGN
  66791. | KU_ENCIPHER_ONLY
  66792. | KU_DECIPHER_ONLY;
  66793. extKeyUsageFlags = XKU_SSL_CLIENT
  66794. | XKU_SSL_SERVER
  66795. | XKU_CODE_SIGN
  66796. | XKU_SMIME
  66797. | XKU_TIMESTAMP
  66798. | XKU_OCSP_SIGN;
  66799. for (i = 0; i < ext_names_count; i++) {
  66800. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66801. ext_values[i]));
  66802. X509_EXTENSION_free(ext);
  66803. ext = NULL;
  66804. }
  66805. for (i = 0; i < ext_nids_count; i++) {
  66806. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  66807. ext_values[i]));
  66808. X509_EXTENSION_free(ext);
  66809. ext = NULL;
  66810. }
  66811. /* Test adding extension to X509 */
  66812. for (i = 0; i < ext_nids_count; i++) {
  66813. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66814. ext_values[i]));
  66815. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  66816. if (ext_nids[i] == NID_key_usage) {
  66817. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66818. }
  66819. else if (ext_nids[i] == NID_ext_key_usage) {
  66820. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66821. }
  66822. X509_EXTENSION_free(ext);
  66823. ext = NULL;
  66824. }
  66825. X509_free(x509);
  66826. #endif
  66827. return EXPECT_RESULT();
  66828. }
  66829. static int test_wolfSSL_X509V3_EXT(void) {
  66830. EXPECT_DECLS;
  66831. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66832. XFILE f = XBADFILE;
  66833. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  66834. char* str = NULL;
  66835. unsigned char* data = NULL;
  66836. const WOLFSSL_v3_ext_method* method = NULL;
  66837. WOLFSSL_X509* x509 = NULL;
  66838. WOLFSSL_X509_EXTENSION* ext = NULL;
  66839. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  66840. WOLFSSL_ASN1_OBJECT *obj = NULL;
  66841. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  66842. WOLFSSL_ASN1_STRING* asn1str = NULL;
  66843. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  66844. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  66845. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  66846. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  66847. WOLFSSL_GENERAL_NAME* gn = NULL;
  66848. /* Check NULL argument */
  66849. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  66850. /* Using OCSP cert with X509V3 extensions */
  66851. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  66852. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66853. if (f != XBADFILE)
  66854. XFCLOSE(f);
  66855. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66856. /* Basic Constraints */
  66857. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66858. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66859. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  66860. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  66861. ExpectIntEQ(bc->ca, 1);
  66862. ExpectNull(bc->pathlen);
  66863. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  66864. bc = NULL;
  66865. i++;
  66866. /* Subject Key Identifier */
  66867. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66868. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66869. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  66870. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66871. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  66872. asn1str));
  66873. X509_EXTENSION_free(ext2);
  66874. ext2 = NULL;
  66875. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66876. ExpectNotNull(method->i2s);
  66877. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  66878. wolfSSL_ASN1_STRING_free(asn1str);
  66879. asn1str = NULL;
  66880. if (str != NULL) {
  66881. actual = strcmp(str,
  66882. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66883. }
  66884. ExpectIntEQ(actual, 0);
  66885. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66886. str = NULL;
  66887. i++;
  66888. /* Authority Key Identifier */
  66889. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66890. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66891. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  66892. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  66893. ext));
  66894. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66895. ExpectNotNull(asn1str = aKeyId->keyid);
  66896. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  66897. asn1str));
  66898. asn1str = NULL;
  66899. if (str != NULL) {
  66900. actual = strcmp(str,
  66901. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66902. }
  66903. ExpectIntEQ(actual, 0);
  66904. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66905. str = NULL;
  66906. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  66907. aKeyId = NULL;
  66908. i++;
  66909. /* Key Usage */
  66910. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66911. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66912. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  66913. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66914. #if defined(WOLFSSL_QT)
  66915. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  66916. #else
  66917. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  66918. #endif
  66919. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  66920. if (data != NULL) {
  66921. #ifdef BIG_ENDIAN_ORDER
  66922. actual = data[1];
  66923. #else
  66924. actual = data[0];
  66925. #endif
  66926. }
  66927. ExpectIntEQ(actual, expected);
  66928. wolfSSL_ASN1_STRING_free(asn1str);
  66929. asn1str = NULL;
  66930. #if 1
  66931. i++;
  66932. /* Authority Info Access */
  66933. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66934. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66935. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  66936. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  66937. ext));
  66938. #if defined(WOLFSSL_QT)
  66939. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66940. #else
  66941. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66942. #endif
  66943. /* URI entry is an ACCESS_DESCRIPTION type */
  66944. #if defined(WOLFSSL_QT)
  66945. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  66946. #else
  66947. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  66948. #endif
  66949. ExpectNotNull(adObj = ad->method);
  66950. /* Make sure nid is OCSP */
  66951. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  66952. /* GENERAL_NAME stores URI as an ASN1_STRING */
  66953. ExpectNotNull(gn = ad->location);
  66954. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  66955. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  66956. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  66957. #if defined(WOLFSSL_QT)
  66958. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  66959. #else
  66960. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  66961. #endif
  66962. if (str != NULL) {
  66963. actual = strcmp(str, "http://127.0.0.1:22220");
  66964. }
  66965. ExpectIntEQ(actual, 0);
  66966. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  66967. aia = NULL;
  66968. #else
  66969. (void) aia; (void) ad; (void) adObj; (void) gn;
  66970. #endif
  66971. wolfSSL_X509_free(x509);
  66972. #endif
  66973. return EXPECT_RESULT();
  66974. }
  66975. static int test_wolfSSL_X509_get_extension_flags(void)
  66976. {
  66977. EXPECT_DECLS;
  66978. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66979. XFILE f = XBADFILE;
  66980. X509* x509 = NULL;
  66981. unsigned int extFlags;
  66982. unsigned int keyUsageFlags;
  66983. unsigned int extKeyUsageFlags;
  66984. /* client-int-cert.pem has the following extension flags. */
  66985. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  66986. /* and the following key usage flags. */
  66987. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66988. | KU_NON_REPUDIATION
  66989. | KU_KEY_ENCIPHERMENT;
  66990. /* and the following extended key usage flags. */
  66991. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  66992. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  66993. XBADFILE);
  66994. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66995. if (f != XBADFILE) {
  66996. XFCLOSE(f);
  66997. f = XBADFILE;
  66998. }
  66999. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  67000. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67001. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  67002. X509_free(x509);
  67003. x509 = NULL;
  67004. /* client-cert-ext.pem has the following extension flags. */
  67005. extFlags = EXFLAG_KUSAGE;
  67006. /* and the following key usage flags. */
  67007. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67008. | KU_KEY_CERT_SIGN
  67009. | KU_CRL_SIGN;
  67010. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  67011. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67012. if (f != XBADFILE)
  67013. XFCLOSE(f);
  67014. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  67015. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67016. X509_free(x509);
  67017. #endif /* OPENSSL_ALL */
  67018. return EXPECT_RESULT();
  67019. }
  67020. static int test_wolfSSL_X509_get_ext(void)
  67021. {
  67022. EXPECT_DECLS;
  67023. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67024. int ret = 0;
  67025. XFILE f = XBADFILE;
  67026. WOLFSSL_X509* x509 = NULL;
  67027. WOLFSSL_X509_EXTENSION* foundExtension;
  67028. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67029. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67030. if (f != XBADFILE)
  67031. XFCLOSE(f);
  67032. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  67033. /* wolfSSL_X509_get_ext() valid input */
  67034. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  67035. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  67036. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  67037. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  67038. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  67039. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  67040. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  67041. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  67042. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  67043. wolfSSL_X509_free(x509);
  67044. #endif
  67045. return EXPECT_RESULT();
  67046. }
  67047. static int test_wolfSSL_X509_get_ext_by_NID(void)
  67048. {
  67049. EXPECT_DECLS;
  67050. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67051. int rc = 0;
  67052. XFILE f = XBADFILE;
  67053. WOLFSSL_X509* x509 = NULL;
  67054. ASN1_OBJECT* obj = NULL;
  67055. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67056. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67057. if (f != XBADFILE)
  67058. XFCLOSE(f);
  67059. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67060. -1), 0);
  67061. /* Start search from last location (should fail) */
  67062. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67063. rc), -1);
  67064. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67065. -2), -1);
  67066. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  67067. -1), -1);
  67068. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  67069. /* NID_ext_key_usage, check also its nid and oid */
  67070. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  67071. -1);
  67072. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  67073. x509, rc)));
  67074. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  67075. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  67076. wolfSSL_X509_free(x509);
  67077. #endif
  67078. return EXPECT_RESULT();
  67079. }
  67080. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  67081. {
  67082. EXPECT_DECLS;
  67083. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67084. int rc = 0;
  67085. XFILE f = XBADFILE;
  67086. WOLFSSL_X509* x509 = NULL;
  67087. WOLFSSL_X509_EXTENSION* ext = NULL;
  67088. WOLFSSL_ASN1_STRING* sanString = NULL;
  67089. byte* sanDer = NULL;
  67090. const byte expectedDer[] = {
  67091. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  67092. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  67093. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67094. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67095. if (f != XBADFILE)
  67096. XFCLOSE(f);
  67097. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  67098. ExpectNotNull(ext = X509_get_ext(x509, rc));
  67099. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  67100. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  67101. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  67102. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  67103. X509_free(x509);
  67104. #endif
  67105. return EXPECT_RESULT();
  67106. }
  67107. static int test_wolfSSL_X509_EXTENSION_new(void)
  67108. {
  67109. EXPECT_DECLS;
  67110. #if defined (OPENSSL_ALL)
  67111. WOLFSSL_X509_EXTENSION* ext = NULL;
  67112. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  67113. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  67114. wolfSSL_X509_EXTENSION_free(ext);
  67115. #endif
  67116. return EXPECT_RESULT();
  67117. }
  67118. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  67119. {
  67120. EXPECT_DECLS;
  67121. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67122. WOLFSSL_X509* x509 = NULL;
  67123. WOLFSSL_X509_EXTENSION* ext = NULL;
  67124. WOLFSSL_ASN1_OBJECT* o = NULL;
  67125. XFILE file = XBADFILE;
  67126. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67127. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67128. if (file != XBADFILE)
  67129. XFCLOSE(file);
  67130. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  67131. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67132. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  67133. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  67134. ExpectIntEQ(o->nid, 128);
  67135. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  67136. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  67137. wolfSSL_X509_free(x509);
  67138. #endif
  67139. return EXPECT_RESULT();
  67140. }
  67141. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  67142. {
  67143. EXPECT_DECLS;
  67144. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67145. WOLFSSL_X509* x509 = NULL;
  67146. WOLFSSL_X509_EXTENSION* ext = NULL;
  67147. WOLFSSL_ASN1_STRING* str = NULL;
  67148. XFILE file = XBADFILE;
  67149. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67150. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67151. if (file != XBADFILE)
  67152. XFCLOSE(file);
  67153. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67154. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  67155. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  67156. wolfSSL_X509_free(x509);
  67157. #endif
  67158. return EXPECT_RESULT();
  67159. }
  67160. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  67161. {
  67162. EXPECT_DECLS;
  67163. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67164. WOLFSSL_X509* x509 = NULL;
  67165. WOLFSSL_X509_EXTENSION* ext = NULL;
  67166. XFILE file = XBADFILE;
  67167. int crit = 0;
  67168. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67169. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67170. if (file != XBADFILE)
  67171. XFCLOSE(file);
  67172. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67173. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67174. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  67175. wolfSSL_X509_free(x509);
  67176. #endif
  67177. return EXPECT_RESULT();
  67178. }
  67179. static int test_wolfSSL_X509V3_EXT_print(void)
  67180. {
  67181. EXPECT_DECLS;
  67182. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  67183. !defined(NO_RSA)
  67184. {
  67185. XFILE f = XBADFILE;
  67186. WOLFSSL_X509* x509 = NULL;
  67187. X509_EXTENSION * ext = NULL;
  67188. int loc = 0;
  67189. BIO *bio = NULL;
  67190. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  67191. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67192. if (f != XBADFILE)
  67193. fclose(f);
  67194. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  67195. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  67196. NID_basic_constraints, -1), -1);
  67197. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  67198. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  67199. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  67200. NID_subject_key_identifier, -1), -1);
  67201. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  67202. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  67203. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  67204. NID_authority_key_identifier, -1), -1);
  67205. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  67206. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  67207. wolfSSL_BIO_free(bio);
  67208. wolfSSL_X509_free(x509);
  67209. }
  67210. {
  67211. X509 *x509 = NULL;
  67212. BIO *bio = NULL;
  67213. X509_EXTENSION *ext = NULL;
  67214. unsigned int i = 0;
  67215. unsigned int idx = 0;
  67216. /* Some NIDs to test with */
  67217. int nids[] = {
  67218. /* NID_key_usage, currently X509_get_ext returns this as a bit
  67219. * string, which messes up X509V3_EXT_print */
  67220. /* NID_ext_key_usage, */
  67221. NID_subject_alt_name,
  67222. };
  67223. int* n = NULL;
  67224. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  67225. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  67226. WOLFSSL_FILETYPE_PEM));
  67227. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  67228. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  67229. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  67230. * update the index */
  67231. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  67232. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  67233. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  67234. ExpectIntGT(fprintf(stderr, "\n"), 0);
  67235. }
  67236. BIO_free(bio);
  67237. X509_free(x509);
  67238. }
  67239. #endif
  67240. return EXPECT_RESULT();
  67241. }
  67242. static int test_wolfSSL_X509_cmp(void)
  67243. {
  67244. EXPECT_DECLS;
  67245. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67246. XFILE file1 = XBADFILE;
  67247. XFILE file2 = XBADFILE;
  67248. WOLFSSL_X509* cert1 = NULL;
  67249. WOLFSSL_X509* cert2 = NULL;
  67250. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67251. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  67252. XBADFILE);
  67253. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  67254. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  67255. if (file1 != XBADFILE)
  67256. fclose(file1);
  67257. if (file2 != XBADFILE)
  67258. fclose(file2);
  67259. /* wolfSSL_X509_cmp() testing matching certs */
  67260. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  67261. /* wolfSSL_X509_cmp() testing mismatched certs */
  67262. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  67263. /* wolfSSL_X509_cmp() testing NULL, valid args */
  67264. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  67265. /* wolfSSL_X509_cmp() testing valid, NULL args */
  67266. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  67267. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  67268. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  67269. wolfSSL_X509_free(cert1);
  67270. wolfSSL_X509_free(cert2);
  67271. #endif
  67272. return EXPECT_RESULT();
  67273. }
  67274. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  67275. {
  67276. EXPECT_DECLS;
  67277. #if defined(OPENSSL_ALL)
  67278. EVP_PKEY* pkey;
  67279. pkey = EVP_PKEY_new();
  67280. ExpectNotNull(pkey);
  67281. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  67282. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67283. EVP_PKEY_free(pkey);
  67284. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67285. EVP_PKEY_free(pkey);
  67286. EVP_PKEY_free(pkey);
  67287. #endif
  67288. return EXPECT_RESULT();
  67289. }
  67290. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  67291. {
  67292. EXPECT_DECLS;
  67293. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  67294. EVP_PKEY* pkey = NULL;
  67295. const unsigned char* p;
  67296. unsigned char *der = NULL;
  67297. unsigned char *tmp = NULL;
  67298. int derLen;
  67299. p = client_keypub_der_2048;
  67300. /* Check that key can be successfully decoded. */
  67301. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  67302. sizeof_client_keypub_der_2048));
  67303. /* Check that key can be successfully encoded. */
  67304. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67305. /* Ensure that the encoded version matches the original. */
  67306. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67307. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67308. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67309. * is advanced. */
  67310. tmp = der;
  67311. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67312. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67313. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67314. ExpectTrue(der + derLen == tmp);
  67315. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67316. EVP_PKEY_free(pkey);
  67317. #endif
  67318. return EXPECT_RESULT();
  67319. }
  67320. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  67321. {
  67322. EXPECT_DECLS;
  67323. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  67324. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67325. EVP_PKEY* pkey = NULL;
  67326. const unsigned char* p;
  67327. unsigned char *der = NULL;
  67328. unsigned char *tmp = NULL;
  67329. int derLen;
  67330. unsigned char pub_buf[65];
  67331. const int pub_len = 65;
  67332. BN_CTX* ctx;
  67333. EC_GROUP* curve = NULL;
  67334. EC_KEY* ephemeral_key = NULL;
  67335. const EC_POINT* h = NULL;
  67336. /* Generate an x963 key pair and get public part into pub_buf */
  67337. ExpectNotNull(ctx = BN_CTX_new());
  67338. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  67339. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  67340. NID_X9_62_prime256v1));
  67341. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  67342. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  67343. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  67344. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  67345. /* Prepare the EVP_PKEY */
  67346. ExpectNotNull(pkey = EVP_PKEY_new());
  67347. p = pub_buf;
  67348. /* Check that key can be successfully decoded. */
  67349. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  67350. pub_len));
  67351. /* Check that key can be successfully encoded. */
  67352. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67353. /* Ensure that the encoded version matches the original. */
  67354. ExpectIntEQ(derLen, pub_len);
  67355. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67356. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67357. * is advanced. */
  67358. tmp = der;
  67359. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67360. ExpectIntEQ(derLen, pub_len);
  67361. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67362. ExpectTrue(der + derLen == tmp);
  67363. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67364. EVP_PKEY_free(pkey);
  67365. EC_KEY_free(ephemeral_key);
  67366. EC_GROUP_free(curve);
  67367. #endif
  67368. return EXPECT_RESULT();
  67369. }
  67370. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  67371. {
  67372. EXPECT_DECLS;
  67373. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  67374. DSA* dsa = NULL;
  67375. byte derIn[] = {
  67376. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  67377. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  67378. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  67379. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  67380. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  67381. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  67382. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  67383. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  67384. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  67385. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  67386. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  67387. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  67388. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  67389. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  67390. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  67391. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  67392. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  67393. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  67394. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  67395. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  67396. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  67397. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  67398. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  67399. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  67400. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  67401. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  67402. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  67403. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  67404. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  67405. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  67406. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  67407. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  67408. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  67409. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  67410. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  67411. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  67412. 0x1e, 0xde, 0xc4
  67413. };
  67414. int derInLen = sizeof(derIn);
  67415. byte* derOut = NULL;
  67416. int derOutLen;
  67417. byte* p = derIn;
  67418. /* Check that params can be successfully decoded. */
  67419. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  67420. /* Check that params can be successfully encoded. */
  67421. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  67422. /* Ensure that the encoded version matches the original. */
  67423. ExpectIntEQ(derInLen, derOutLen);
  67424. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  67425. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67426. DSA_free(dsa);
  67427. #endif
  67428. return EXPECT_RESULT();
  67429. }
  67430. static int test_wolfSSL_i2d_PrivateKey(void)
  67431. {
  67432. EXPECT_DECLS;
  67433. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  67434. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67435. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  67436. {
  67437. EVP_PKEY* pkey = NULL;
  67438. const unsigned char* server_key =
  67439. (const unsigned char*)server_key_der_2048;
  67440. unsigned char buf[FOURK_BUF];
  67441. unsigned char* pt = NULL;
  67442. int bufSz = 0;
  67443. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  67444. (long)sizeof_server_key_der_2048));
  67445. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  67446. pt = buf;
  67447. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  67448. ExpectIntNE((pt - buf), 0);
  67449. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  67450. EVP_PKEY_free(pkey);
  67451. }
  67452. #endif
  67453. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  67454. {
  67455. EVP_PKEY* pkey = NULL;
  67456. const unsigned char* client_key =
  67457. (const unsigned char*)ecc_clikey_der_256;
  67458. unsigned char buf[FOURK_BUF];
  67459. unsigned char* pt = NULL;
  67460. int bufSz = 0;
  67461. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  67462. (long)sizeof_ecc_clikey_der_256)));
  67463. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  67464. pt = buf;
  67465. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  67466. ExpectIntNE((pt - buf), 0);
  67467. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  67468. EVP_PKEY_free(pkey);
  67469. }
  67470. #endif
  67471. #endif
  67472. return EXPECT_RESULT();
  67473. }
  67474. static int test_wolfSSL_OCSP_id_get0_info(void)
  67475. {
  67476. EXPECT_DECLS;
  67477. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  67478. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  67479. X509* cert = NULL;
  67480. X509* issuer = NULL;
  67481. OCSP_CERTID* id = NULL;
  67482. OCSP_CERTID* id2 = NULL;
  67483. ASN1_STRING* name = NULL;
  67484. ASN1_OBJECT* pmd = NULL;
  67485. ASN1_STRING* keyHash = NULL;
  67486. ASN1_INTEGER* serial = NULL;
  67487. ASN1_INTEGER* x509Int = NULL;
  67488. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  67489. SSL_FILETYPE_PEM));
  67490. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  67491. SSL_FILETYPE_PEM));
  67492. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  67493. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  67494. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  67495. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  67496. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  67497. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  67498. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  67499. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  67500. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  67501. ExpectNotNull(serial);
  67502. /* compare serial number to one in cert, should be equal */
  67503. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  67504. ExpectIntEQ(x509Int->length, serial->length);
  67505. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  67506. /* test OCSP_id_cmp */
  67507. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67508. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  67509. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  67510. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  67511. if (id != NULL) {
  67512. id->issuerHash[0] = ~id->issuerHash[0];
  67513. }
  67514. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  67515. OCSP_CERTID_free(id);
  67516. OCSP_CERTID_free(id2);
  67517. X509_free(cert); /* free's x509Int */
  67518. X509_free(issuer);
  67519. #endif
  67520. return EXPECT_RESULT();
  67521. }
  67522. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  67523. {
  67524. EXPECT_DECLS;
  67525. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67526. WOLFSSL_OCSP_CERTID certId;
  67527. byte* targetBuffer = NULL;
  67528. byte* p;
  67529. /* OCSP CertID bytes taken from PCAP */
  67530. byte rawCertId[] = {
  67531. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67532. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67533. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67534. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67535. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67536. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67537. 0xcf, 0xbc, 0x91
  67538. };
  67539. int ret = 0;
  67540. int i;
  67541. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  67542. certId.rawCertId = rawCertId;
  67543. certId.rawCertIdSize = sizeof(rawCertId);
  67544. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  67545. DYNAMIC_TYPE_TMP_BUFFER));
  67546. p = targetBuffer;
  67547. /* Function returns the size of the encoded data. */
  67548. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  67549. /* If target buffer is not null, function increments targetBuffer to point
  67550. * just past the end of the encoded data. */
  67551. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  67552. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67553. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67554. }
  67555. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67556. targetBuffer = NULL;
  67557. /* If target buffer is null, function allocates memory for a buffer and
  67558. * copies the encoded data into it. targetBuffer then points to the start of
  67559. * this newly allocate buffer. */
  67560. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  67561. sizeof(rawCertId));
  67562. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67563. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67564. }
  67565. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  67566. #endif
  67567. return EXPECT_RESULT();
  67568. }
  67569. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  67570. {
  67571. EXPECT_DECLS;
  67572. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67573. WOLFSSL_OCSP_CERTID* certId;
  67574. WOLFSSL_OCSP_CERTID* certIdGood;
  67575. WOLFSSL_OCSP_CERTID* certIdBad;
  67576. const unsigned char* rawCertIdPtr;
  67577. const unsigned char rawCertId[] = {
  67578. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67579. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67580. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67581. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67582. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67583. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67584. 0xcf, 0xbc, 0x91
  67585. };
  67586. rawCertIdPtr = &rawCertId[0];
  67587. /* If the cert ID is NULL the function should allocate it and copy the
  67588. * data to it. */
  67589. certId = NULL;
  67590. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67591. sizeof(rawCertId)));
  67592. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67593. if (certId != NULL) {
  67594. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67595. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  67596. }
  67597. /* If the cert ID is not NULL the function will just copy the data to it. */
  67598. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  67599. DYNAMIC_TYPE_TMP_BUFFER));
  67600. ExpectNotNull(certId);
  67601. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  67602. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  67603. rawCertIdPtr = &rawCertId[0];
  67604. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67605. sizeof(rawCertId)));
  67606. ExpectPtrEq(certIdGood, certId);
  67607. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67608. if (certId != NULL) {
  67609. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67610. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67611. certId = NULL;
  67612. }
  67613. /* The below tests should fail when passed bad parameters. NULL should
  67614. * always be returned. */
  67615. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  67616. sizeof(rawCertId)));
  67617. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  67618. sizeof(rawCertId)));
  67619. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  67620. #endif
  67621. return EXPECT_RESULT();
  67622. }
  67623. static int test_wolfSSL_OCSP_id_cmp(void)
  67624. {
  67625. EXPECT_DECLS;
  67626. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  67627. OCSP_CERTID id1;
  67628. OCSP_CERTID id2;
  67629. XMEMSET(&id1, 0, sizeof(id1));
  67630. XMEMSET(&id2, 0, sizeof(id2));
  67631. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  67632. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67633. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  67634. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  67635. #endif
  67636. return EXPECT_RESULT();
  67637. }
  67638. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  67639. {
  67640. EXPECT_DECLS;
  67641. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67642. WOLFSSL_OCSP_SINGLERESP single;
  67643. const WOLFSSL_OCSP_CERTID* certId;
  67644. XMEMSET(&single, 0, sizeof(single));
  67645. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  67646. ExpectPtrEq(&single, certId);
  67647. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  67648. #endif
  67649. return EXPECT_RESULT();
  67650. }
  67651. static int test_wolfSSL_OCSP_single_get0_status(void)
  67652. {
  67653. EXPECT_DECLS;
  67654. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  67655. defined(WOLFSSL_OCSP_PARSE_STATUS)
  67656. WOLFSSL_OCSP_SINGLERESP single;
  67657. CertStatus certStatus;
  67658. WOLFSSL_ASN1_TIME* thisDate;
  67659. WOLFSSL_ASN1_TIME* nextDate;
  67660. int ret, i;
  67661. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67662. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  67663. /* Fill the date fields with some dummy data. */
  67664. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  67665. certStatus.thisDateParsed.data[i] = i;
  67666. certStatus.nextDateParsed.data[i] = i;
  67667. }
  67668. certStatus.status = CERT_GOOD;
  67669. single.status = &certStatus;
  67670. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  67671. &nextDate);
  67672. ExpectIntEQ(ret, CERT_GOOD);
  67673. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  67674. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  67675. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  67676. CERT_GOOD);
  67677. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  67678. NULL), CERT_GOOD);
  67679. #endif
  67680. return EXPECT_RESULT();
  67681. }
  67682. static int test_wolfSSL_OCSP_resp_count(void)
  67683. {
  67684. EXPECT_DECLS;
  67685. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67686. WOLFSSL_OCSP_BASICRESP basicResp;
  67687. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67688. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67689. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67690. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67691. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67692. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  67693. basicResp.single = &singleRespOne;
  67694. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  67695. singleRespOne.next = &singleRespTwo;
  67696. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  67697. #endif
  67698. return EXPECT_RESULT();
  67699. }
  67700. static int test_wolfSSL_OCSP_resp_get0(void)
  67701. {
  67702. EXPECT_DECLS;
  67703. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67704. WOLFSSL_OCSP_BASICRESP basicResp;
  67705. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67706. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67707. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67708. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67709. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67710. basicResp.single = &singleRespOne;
  67711. singleRespOne.next = &singleRespTwo;
  67712. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  67713. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  67714. #endif
  67715. return EXPECT_RESULT();
  67716. }
  67717. static int test_wolfSSL_OCSP_parse_url(void)
  67718. {
  67719. EXPECT_DECLS;
  67720. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  67721. #define CK_OPU_OK(u, h, po, pa, s) do { \
  67722. char* host = NULL; \
  67723. char* port = NULL; \
  67724. char* path = NULL; \
  67725. int isSsl = 0; \
  67726. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  67727. ExpectStrEQ(host, h); \
  67728. ExpectStrEQ(port, po); \
  67729. ExpectStrEQ(path, pa); \
  67730. ExpectIntEQ(isSsl, s); \
  67731. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67732. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67733. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67734. } while(0)
  67735. #define CK_OPU_FAIL(u) do { \
  67736. char* host = NULL; \
  67737. char* port = NULL; \
  67738. char* path = NULL; \
  67739. int isSsl = 0; \
  67740. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  67741. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67742. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67743. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67744. } while(0)
  67745. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  67746. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  67747. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  67748. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  67749. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  67750. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  67751. CK_OPU_FAIL("ftp://localhost");
  67752. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  67753. CK_OPU_FAIL("http/""/localhost");
  67754. CK_OPU_FAIL("http:/localhost");
  67755. CK_OPU_FAIL("https://localhost/path:1234");
  67756. #undef CK_OPU_OK
  67757. #undef CK_OPU_FAIL
  67758. #endif
  67759. return EXPECT_RESULT();
  67760. }
  67761. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67762. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67763. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  67764. {
  67765. if (t != NULL) {
  67766. *t = 1722006780;
  67767. }
  67768. return 1722006780;
  67769. }
  67770. #endif
  67771. static int test_wolfSSL_OCSP_REQ_CTX(void)
  67772. {
  67773. EXPECT_DECLS;
  67774. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67775. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67776. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  67777. * response was captured in wireshark. It contains both the http and binary
  67778. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  67779. * the time check passes. */
  67780. unsigned char ocspRespBin[] = {
  67781. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  67782. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  67783. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  67784. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  67785. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  67786. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  67787. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  67788. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  67789. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  67790. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  67791. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  67792. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  67793. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  67794. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67795. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  67796. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  67797. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  67798. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  67799. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  67800. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  67801. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  67802. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  67803. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  67804. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  67805. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  67806. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  67807. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  67808. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  67809. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  67810. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  67811. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  67812. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  67813. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  67814. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67815. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  67816. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  67817. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  67818. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  67819. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  67820. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  67821. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  67822. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  67823. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  67824. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  67825. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  67826. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  67827. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  67828. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  67829. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  67830. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  67831. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  67832. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  67833. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  67834. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  67835. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  67836. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  67837. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  67838. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  67839. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67840. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  67841. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  67842. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  67843. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  67844. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  67845. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  67846. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  67847. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  67848. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  67849. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  67850. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  67851. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  67852. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  67853. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  67854. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  67855. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  67856. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  67857. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  67858. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  67859. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  67860. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  67861. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  67862. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  67863. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  67864. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  67865. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  67866. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  67867. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67868. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67869. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  67870. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  67871. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  67872. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  67873. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  67874. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  67875. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  67876. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  67877. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  67878. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  67879. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  67880. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  67881. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  67882. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  67883. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  67884. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  67885. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  67886. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  67887. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  67888. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  67889. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  67890. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  67891. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  67892. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  67893. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  67894. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  67895. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  67896. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  67897. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  67898. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  67899. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  67900. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  67901. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  67902. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  67903. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  67904. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  67905. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  67906. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67907. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  67908. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  67909. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  67910. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  67911. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  67912. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67913. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67914. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  67915. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  67916. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  67917. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  67918. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  67919. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  67920. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  67921. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  67922. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  67923. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  67924. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  67925. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  67926. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  67927. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  67928. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  67929. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  67930. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  67931. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  67932. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  67933. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  67934. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  67935. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  67936. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  67937. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  67938. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  67939. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  67940. };
  67941. OCSP_REQ_CTX *ctx = NULL;
  67942. OCSP_REQUEST *req = NULL;
  67943. OCSP_CERTID *cid = NULL;
  67944. OCSP_RESPONSE *rsp = NULL;
  67945. BIO* bio1 = NULL;
  67946. BIO* bio2 = NULL;
  67947. X509* cert = NULL;
  67948. X509 *issuer = NULL;
  67949. X509_LOOKUP *lookup = NULL;
  67950. X509_STORE *store = NULL;
  67951. STACK_OF(X509_OBJECT) *str_objs = NULL;
  67952. X509_OBJECT *x509_obj = NULL;
  67953. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  67954. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  67955. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  67956. /* Load the leaf cert */
  67957. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  67958. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  67959. ExpectNotNull(store = X509_STORE_new());
  67960. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  67961. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  67962. X509_FILETYPE_PEM), 1);
  67963. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  67964. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  67965. X509_LU_X509, X509_get_issuer_name(cert)));
  67966. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  67967. ExpectNotNull(req = OCSP_REQUEST_new());
  67968. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  67969. ExpectNotNull(OCSP_request_add0_id(req, cid));
  67970. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  67971. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  67972. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  67973. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  67974. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  67975. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  67976. sizeof(ocspRespBin));
  67977. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  67978. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  67979. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  67980. ExpectNotNull(rsp);
  67981. OCSP_REQ_CTX_free(ctx);
  67982. OCSP_REQUEST_free(req);
  67983. OCSP_RESPONSE_free(rsp);
  67984. BIO_free(bio1);
  67985. BIO_free(bio2);
  67986. X509_free(cert);
  67987. X509_STORE_free(store);
  67988. #endif
  67989. return EXPECT_RESULT();
  67990. }
  67991. static int test_wolfSSL_EVP_PKEY_derive(void)
  67992. {
  67993. EXPECT_DECLS;
  67994. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  67995. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  67996. EVP_PKEY_CTX *ctx = NULL;
  67997. unsigned char *skey = NULL;
  67998. size_t skeylen;
  67999. EVP_PKEY *pkey = NULL;
  68000. EVP_PKEY *peerkey = NULL;
  68001. const unsigned char* key;
  68002. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  68003. /* DH */
  68004. key = dh_key_der_2048;
  68005. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68006. sizeof_dh_key_der_2048)));
  68007. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  68008. key = dh_key_der_2048;
  68009. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68010. sizeof_dh_key_der_2048)));
  68011. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  68012. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68013. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68014. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68015. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68016. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68017. DYNAMIC_TYPE_OPENSSL));
  68018. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68019. EVP_PKEY_CTX_free(ctx);
  68020. ctx = NULL;
  68021. EVP_PKEY_free(peerkey);
  68022. peerkey = NULL;
  68023. EVP_PKEY_free(pkey);
  68024. pkey = NULL;
  68025. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68026. skey = NULL;
  68027. #endif
  68028. #ifdef HAVE_ECC
  68029. /* ECDH */
  68030. key = ecc_clikey_der_256;
  68031. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  68032. sizeof_ecc_clikey_der_256)));
  68033. key = ecc_clikeypub_der_256;
  68034. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  68035. sizeof_ecc_clikeypub_der_256)));
  68036. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68037. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68038. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68039. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68040. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68041. DYNAMIC_TYPE_OPENSSL));
  68042. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68043. EVP_PKEY_CTX_free(ctx);
  68044. EVP_PKEY_free(peerkey);
  68045. EVP_PKEY_free(pkey);
  68046. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68047. #endif /* HAVE_ECC */
  68048. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  68049. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  68050. return EXPECT_RESULT();
  68051. }
  68052. static int test_wolfSSL_EVP_PBE_scrypt(void)
  68053. {
  68054. EXPECT_DECLS;
  68055. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  68056. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  68057. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  68058. int ret;
  68059. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  68060. int pwdlen = sizeof(pwd);
  68061. const byte salt[] = {'N','a','C','l'};
  68062. int saltlen = sizeof(salt);
  68063. byte key[80];
  68064. word64 numOvr32 = (word64)INT32_MAX + 1;
  68065. /* expected derived key for N:16, r:1, p:1 */
  68066. const byte expectedKey[] = {
  68067. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  68068. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  68069. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  68070. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  68071. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  68072. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  68073. 0xE7, 0xE9, 0xC0, 0x9A};
  68074. /* N r p mx key keylen */
  68075. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  68076. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  68077. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  68078. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  68079. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  68080. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  68081. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  68082. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  68083. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  68084. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  68085. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  68086. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  68087. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  68088. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  68089. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  68090. ExpectIntEQ(ret, 1); /* should succeed */
  68091. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  68092. key, 64);
  68093. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  68094. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  68095. key, 64);
  68096. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  68097. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  68098. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  68099. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  68100. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  68101. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  68102. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  68103. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  68104. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  68105. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  68106. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  68107. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  68108. ExpectIntEQ(ret, 1);
  68109. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  68110. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  68111. #endif /* !NO_PWDBASED && !NO_SHA256 */
  68112. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  68113. return EXPECT_RESULT();
  68114. }
  68115. static int test_no_op_functions(void)
  68116. {
  68117. EXPECT_DECLS;
  68118. #if defined(OPENSSL_EXTRA)
  68119. /* this makes sure wolfSSL can compile and run these no-op functions */
  68120. SSL_load_error_strings();
  68121. ENGINE_load_builtin_engines();
  68122. OpenSSL_add_all_ciphers();
  68123. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  68124. #endif
  68125. return EXPECT_RESULT();
  68126. }
  68127. static int test_wolfSSL_CRYPTO_memcmp(void)
  68128. {
  68129. EXPECT_DECLS;
  68130. #ifdef OPENSSL_EXTRA
  68131. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68132. "implementation of TLS/SSL for embedded devices to the cloud.";
  68133. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68134. "implementation of TLS/SSL for embedded devices to the cloud.";
  68135. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68136. "implementation of TLS/SSL for embedded devices to the cloud!";
  68137. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  68138. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  68139. #endif
  68140. return EXPECT_RESULT();
  68141. }
  68142. /*----------------------------------------------------------------------------*
  68143. | wolfCrypt ASN
  68144. *----------------------------------------------------------------------------*/
  68145. static int test_wc_CreateEncryptedPKCS8Key(void)
  68146. {
  68147. EXPECT_DECLS;
  68148. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  68149. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  68150. !defined(NO_ASN_CRYPT)
  68151. WC_RNG rng;
  68152. byte* encKey = NULL;
  68153. word32 encKeySz = 0;
  68154. word32 decKeySz = 0;
  68155. const char password[] = "Lorem ipsum dolor sit amet";
  68156. word32 passwordSz = (word32)XSTRLEN(password);
  68157. word32 tradIdx = 0;
  68158. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68159. ExpectIntEQ(wc_InitRng(&rng), 0);
  68160. PRIVATE_KEY_UNLOCK();
  68161. /* Call with NULL for out buffer to get necessary length. */
  68162. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68163. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  68164. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68165. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  68166. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  68167. DYNAMIC_TYPE_TMP_BUFFER));
  68168. /* Call with the allocated out buffer. */
  68169. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68170. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  68171. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68172. 0);
  68173. /* Decrypt the encrypted PKCS8 key we just made. */
  68174. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  68175. (int)passwordSz)), 0);
  68176. /* encKey now holds the decrypted key (decrypted in place). */
  68177. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  68178. /* Check that the decrypted key matches the key prior to encryption. */
  68179. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  68180. sizeof_server_key_der_2048), 0);
  68181. PRIVATE_KEY_LOCK();
  68182. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68183. wc_FreeRng(&rng);
  68184. #endif
  68185. return EXPECT_RESULT();
  68186. }
  68187. static int test_wc_GetPkcs8TraditionalOffset(void)
  68188. {
  68189. EXPECT_DECLS;
  68190. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  68191. int length;
  68192. int derSz = 0;
  68193. word32 inOutIdx;
  68194. const char* path = "./certs/server-keyPkcs8.der";
  68195. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  68196. XFILE file = XBADFILE;
  68197. byte der[2048];
  68198. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  68199. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  68200. if (file != XBADFILE)
  68201. XFCLOSE(file);
  68202. file = XBADFILE; /* reset file to avoid warning of use after close */
  68203. /* valid case */
  68204. inOutIdx = 0;
  68205. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68206. 0);
  68207. /* inOutIdx > sz */
  68208. inOutIdx = 4000;
  68209. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68210. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68211. /* null input */
  68212. inOutIdx = 0;
  68213. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  68214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68215. /* invalid input, fill buffer with 1's */
  68216. XMEMSET(der, 1, sizeof(der));
  68217. inOutIdx = 0;
  68218. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68219. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68220. /* test parsing with attributes */
  68221. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  68222. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  68223. if (file != XBADFILE)
  68224. XFCLOSE(file);
  68225. inOutIdx = 0;
  68226. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  68227. (word32)derSz), 0);
  68228. #endif /* NO_ASN */
  68229. return EXPECT_RESULT();
  68230. }
  68231. static int test_wc_SetSubjectRaw(void)
  68232. {
  68233. EXPECT_DECLS;
  68234. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68235. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68236. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68237. WOLFSSL_X509* x509 = NULL;
  68238. int peerCertSz;
  68239. const byte* peerCertBuf = NULL;
  68240. Cert forgedCert;
  68241. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68242. WOLFSSL_FILETYPE_ASN1));
  68243. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68244. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68245. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  68246. wolfSSL_FreeX509(x509);
  68247. #endif
  68248. return EXPECT_RESULT();
  68249. }
  68250. static int test_wc_GetSubjectRaw(void)
  68251. {
  68252. EXPECT_DECLS;
  68253. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68254. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  68255. Cert cert;
  68256. byte *subjectRaw;
  68257. ExpectIntEQ(0, wc_InitCert(&cert));
  68258. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  68259. #endif
  68260. return EXPECT_RESULT();
  68261. }
  68262. static int test_wc_SetIssuerRaw(void)
  68263. {
  68264. EXPECT_DECLS;
  68265. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68266. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68267. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68268. WOLFSSL_X509* x509 = NULL;
  68269. int peerCertSz;
  68270. const byte* peerCertBuf = NULL;
  68271. Cert forgedCert;
  68272. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68273. WOLFSSL_FILETYPE_ASN1));
  68274. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68275. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68276. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  68277. wolfSSL_FreeX509(x509);
  68278. #endif
  68279. return EXPECT_RESULT();
  68280. }
  68281. static int test_wc_SetIssueBuffer(void)
  68282. {
  68283. EXPECT_DECLS;
  68284. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68285. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68286. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68287. WOLFSSL_X509* x509 = NULL;
  68288. int peerCertSz;
  68289. const byte* peerCertBuf = NULL;
  68290. Cert forgedCert;
  68291. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68292. WOLFSSL_FILETYPE_ASN1));
  68293. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68294. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68295. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  68296. wolfSSL_FreeX509(x509);
  68297. #endif
  68298. return EXPECT_RESULT();
  68299. }
  68300. /*
  68301. * Testing wc_SetSubjectKeyId
  68302. */
  68303. static int test_wc_SetSubjectKeyId(void)
  68304. {
  68305. EXPECT_DECLS;
  68306. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68307. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68308. Cert cert;
  68309. const char* file = "certs/ecc-client-keyPub.pem";
  68310. ExpectIntEQ(0, wc_InitCert(&cert));
  68311. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  68312. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  68313. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  68314. #endif
  68315. return EXPECT_RESULT();
  68316. } /* END test_wc_SetSubjectKeyId */
  68317. /*
  68318. * Testing wc_SetSubject
  68319. */
  68320. static int test_wc_SetSubject(void)
  68321. {
  68322. EXPECT_DECLS;
  68323. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68324. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68325. Cert cert;
  68326. const char* file = "./certs/ca-ecc-cert.pem";
  68327. ExpectIntEQ(0, wc_InitCert(&cert));
  68328. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  68329. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  68330. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  68331. #endif
  68332. return EXPECT_RESULT();
  68333. } /* END test_wc_SetSubject */
  68334. static int test_CheckCertSignature(void)
  68335. {
  68336. EXPECT_DECLS;
  68337. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  68338. WOLFSSL_CERT_MANAGER* cm = NULL;
  68339. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68340. XFILE fp = XBADFILE;
  68341. byte cert[4096];
  68342. int certSz;
  68343. #endif
  68344. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  68345. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68346. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  68347. #ifndef NO_RSA
  68348. #ifdef USE_CERT_BUFFERS_1024
  68349. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  68350. sizeof_server_cert_der_1024, NULL, cm));
  68351. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68352. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  68353. WOLFSSL_FILETYPE_ASN1));
  68354. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  68355. sizeof_server_cert_der_1024, NULL, cm));
  68356. #elif defined(USE_CERT_BUFFERS_2048)
  68357. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  68358. sizeof_server_cert_der_2048, NULL, cm));
  68359. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68360. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  68361. WOLFSSL_FILETYPE_ASN1));
  68362. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  68363. sizeof_server_cert_der_2048, NULL, cm));
  68364. #endif
  68365. #endif
  68366. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68367. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  68368. sizeof_serv_ecc_der_256, NULL, cm));
  68369. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68370. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  68371. WOLFSSL_FILETYPE_ASN1));
  68372. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  68373. NULL, cm));
  68374. #endif
  68375. #if !defined(NO_FILESYSTEM)
  68376. wolfSSL_CertManagerFree(cm);
  68377. cm = NULL;
  68378. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68379. #ifndef NO_RSA
  68380. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  68381. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68382. if (fp != XBADFILE) {
  68383. XFCLOSE(fp);
  68384. fp = XBADFILE;
  68385. }
  68386. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68387. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68388. "./certs/ca-cert.pem", NULL));
  68389. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68390. #endif
  68391. #ifdef HAVE_ECC
  68392. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  68393. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68394. if (fp != XBADFILE) {
  68395. XFCLOSE(fp);
  68396. fp = XBADFILE;
  68397. }
  68398. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68399. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68400. "./certs/ca-ecc-cert.pem", NULL));
  68401. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68402. #endif
  68403. #endif
  68404. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68405. (void)fp;
  68406. (void)cert;
  68407. (void)certSz;
  68408. #endif
  68409. wolfSSL_CertManagerFree(cm);
  68410. #endif
  68411. return EXPECT_RESULT();
  68412. }
  68413. static int test_wc_ParseCert(void)
  68414. {
  68415. EXPECT_DECLS;
  68416. #if !defined(NO_CERTS) && !defined(NO_RSA)
  68417. DecodedCert decodedCert;
  68418. const byte* rawCert = client_cert_der_2048;
  68419. const int rawCertSize = sizeof_client_cert_der_2048;
  68420. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  68421. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68422. #ifndef IGNORE_NAME_CONSTRAINTS
  68423. /* check that the subjects emailAddress was not put in the alt name list */
  68424. ExpectNotNull(decodedCert.subjectEmail);
  68425. ExpectNull(decodedCert.altEmailNames);
  68426. #endif
  68427. wc_FreeDecodedCert(&decodedCert);
  68428. #endif
  68429. return EXPECT_RESULT();
  68430. }
  68431. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  68432. * the API safely errors out on badly-formed ASN input.
  68433. * NOTE: Test not compatible with released FIPS implementations!
  68434. */
  68435. static int test_wc_ParseCert_Error(void)
  68436. {
  68437. EXPECT_DECLS;
  68438. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  68439. (!defined(HAVE_FIPS) || \
  68440. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  68441. DecodedCert decodedCert;
  68442. int i;
  68443. /* Certificate data */
  68444. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  68445. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68446. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68447. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  68448. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  68449. /* Test data */
  68450. const struct testStruct {
  68451. const byte* c;
  68452. const int cSz;
  68453. const int expRet;
  68454. } t[] = {
  68455. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68456. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68457. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  68458. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  68459. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  68460. };
  68461. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  68462. for (i = 0; i < tSz; i++) {
  68463. WOLFSSL_MSG_EX("i == %d", i);
  68464. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  68465. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  68466. wc_FreeDecodedCert(&decodedCert);
  68467. }
  68468. #endif
  68469. return EXPECT_RESULT();
  68470. }
  68471. static int test_MakeCertWithPathLen(void)
  68472. {
  68473. EXPECT_DECLS;
  68474. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68475. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68476. const byte expectedPathLen = 7;
  68477. Cert cert;
  68478. DecodedCert decodedCert;
  68479. byte der[FOURK_BUF];
  68480. int derSize = 0;
  68481. WC_RNG rng;
  68482. ecc_key key;
  68483. int ret;
  68484. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68485. XMEMSET(&key, 0, sizeof(ecc_key));
  68486. XMEMSET(&cert, 0, sizeof(Cert));
  68487. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68488. ExpectIntEQ(wc_InitRng(&rng), 0);
  68489. ExpectIntEQ(wc_ecc_init(&key), 0);
  68490. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68491. ExpectIntEQ(wc_InitCert(&cert), 0);
  68492. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68493. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68494. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68495. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68496. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68497. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68498. CTC_NAME_SIZE);
  68499. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68500. CTC_NAME_SIZE);
  68501. cert.selfSigned = 1;
  68502. cert.isCA = 1;
  68503. cert.pathLen = expectedPathLen;
  68504. cert.pathLenSet = 1;
  68505. cert.sigType = CTC_SHA256wECDSA;
  68506. #ifdef WOLFSSL_CERT_EXT
  68507. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68508. #endif
  68509. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68510. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68511. FOURK_BUF, NULL, &key, &rng), 0);
  68512. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68513. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68514. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  68515. wc_FreeDecodedCert(&decodedCert);
  68516. ret = wc_ecc_free(&key);
  68517. ExpectIntEQ(ret, 0);
  68518. ret = wc_FreeRng(&rng);
  68519. ExpectIntEQ(ret, 0);
  68520. #endif
  68521. return EXPECT_RESULT();
  68522. }
  68523. static int test_MakeCertWith0Ser(void)
  68524. {
  68525. EXPECT_DECLS;
  68526. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68527. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  68528. defined(WOLFSSL_ASN_TEMPLATE)
  68529. Cert cert;
  68530. DecodedCert decodedCert;
  68531. byte der[FOURK_BUF];
  68532. int derSize = 0;
  68533. WC_RNG rng;
  68534. ecc_key key;
  68535. int ret;
  68536. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68537. XMEMSET(&key, 0, sizeof(ecc_key));
  68538. XMEMSET(&cert, 0, sizeof(Cert));
  68539. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68540. ExpectIntEQ(wc_InitRng(&rng), 0);
  68541. ExpectIntEQ(wc_ecc_init(&key), 0);
  68542. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68543. ExpectIntEQ(wc_InitCert(&cert), 0);
  68544. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68545. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68546. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68547. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68548. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68549. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68550. CTC_NAME_SIZE);
  68551. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68552. CTC_NAME_SIZE);
  68553. cert.selfSigned = 1;
  68554. cert.isCA = 1;
  68555. cert.sigType = CTC_SHA256wECDSA;
  68556. #ifdef WOLFSSL_CERT_EXT
  68557. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68558. #endif
  68559. /* set serial number to 0 */
  68560. cert.serialSz = 1;
  68561. cert.serial[0] = 0;
  68562. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68563. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68564. FOURK_BUF, NULL, &key, &rng), 0);
  68565. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68566. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  68567. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  68568. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68569. #else
  68570. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68571. #endif
  68572. wc_FreeDecodedCert(&decodedCert);
  68573. ret = wc_ecc_free(&key);
  68574. ExpectIntEQ(ret, 0);
  68575. ret = wc_FreeRng(&rng);
  68576. ExpectIntEQ(ret, 0);
  68577. #endif
  68578. return EXPECT_RESULT();
  68579. }
  68580. static int test_MakeCertWithCaFalse(void)
  68581. {
  68582. EXPECT_DECLS;
  68583. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  68584. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68585. const byte expectedIsCa = 0;
  68586. Cert cert;
  68587. DecodedCert decodedCert;
  68588. byte der[FOURK_BUF];
  68589. int derSize = 0;
  68590. WC_RNG rng;
  68591. ecc_key key;
  68592. int ret;
  68593. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68594. XMEMSET(&key, 0, sizeof(ecc_key));
  68595. XMEMSET(&cert, 0, sizeof(Cert));
  68596. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68597. ExpectIntEQ(wc_InitRng(&rng), 0);
  68598. ExpectIntEQ(wc_ecc_init(&key), 0);
  68599. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68600. ExpectIntEQ(wc_InitCert(&cert), 0);
  68601. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68602. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68603. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68604. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68605. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68606. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68607. CTC_NAME_SIZE);
  68608. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68609. CTC_NAME_SIZE);
  68610. cert.selfSigned = 1;
  68611. cert.isCA = expectedIsCa;
  68612. cert.isCaSet = 1;
  68613. cert.sigType = CTC_SHA256wECDSA;
  68614. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68615. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68616. FOURK_BUF, NULL, &key, &rng), 0);
  68617. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  68618. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68619. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  68620. wc_FreeDecodedCert(&decodedCert);
  68621. ret = wc_ecc_free(&key);
  68622. ExpectIntEQ(ret, 0);
  68623. ret = wc_FreeRng(&rng);
  68624. ExpectIntEQ(ret, 0);
  68625. #endif
  68626. return EXPECT_RESULT();
  68627. }
  68628. /*----------------------------------------------------------------------------*
  68629. | wolfCrypt ECC
  68630. *----------------------------------------------------------------------------*/
  68631. static int test_wc_ecc_get_curve_size_from_name(void)
  68632. {
  68633. EXPECT_DECLS;
  68634. #ifdef HAVE_ECC
  68635. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68636. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  68637. #endif
  68638. /* invalid case */
  68639. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  68640. /* NULL input */
  68641. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68642. #endif /* HAVE_ECC */
  68643. return EXPECT_RESULT();
  68644. }
  68645. static int test_wc_ecc_get_curve_id_from_name(void)
  68646. {
  68647. EXPECT_DECLS;
  68648. #ifdef HAVE_ECC
  68649. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68650. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  68651. ECC_SECP256R1);
  68652. #endif
  68653. /* invalid case */
  68654. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  68655. /* NULL input */
  68656. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68657. #endif /* HAVE_ECC */
  68658. return EXPECT_RESULT();
  68659. }
  68660. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  68661. !defined(HAVE_SELFTEST) && \
  68662. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  68663. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  68664. {
  68665. EXPECT_DECLS;
  68666. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68667. ecc_key* key;
  68668. const ecc_set_type* params = NULL;
  68669. int ret;
  68670. #endif
  68671. WOLFSSL_EC_KEY *ecKey = NULL;
  68672. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68673. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  68674. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  68675. if (EXPECT_SUCCESS()) {
  68676. ret = EC_KEY_generate_key(ecKey);
  68677. } else
  68678. ret = 0;
  68679. if (ret == 1) {
  68680. /* normal test */
  68681. key = (ecc_key*)ecKey->internal;
  68682. if (key != NULL) {
  68683. params = key->dp;
  68684. }
  68685. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  68686. ECC_SECP256R1);
  68687. }
  68688. #endif
  68689. /* invalid case, NULL input*/
  68690. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68691. wolfSSL_EC_KEY_free(ecKey);
  68692. return EXPECT_RESULT();
  68693. }
  68694. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  68695. static int test_wc_ecc_get_curve_id_from_params(void)
  68696. {
  68697. EXPECT_DECLS;
  68698. #ifdef HAVE_ECC
  68699. const byte prime[] =
  68700. {
  68701. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68702. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68703. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68704. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  68705. };
  68706. const byte primeInvalid[] =
  68707. {
  68708. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68709. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68710. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68711. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  68712. };
  68713. const byte Af[] =
  68714. {
  68715. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68716. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68717. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68718. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  68719. };
  68720. const byte Bf[] =
  68721. {
  68722. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  68723. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  68724. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  68725. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  68726. };
  68727. const byte order[] =
  68728. {
  68729. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  68730. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  68731. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  68732. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  68733. };
  68734. const byte Gx[] =
  68735. {
  68736. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  68737. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  68738. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  68739. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  68740. };
  68741. const byte Gy[] =
  68742. {
  68743. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  68744. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  68745. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  68746. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  68747. };
  68748. int cofactor = 1;
  68749. int fieldSize = 256;
  68750. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68751. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68752. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  68753. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  68754. ECC_SECP256R1);
  68755. #endif
  68756. /* invalid case, fieldSize = 0 */
  68757. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  68758. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68759. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68760. /* invalid case, NULL prime */
  68761. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  68762. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68763. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68764. /* invalid case, invalid prime */
  68765. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68766. primeInvalid, sizeof(primeInvalid),
  68767. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68768. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68769. #endif
  68770. return EXPECT_RESULT();
  68771. }
  68772. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  68773. {
  68774. EXPECT_DECLS;
  68775. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  68776. WOLFSSL_RSA* rsa = NULL;
  68777. WOLFSSL_EVP_PKEY* pkey = NULL;
  68778. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68779. const char* in = "What is easy to do is easy not to do.";
  68780. size_t inlen = XSTRLEN(in);
  68781. size_t outEncLen = 0;
  68782. byte* outEnc = NULL;
  68783. byte* outDec = NULL;
  68784. size_t outDecLen = 0;
  68785. size_t rsaKeySz = 2048/8; /* Bytes */
  68786. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68787. byte* inTmp = NULL;
  68788. byte* outEncTmp = NULL;
  68789. byte* outDecTmp = NULL;
  68790. #endif
  68791. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68792. DYNAMIC_TYPE_TMP_BUFFER));
  68793. if (outEnc != NULL) {
  68794. XMEMSET(outEnc, 0, rsaKeySz);
  68795. }
  68796. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68797. DYNAMIC_TYPE_TMP_BUFFER));
  68798. if (outDec != NULL) {
  68799. XMEMSET(outDec, 0, rsaKeySz);
  68800. }
  68801. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68802. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68803. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68804. if (EXPECT_FAIL()) {
  68805. RSA_free(rsa);
  68806. }
  68807. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68808. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68809. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68810. WOLFSSL_SUCCESS);
  68811. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  68812. since ctx uses it.*/
  68813. ExpectIntEQ(pkey->ref.count, 2);
  68814. EVP_PKEY_free(pkey);
  68815. ExpectIntEQ(pkey->ref.count, 1);
  68816. /* Encrypt data */
  68817. /* Check that we can get the required output buffer length by passing in a
  68818. * NULL output buffer. */
  68819. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  68820. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68821. ExpectIntEQ(rsaKeySz, outEncLen);
  68822. /* Now do the actual encryption. */
  68823. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  68824. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68825. /* Decrypt data */
  68826. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68827. /* Check that we can get the required output buffer length by passing in a
  68828. * NULL output buffer. */
  68829. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  68830. WOLFSSL_SUCCESS);
  68831. ExpectIntEQ(rsaKeySz, outDecLen);
  68832. /* Now do the actual decryption. */
  68833. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  68834. WOLFSSL_SUCCESS);
  68835. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  68836. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68837. /* The input length must be the same size as the RSA key.*/
  68838. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68839. DYNAMIC_TYPE_TMP_BUFFER));
  68840. if (inTmp != NULL) {
  68841. XMEMSET(inTmp, 9, rsaKeySz);
  68842. }
  68843. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68844. DYNAMIC_TYPE_TMP_BUFFER));
  68845. if (outEncTmp != NULL) {
  68846. XMEMSET(outEncTmp, 0, rsaKeySz);
  68847. }
  68848. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68849. DYNAMIC_TYPE_TMP_BUFFER));
  68850. if (outDecTmp != NULL) {
  68851. XMEMSET(outDecTmp, 0, rsaKeySz);
  68852. }
  68853. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68854. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68855. WOLFSSL_SUCCESS);
  68856. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  68857. WOLFSSL_SUCCESS);
  68858. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68859. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  68860. outEncLen), WOLFSSL_SUCCESS);
  68861. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  68862. #endif
  68863. EVP_PKEY_CTX_free(ctx);
  68864. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68865. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68866. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68867. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68868. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68869. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68870. #endif
  68871. #endif
  68872. return EXPECT_RESULT();
  68873. }
  68874. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68875. !defined(HAVE_SELFTEST)
  68876. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68877. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68878. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68879. #endif
  68880. #endif
  68881. #endif
  68882. #if defined(OPENSSL_EXTRA)
  68883. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68884. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68885. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68886. #endif
  68887. #endif
  68888. #endif
  68889. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68890. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68891. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68892. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68893. #endif
  68894. #endif
  68895. #endif
  68896. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68897. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  68898. {
  68899. EXPECT_DECLS;
  68900. #if defined(OPENSSL_EXTRA)
  68901. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68902. !defined(HAVE_SELFTEST)
  68903. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68904. WOLFSSL_RSA* rsa = NULL;
  68905. #endif
  68906. #endif
  68907. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68908. WOLFSSL_DSA* dsa = NULL;
  68909. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68910. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68911. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68912. WOLFSSL_EC_KEY* ecKey = NULL;
  68913. #endif
  68914. #endif
  68915. WOLFSSL_EVP_PKEY* pkey = NULL;
  68916. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68917. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  68918. const char* in = "What is easy to do is easy not to do.";
  68919. size_t inlen = XSTRLEN(in);
  68920. byte hash[SHA256_DIGEST_LENGTH] = {0};
  68921. byte zero[SHA256_DIGEST_LENGTH] = {0};
  68922. SHA256_CTX c;
  68923. byte* sig = NULL;
  68924. byte* sigVerify = NULL;
  68925. size_t siglen;
  68926. size_t siglenOnlyLen;
  68927. size_t keySz = 2048/8; /* Bytes */
  68928. ExpectNotNull(sig =
  68929. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68930. ExpectNotNull(sigVerify =
  68931. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68932. siglen = keySz;
  68933. ExpectNotNull(XMEMSET(sig, 0, keySz));
  68934. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  68935. /* Generate hash */
  68936. SHA256_Init(&c);
  68937. SHA256_Update(&c, in, inlen);
  68938. SHA256_Final(hash, &c);
  68939. #ifdef WOLFSSL_SMALL_STACK_CACHE
  68940. /* workaround for small stack cache case */
  68941. wc_Sha256Free((wc_Sha256*)&c);
  68942. #endif
  68943. /* Generate key */
  68944. ExpectNotNull(pkey = EVP_PKEY_new());
  68945. switch (keyType) {
  68946. case EVP_PKEY_RSA:
  68947. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68948. !defined(HAVE_SELFTEST)
  68949. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68950. {
  68951. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68952. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68953. }
  68954. #endif
  68955. #endif
  68956. break;
  68957. case EVP_PKEY_DSA:
  68958. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68959. ExpectNotNull(dsa = DSA_new());
  68960. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  68961. NULL, 0, NULL, NULL, NULL), 1);
  68962. ExpectIntEQ(DSA_generate_key(dsa), 1);
  68963. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  68964. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68965. break;
  68966. case EVP_PKEY_EC:
  68967. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68968. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68969. {
  68970. ExpectNotNull(ecKey = EC_KEY_new());
  68971. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  68972. ExpectIntEQ(
  68973. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68974. if (EXPECT_FAIL()) {
  68975. EC_KEY_free(ecKey);
  68976. }
  68977. }
  68978. #endif
  68979. #endif
  68980. break;
  68981. }
  68982. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68983. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68984. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68985. !defined(HAVE_SELFTEST)
  68986. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68987. if (keyType == EVP_PKEY_RSA)
  68988. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68989. WOLFSSL_SUCCESS);
  68990. #endif
  68991. #endif
  68992. /* Check returning only length */
  68993. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  68994. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68995. ExpectIntGT(siglenOnlyLen, 0);
  68996. /* Sign data */
  68997. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  68998. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68999. ExpectIntGE(siglenOnlyLen, siglen);
  69000. /* Verify signature */
  69001. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  69002. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69003. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69004. !defined(HAVE_SELFTEST)
  69005. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69006. if (keyType == EVP_PKEY_RSA)
  69007. ExpectIntEQ(
  69008. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  69009. WOLFSSL_SUCCESS);
  69010. #endif
  69011. #endif
  69012. ExpectIntEQ(EVP_PKEY_verify(
  69013. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  69014. WOLFSSL_SUCCESS);
  69015. ExpectIntEQ(EVP_PKEY_verify(
  69016. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  69017. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69018. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69019. !defined(HAVE_SELFTEST)
  69020. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69021. if (keyType == EVP_PKEY_RSA) {
  69022. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  69023. /* Try RSA sign/verify with no padding. */
  69024. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69025. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  69026. WOLFSSL_SUCCESS);
  69027. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69028. siglen), WOLFSSL_SUCCESS);
  69029. ExpectIntGE(siglenOnlyLen, siglen);
  69030. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69031. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69032. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  69033. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69034. siglen), WOLFSSL_SUCCESS);
  69035. #endif
  69036. /* Wrong padding schemes. */
  69037. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69038. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  69039. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69040. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69041. siglen), WOLFSSL_SUCCESS);
  69042. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69043. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69044. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69045. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69046. siglen), WOLFSSL_SUCCESS);
  69047. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69048. WOLFSSL_SUCCESS);
  69049. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69050. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  69051. }
  69052. #endif
  69053. #endif
  69054. /* error cases */
  69055. siglen = keySz; /* Reset because sig size may vary slightly */
  69056. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  69057. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69058. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  69059. WOLFSSL_SUCCESS);
  69060. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  69061. WOLFSSL_SUCCESS);
  69062. EVP_PKEY_free(pkey);
  69063. pkey = NULL;
  69064. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69065. DSA_free(dsa);
  69066. dsa = NULL;
  69067. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69068. EVP_PKEY_CTX_free(ctx_verify);
  69069. ctx_verify = NULL;
  69070. EVP_PKEY_CTX_free(ctx);
  69071. ctx = NULL;
  69072. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69073. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69074. #endif /* OPENSSL_EXTRA */
  69075. return EXPECT_RESULT();
  69076. }
  69077. #endif
  69078. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  69079. {
  69080. EXPECT_DECLS;
  69081. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69082. !defined(HAVE_SELFTEST)
  69083. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69084. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  69085. #endif
  69086. #endif
  69087. return EXPECT_RESULT();
  69088. }
  69089. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  69090. {
  69091. EXPECT_DECLS;
  69092. #if defined(OPENSSL_EXTRA)
  69093. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69094. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  69095. #endif
  69096. #endif
  69097. return EXPECT_RESULT();
  69098. }
  69099. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  69100. {
  69101. EXPECT_DECLS;
  69102. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69103. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69104. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  69105. #endif
  69106. #endif
  69107. return EXPECT_RESULT();
  69108. }
  69109. static int test_EVP_PKEY_rsa(void)
  69110. {
  69111. EXPECT_DECLS;
  69112. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  69113. WOLFSSL_RSA* rsa = NULL;
  69114. WOLFSSL_EVP_PKEY* pkey = NULL;
  69115. ExpectNotNull(rsa = wolfSSL_RSA_new());
  69116. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69117. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69118. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69119. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69120. if (EXPECT_FAIL()) {
  69121. wolfSSL_RSA_free(rsa);
  69122. }
  69123. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  69124. wolfSSL_EVP_PKEY_free(pkey);
  69125. #endif
  69126. return EXPECT_RESULT();
  69127. }
  69128. static int test_EVP_PKEY_ec(void)
  69129. {
  69130. EXPECT_DECLS;
  69131. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69132. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69133. WOLFSSL_EC_KEY* ecKey = NULL;
  69134. WOLFSSL_EVP_PKEY* pkey = NULL;
  69135. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  69136. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69137. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69138. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69139. /* Should fail since ecKey is empty */
  69140. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69141. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  69142. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  69143. if (EXPECT_FAIL()) {
  69144. wolfSSL_EC_KEY_free(ecKey);
  69145. }
  69146. wolfSSL_EVP_PKEY_free(pkey);
  69147. #endif
  69148. #endif
  69149. return EXPECT_RESULT();
  69150. }
  69151. static int test_EVP_PKEY_cmp(void)
  69152. {
  69153. EXPECT_DECLS;
  69154. #if defined(OPENSSL_EXTRA)
  69155. EVP_PKEY *a = NULL;
  69156. EVP_PKEY *b = NULL;
  69157. const unsigned char *in;
  69158. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  69159. in = client_key_der_2048;
  69160. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69161. &in, (long)sizeof_client_key_der_2048));
  69162. in = client_key_der_2048;
  69163. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69164. &in, (long)sizeof_client_key_der_2048));
  69165. /* Test success case RSA */
  69166. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69167. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69168. #else
  69169. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69170. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69171. EVP_PKEY_free(b);
  69172. b = NULL;
  69173. EVP_PKEY_free(a);
  69174. a = NULL;
  69175. #endif
  69176. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69177. in = ecc_clikey_der_256;
  69178. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69179. &in, (long)sizeof_ecc_clikey_der_256));
  69180. in = ecc_clikey_der_256;
  69181. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69182. &in, (long)sizeof_ecc_clikey_der_256));
  69183. /* Test success case ECC */
  69184. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69185. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69186. #else
  69187. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69188. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69189. EVP_PKEY_free(b);
  69190. b = NULL;
  69191. EVP_PKEY_free(a);
  69192. a = NULL;
  69193. #endif
  69194. /* Test failure cases */
  69195. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  69196. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69197. in = client_key_der_2048;
  69198. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69199. &in, (long)sizeof_client_key_der_2048));
  69200. in = ecc_clikey_der_256;
  69201. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69202. &in, (long)sizeof_ecc_clikey_der_256));
  69203. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69204. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  69205. #else
  69206. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  69207. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69208. EVP_PKEY_free(b);
  69209. b = NULL;
  69210. EVP_PKEY_free(a);
  69211. a = NULL;
  69212. #endif
  69213. /* invalid or empty failure cases */
  69214. a = EVP_PKEY_new();
  69215. b = EVP_PKEY_new();
  69216. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69217. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  69218. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  69219. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  69220. #ifdef NO_RSA
  69221. /* Type check will fail since RSA is the default EVP key type */
  69222. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  69223. #else
  69224. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69225. #endif
  69226. #else
  69227. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  69228. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  69229. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  69230. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  69231. #endif
  69232. EVP_PKEY_free(b);
  69233. EVP_PKEY_free(a);
  69234. (void)in;
  69235. #endif
  69236. return EXPECT_RESULT();
  69237. }
  69238. static int test_ERR_load_crypto_strings(void)
  69239. {
  69240. #if defined(OPENSSL_ALL)
  69241. ERR_load_crypto_strings();
  69242. return TEST_SUCCESS;
  69243. #else
  69244. return TEST_SKIPPED;
  69245. #endif
  69246. }
  69247. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  69248. static void free_x509(X509* x)
  69249. {
  69250. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  69251. }
  69252. #endif
  69253. static int test_sk_X509(void)
  69254. {
  69255. EXPECT_DECLS;
  69256. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  69257. {
  69258. STACK_OF(X509)* s = NULL;
  69259. ExpectNotNull(s = sk_X509_new_null());
  69260. ExpectIntEQ(sk_X509_num(s), 0);
  69261. sk_X509_pop_free(s, NULL);
  69262. ExpectNotNull(s = sk_X509_new_null());
  69263. ExpectIntEQ(sk_X509_num(s), 0);
  69264. sk_X509_pop_free(s, NULL);
  69265. ExpectNotNull(s = sk_X509_new_null());
  69266. sk_X509_push(s, (X509*)1);
  69267. ExpectIntEQ(sk_X509_num(s), 1);
  69268. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  69269. sk_X509_push(s, (X509*)2);
  69270. ExpectIntEQ(sk_X509_num(s), 2);
  69271. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  69272. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  69273. sk_X509_push(s, (X509*)2);
  69274. sk_X509_pop_free(s, free_x509);
  69275. }
  69276. {
  69277. /* Push a list of 10 X509s onto stack, then verify that
  69278. * value(), push(), shift(), and pop() behave as expected. */
  69279. STACK_OF(X509)* s = NULL;
  69280. X509* xList[10];
  69281. int i = 0;
  69282. const int len = (sizeof(xList) / sizeof(xList[0]));
  69283. for (i = 0; i < len; ++i) {
  69284. xList[i] = NULL;
  69285. ExpectNotNull(xList[i] = X509_new());
  69286. }
  69287. /* test push, pop, and free */
  69288. ExpectNotNull(s = sk_X509_new_null());
  69289. for (i = 0; i < len; ++i) {
  69290. sk_X509_push(s, xList[i]);
  69291. ExpectIntEQ(sk_X509_num(s), i + 1);
  69292. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69293. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69294. }
  69295. /* pop returns and removes last pushed on stack, which is index 0
  69296. * in sk_x509_value */
  69297. for (i = 0; i < len; ++i) {
  69298. X509 * x = sk_X509_value(s, 0);
  69299. X509 * y = sk_X509_pop(s);
  69300. X509 * z = xList[len - 1 - i];
  69301. ExpectIntEQ((x == y), 1);
  69302. ExpectIntEQ((x == z), 1);
  69303. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69304. }
  69305. sk_free(s);
  69306. s = NULL;
  69307. /* test push, shift, and free */
  69308. ExpectNotNull(s = sk_X509_new_null());
  69309. for (i = 0; i < len; ++i) {
  69310. sk_X509_push(s, xList[i]);
  69311. ExpectIntEQ(sk_X509_num(s), i + 1);
  69312. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69313. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69314. }
  69315. /* shift returns and removes first pushed on stack, which is index i
  69316. * in sk_x509_value() */
  69317. for (i = 0; i < len; ++i) {
  69318. X509 * x = sk_X509_value(s, len - 1 - i);
  69319. X509 * y = sk_X509_shift(s);
  69320. X509 * z = xList[i];
  69321. ExpectIntEQ((x == y), 1);
  69322. ExpectIntEQ((x == z), 1);
  69323. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69324. }
  69325. sk_free(s);
  69326. for (i = 0; i < len; ++i)
  69327. X509_free(xList[i]);
  69328. }
  69329. #endif
  69330. return EXPECT_RESULT();
  69331. }
  69332. static int test_sk_X509_CRL(void)
  69333. {
  69334. EXPECT_DECLS;
  69335. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  69336. X509_CRL* crl = NULL;
  69337. XFILE fp = XBADFILE;
  69338. STACK_OF(X509_CRL)* s = NULL;
  69339. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  69340. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69341. NULL, NULL));
  69342. if (fp != XBADFILE)
  69343. XFCLOSE(fp);
  69344. ExpectNotNull(s = sk_X509_CRL_new());
  69345. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  69346. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  69347. if (EXPECT_FAIL()) {
  69348. X509_CRL_free(crl);
  69349. }
  69350. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  69351. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  69352. sk_X509_CRL_free(s);
  69353. #endif
  69354. return EXPECT_RESULT();
  69355. }
  69356. static int test_X509_get_signature_nid(void)
  69357. {
  69358. EXPECT_DECLS;
  69359. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69360. X509* x509 = NULL;
  69361. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  69362. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  69363. SSL_FILETYPE_PEM));
  69364. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  69365. X509_free(x509);
  69366. #endif
  69367. return EXPECT_RESULT();
  69368. }
  69369. static int test_X509_REQ(void)
  69370. {
  69371. EXPECT_DECLS;
  69372. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  69373. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  69374. X509_NAME* name = NULL;
  69375. #ifndef NO_RSA
  69376. X509_NAME* subject = NULL;
  69377. #endif
  69378. #if !defined(NO_RSA) || defined(HAVE_ECC)
  69379. X509_REQ* req = NULL;
  69380. EVP_PKEY* priv = NULL;
  69381. EVP_PKEY* pub = NULL;
  69382. unsigned char* der = NULL;
  69383. int len;
  69384. #endif
  69385. #ifndef NO_RSA
  69386. EVP_MD_CTX *mctx = NULL;
  69387. EVP_PKEY_CTX *pkctx = NULL;
  69388. #ifdef USE_CERT_BUFFERS_1024
  69389. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  69390. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  69391. #elif defined(USE_CERT_BUFFERS_2048)
  69392. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  69393. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  69394. #endif
  69395. #endif
  69396. #ifdef HAVE_ECC
  69397. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  69398. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  69399. #endif
  69400. ExpectNotNull(name = X509_NAME_new());
  69401. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  69402. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  69403. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  69404. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  69405. #ifndef NO_RSA
  69406. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  69407. (long)sizeof_client_key_der_2048));
  69408. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  69409. (long)sizeof_client_keypub_der_2048));
  69410. ExpectNotNull(req = X509_REQ_new());
  69411. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69412. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69413. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69414. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69415. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69416. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69417. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69418. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69419. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69420. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69421. len = i2d_X509_REQ(req, &der);
  69422. DEBUG_WRITE_DER(der, len, "req.der");
  69423. #ifdef USE_CERT_BUFFERS_1024
  69424. ExpectIntEQ(len, 381);
  69425. #else
  69426. ExpectIntEQ(len, 643);
  69427. #endif
  69428. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69429. der = NULL;
  69430. mctx = EVP_MD_CTX_new();
  69431. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  69432. WOLFSSL_SUCCESS);
  69433. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  69434. EVP_MD_CTX_free(mctx);
  69435. mctx = NULL;
  69436. X509_REQ_free(NULL);
  69437. X509_REQ_free(req);
  69438. req = NULL;
  69439. /* Test getting the subject from a newly created X509_REQ */
  69440. ExpectNotNull(req = X509_REQ_new());
  69441. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  69442. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  69443. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  69444. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  69445. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  69446. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  69447. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  69448. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  69449. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  69450. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  69451. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  69452. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  69453. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  69454. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69455. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69456. len = i2d_X509_REQ(req, &der);
  69457. DEBUG_WRITE_DER(der, len, "req2.der");
  69458. #ifdef USE_CERT_BUFFERS_1024
  69459. ExpectIntEQ(len, 435);
  69460. #else
  69461. ExpectIntEQ(len, 696);
  69462. #endif
  69463. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69464. der = NULL;
  69465. EVP_PKEY_free(pub);
  69466. pub = NULL;
  69467. EVP_PKEY_free(priv);
  69468. priv = NULL;
  69469. X509_REQ_free(req);
  69470. req = NULL;
  69471. #endif
  69472. #ifdef HAVE_ECC
  69473. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  69474. sizeof_ecc_clikey_der_256));
  69475. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  69476. sizeof_ecc_clikeypub_der_256));
  69477. ExpectNotNull(req = X509_REQ_new());
  69478. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69479. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69480. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69481. /* Signature is random and may be shorter or longer. */
  69482. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  69483. ExpectIntLE(len, 253);
  69484. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69485. X509_REQ_free(req);
  69486. EVP_PKEY_free(pub);
  69487. EVP_PKEY_free(priv);
  69488. #ifdef FP_ECC
  69489. wc_ecc_fp_free();
  69490. #endif
  69491. #endif /* HAVE_ECC */
  69492. X509_NAME_free(name);
  69493. #endif
  69494. return EXPECT_RESULT();
  69495. }
  69496. static int test_wolfssl_PKCS7(void)
  69497. {
  69498. EXPECT_DECLS;
  69499. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69500. !defined(NO_RSA)
  69501. PKCS7* pkcs7 = NULL;
  69502. byte data[FOURK_BUF];
  69503. word32 len = sizeof(data);
  69504. const byte* p = data;
  69505. byte content[] = "Test data to encode.";
  69506. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69507. BIO* bio = NULL;
  69508. byte key[sizeof(client_key_der_2048)];
  69509. word32 keySz = (word32)sizeof(key);
  69510. byte* out = NULL;
  69511. #endif
  69512. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  69513. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  69514. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  69515. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  69516. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69517. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  69518. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69519. PKCS7_free(pkcs7);
  69520. pkcs7 = NULL;
  69521. /* fail case, without PKCS7_NOVERIFY */
  69522. p = data;
  69523. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69524. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69525. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69526. PKCS7_free(pkcs7);
  69527. pkcs7 = NULL;
  69528. /* success case, with PKCS7_NOVERIFY */
  69529. p = data;
  69530. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69531. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69532. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  69533. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69534. /* test i2d */
  69535. XMEMCPY(key, client_key_der_2048, keySz);
  69536. if (pkcs7 != NULL) {
  69537. pkcs7->privateKey = key;
  69538. pkcs7->privateKeySz = (word32)sizeof(key);
  69539. pkcs7->encryptOID = RSAk;
  69540. #ifdef NO_SHA
  69541. pkcs7->hashOID = SHA256h;
  69542. #else
  69543. pkcs7->hashOID = SHAh;
  69544. #endif
  69545. }
  69546. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69547. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  69548. #ifndef NO_ASN_TIME
  69549. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  69550. #else
  69551. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  69552. #endif
  69553. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69554. BIO_free(bio);
  69555. #endif
  69556. PKCS7_free(NULL);
  69557. PKCS7_free(pkcs7);
  69558. #endif
  69559. return EXPECT_RESULT();
  69560. }
  69561. static int test_wolfSSL_PKCS7_sign(void)
  69562. {
  69563. EXPECT_DECLS;
  69564. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69565. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69566. PKCS7* p7 = NULL;
  69567. PKCS7* p7Ver = NULL;
  69568. byte* out = NULL;
  69569. byte* tmpPtr = NULL;
  69570. int outLen = 0;
  69571. int flags = 0;
  69572. byte data[] = "Test data to encode.";
  69573. const char* cert = "./certs/server-cert.pem";
  69574. const char* key = "./certs/server-key.pem";
  69575. const char* ca = "./certs/ca-cert.pem";
  69576. WOLFSSL_BIO* certBio = NULL;
  69577. WOLFSSL_BIO* keyBio = NULL;
  69578. WOLFSSL_BIO* caBio = NULL;
  69579. WOLFSSL_BIO* inBio = NULL;
  69580. X509* signCert = NULL;
  69581. EVP_PKEY* signKey = NULL;
  69582. X509* caCert = NULL;
  69583. X509_STORE* store = NULL;
  69584. #ifndef NO_PKCS7_STREAM
  69585. int z;
  69586. int ret;
  69587. #endif /* !NO_PKCS7_STREAM */
  69588. /* read signer cert/key into BIO */
  69589. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69590. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69591. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69592. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69593. /* read CA cert into store (for verify) */
  69594. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69595. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69596. ExpectNotNull(store = X509_STORE_new());
  69597. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69598. /* data to be signed into BIO */
  69599. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69600. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69601. /* PKCS7_sign, bad args: signer NULL */
  69602. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  69603. /* PKCS7_sign, bad args: signer key NULL */
  69604. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  69605. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  69606. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  69607. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  69608. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  69609. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  69610. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  69611. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  69612. {
  69613. flags = PKCS7_BINARY;
  69614. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69615. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69616. /* verify with d2i_PKCS7 */
  69617. tmpPtr = out;
  69618. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69619. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69620. PKCS7_free(p7Ver);
  69621. p7Ver = NULL;
  69622. /* verify with wc_PKCS7_VerifySignedData */
  69623. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69624. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69625. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69626. #ifndef NO_PKCS7_STREAM
  69627. /* verify with wc_PKCS7_VerifySignedData streaming */
  69628. wc_PKCS7_Free(p7Ver);
  69629. p7Ver = NULL;
  69630. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69631. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69632. /* test for streaming */
  69633. ret = -1;
  69634. for (z = 0; z < outLen && ret != 0; z++) {
  69635. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69636. if (ret < 0){
  69637. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69638. }
  69639. }
  69640. ExpectIntEQ(ret, 0);
  69641. #endif /* !NO_PKCS7_STREAM */
  69642. /* compare the signer found to expected signer */
  69643. ExpectIntNE(p7Ver->verifyCertSz, 0);
  69644. tmpPtr = NULL;
  69645. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  69646. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  69647. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  69648. tmpPtr = NULL;
  69649. wc_PKCS7_Free(p7Ver);
  69650. p7Ver = NULL;
  69651. ExpectNotNull(out);
  69652. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69653. out = NULL;
  69654. PKCS7_free(p7);
  69655. p7 = NULL;
  69656. }
  69657. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  69658. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  69659. {
  69660. /* re-populate input BIO, may have been consumed */
  69661. BIO_free(inBio);
  69662. inBio = NULL;
  69663. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69664. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69665. flags = PKCS7_BINARY | PKCS7_STREAM;
  69666. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69667. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69668. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69669. /* PKCS7_final, bad args: PKCS7 null */
  69670. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  69671. /* PKCS7_final, bad args: PKCS7 null */
  69672. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  69673. tmpPtr = out;
  69674. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69675. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69676. PKCS7_free(p7Ver);
  69677. p7Ver = NULL;
  69678. ExpectNotNull(out);
  69679. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69680. out = NULL;
  69681. PKCS7_free(p7);
  69682. p7 = NULL;
  69683. }
  69684. /* TEST SUCCESS: Detached, not streaming, not MIME */
  69685. {
  69686. /* re-populate input BIO, may have been consumed */
  69687. BIO_free(inBio);
  69688. inBio = NULL;
  69689. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69690. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69691. flags = PKCS7_BINARY | PKCS7_DETACHED;
  69692. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69693. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69694. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69695. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69696. if (p7Ver != NULL) {
  69697. p7Ver->content = data;
  69698. p7Ver->contentSz = sizeof(data);
  69699. }
  69700. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69701. wc_PKCS7_Free(p7Ver);
  69702. p7Ver = NULL;
  69703. #ifndef NO_PKCS7_STREAM
  69704. /* verify with wc_PKCS7_VerifySignedData streaming */
  69705. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69706. if (p7Ver != NULL) {
  69707. p7Ver->content = data;
  69708. p7Ver->contentSz = sizeof(data);
  69709. }
  69710. /* test for streaming */
  69711. ret = -1;
  69712. for (z = 0; z < outLen && ret != 0; z++) {
  69713. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69714. if (ret < 0){
  69715. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69716. }
  69717. }
  69718. ExpectIntEQ(ret, 0);
  69719. wc_PKCS7_Free(p7Ver);
  69720. p7Ver = NULL;
  69721. #endif /* !NO_PKCS7_STREAM */
  69722. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  69723. * yet support detached content */
  69724. tmpPtr = out;
  69725. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69726. PKCS7_free(p7Ver);
  69727. p7Ver = NULL;
  69728. ExpectNotNull(out);
  69729. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69730. out = NULL;
  69731. PKCS7_free(p7);
  69732. p7 = NULL;
  69733. }
  69734. /* TEST SUCCESS: Detached, streaming, not MIME */
  69735. {
  69736. /* re-populate input BIO, may have been consumed */
  69737. BIO_free(inBio);
  69738. inBio = NULL;
  69739. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69740. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69741. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  69742. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69743. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69744. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69745. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69746. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69747. if (p7Ver != NULL) {
  69748. p7Ver->content = data;
  69749. p7Ver->contentSz = sizeof(data);
  69750. }
  69751. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69752. wc_PKCS7_Free(p7Ver);
  69753. p7Ver = NULL;
  69754. ExpectNotNull(out);
  69755. #ifndef NO_PKCS7_STREAM
  69756. /* verify with wc_PKCS7_VerifySignedData streaming */
  69757. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69758. if (p7Ver != NULL) {
  69759. p7Ver->content = data;
  69760. p7Ver->contentSz = sizeof(data);
  69761. }
  69762. /* test for streaming */
  69763. ret = -1;
  69764. for (z = 0; z < outLen && ret != 0; z++) {
  69765. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69766. if (ret < 0){
  69767. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69768. }
  69769. }
  69770. ExpectIntEQ(ret, 0);
  69771. ExpectNotNull(out);
  69772. wc_PKCS7_Free(p7Ver);
  69773. p7Ver = NULL;
  69774. #endif /* !NO_PKCS7_STREAM */
  69775. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69776. PKCS7_free(p7);
  69777. p7 = NULL;
  69778. }
  69779. X509_STORE_free(store);
  69780. X509_free(caCert);
  69781. X509_free(signCert);
  69782. EVP_PKEY_free(signKey);
  69783. BIO_free(inBio);
  69784. BIO_free(keyBio);
  69785. BIO_free(certBio);
  69786. BIO_free(caBio);
  69787. #endif
  69788. return EXPECT_RESULT();
  69789. }
  69790. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  69791. {
  69792. EXPECT_DECLS;
  69793. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  69794. PKCS7_SIGNED* pkcs7 = NULL;
  69795. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  69796. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  69797. PKCS7_SIGNED_free(pkcs7);
  69798. #endif
  69799. return EXPECT_RESULT();
  69800. }
  69801. #ifndef NO_BIO
  69802. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  69803. {
  69804. EXPECT_DECLS;
  69805. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  69806. PKCS7* pkcs7 = NULL;
  69807. BIO* bio = NULL;
  69808. const byte* cert_buf = NULL;
  69809. int ret = 0;
  69810. WC_RNG rng;
  69811. const byte data[] = { /* Hello World */
  69812. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  69813. 0x72,0x6c,0x64
  69814. };
  69815. #ifndef NO_RSA
  69816. #if defined(USE_CERT_BUFFERS_2048)
  69817. byte key[sizeof(client_key_der_2048)];
  69818. byte cert[sizeof(client_cert_der_2048)];
  69819. word32 keySz = (word32)sizeof(key);
  69820. word32 certSz = (word32)sizeof(cert);
  69821. XMEMSET(key, 0, keySz);
  69822. XMEMSET(cert, 0, certSz);
  69823. XMEMCPY(key, client_key_der_2048, keySz);
  69824. XMEMCPY(cert, client_cert_der_2048, certSz);
  69825. #elif defined(USE_CERT_BUFFERS_1024)
  69826. byte key[sizeof_client_key_der_1024];
  69827. byte cert[sizeof(sizeof_client_cert_der_1024)];
  69828. word32 keySz = (word32)sizeof(key);
  69829. word32 certSz = (word32)sizeof(cert);
  69830. XMEMSET(key, 0, keySz);
  69831. XMEMSET(cert, 0, certSz);
  69832. XMEMCPY(key, client_key_der_1024, keySz);
  69833. XMEMCPY(cert, client_cert_der_1024, certSz);
  69834. #else
  69835. unsigned char cert[ONEK_BUF];
  69836. unsigned char key[ONEK_BUF];
  69837. XFILE fp = XBADFILE;
  69838. int certSz;
  69839. int keySz;
  69840. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  69841. XBADFILE);
  69842. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  69843. fp), 0);
  69844. if (fp != XBADFILE) {
  69845. XFCLOSE(fp);
  69846. fp = XBADFILE;
  69847. }
  69848. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  69849. XBADFILE);
  69850. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  69851. 0);
  69852. if (fp != XBADFILE) {
  69853. XFCLOSE(fp);
  69854. fp = XBADFILE;
  69855. }
  69856. #endif
  69857. #elif defined(HAVE_ECC)
  69858. #if defined(USE_CERT_BUFFERS_256)
  69859. unsigned char cert[sizeof(cliecc_cert_der_256)];
  69860. unsigned char key[sizeof(ecc_clikey_der_256)];
  69861. int certSz = (int)sizeof(cert);
  69862. int keySz = (int)sizeof(key);
  69863. XMEMSET(cert, 0, certSz);
  69864. XMEMSET(key, 0, keySz);
  69865. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  69866. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  69867. #else
  69868. unsigned char cert[ONEK_BUF];
  69869. unsigned char key[ONEK_BUF];
  69870. XFILE fp = XBADFILE;
  69871. int certSz, keySz;
  69872. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  69873. XBADFILE);
  69874. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  69875. fp), 0);
  69876. if (fp != XBADFILE) {
  69877. XFCLOSE(fp);
  69878. fp = XBADFILE;
  69879. }
  69880. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  69881. XBADFILE);
  69882. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  69883. 0);
  69884. if (fp != XBADFILE) {
  69885. XFCLOSE(fp);
  69886. fp = XBADFILE;
  69887. }
  69888. #endif
  69889. #else
  69890. #error PKCS7 requires ECC or RSA
  69891. #endif
  69892. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  69893. /* initialize with DER encoded cert */
  69894. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  69895. /* init rng */
  69896. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69897. ExpectIntEQ(wc_InitRng(&rng), 0);
  69898. if (pkcs7 != NULL) {
  69899. pkcs7->rng = &rng;
  69900. pkcs7->content = (byte*)data; /* not used for ex */
  69901. pkcs7->contentSz = (word32)sizeof(data);
  69902. pkcs7->contentOID = SIGNED_DATA;
  69903. pkcs7->privateKey = key;
  69904. pkcs7->privateKeySz = (word32)sizeof(key);
  69905. pkcs7->encryptOID = RSAk;
  69906. #ifdef NO_SHA
  69907. pkcs7->hashOID = SHA256h;
  69908. #else
  69909. pkcs7->hashOID = SHAh;
  69910. #endif
  69911. pkcs7->signedAttribs = NULL;
  69912. pkcs7->signedAttribsSz = 0;
  69913. }
  69914. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69915. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  69916. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  69917. /* Read PKCS#7 PEM from BIO */
  69918. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  69919. ExpectIntGE(ret, 0);
  69920. BIO_free(bio);
  69921. wc_PKCS7_Free(pkcs7);
  69922. wc_FreeRng(&rng);
  69923. #endif
  69924. return EXPECT_RESULT();
  69925. }
  69926. #ifdef HAVE_SMIME
  69927. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  69928. static int test_wolfSSL_SMIME_read_PKCS7(void)
  69929. {
  69930. EXPECT_DECLS;
  69931. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  69932. !defined(NO_RSA)
  69933. PKCS7* pkcs7 = NULL;
  69934. BIO* bio = NULL;
  69935. BIO* bcont = NULL;
  69936. BIO* out = NULL;
  69937. const byte* outBuf = NULL;
  69938. int outBufLen = 0;
  69939. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  69940. XFILE smimeTestFile = XBADFILE;
  69941. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  69942. XBADFILE);
  69943. /* smime-test.p7s */
  69944. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  69945. ExpectNotNull(bio);
  69946. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69947. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69948. ExpectNotNull(pkcs7);
  69949. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69950. PKCS7_NOVERIFY), SSL_SUCCESS);
  69951. if (smimeTestFile != XBADFILE) {
  69952. XFCLOSE(smimeTestFile);
  69953. smimeTestFile = XBADFILE;
  69954. }
  69955. if (bcont) BIO_free(bcont);
  69956. bcont = NULL;
  69957. wolfSSL_PKCS7_free(pkcs7);
  69958. pkcs7 = NULL;
  69959. /* smime-test-multipart.p7s */
  69960. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  69961. ExpectFalse(smimeTestFile == XBADFILE);
  69962. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69963. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69964. ExpectNotNull(pkcs7);
  69965. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69966. PKCS7_NOVERIFY), SSL_SUCCESS);
  69967. if (smimeTestFile != XBADFILE) {
  69968. XFCLOSE(smimeTestFile);
  69969. smimeTestFile = XBADFILE;
  69970. }
  69971. if (bcont) BIO_free(bcont);
  69972. bcont = NULL;
  69973. wolfSSL_PKCS7_free(pkcs7);
  69974. pkcs7 = NULL;
  69975. /* smime-test-multipart-badsig.p7s */
  69976. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  69977. ExpectFalse(smimeTestFile == XBADFILE);
  69978. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69979. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69980. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  69981. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69982. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69983. if (smimeTestFile != XBADFILE) {
  69984. XFCLOSE(smimeTestFile);
  69985. smimeTestFile = XBADFILE;
  69986. }
  69987. if (bcont) BIO_free(bcont);
  69988. bcont = NULL;
  69989. wolfSSL_PKCS7_free(pkcs7);
  69990. pkcs7 = NULL;
  69991. /* smime-test-canon.p7s */
  69992. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69993. ExpectFalse(smimeTestFile == XBADFILE);
  69994. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69995. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69996. ExpectNotNull(pkcs7);
  69997. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69998. PKCS7_NOVERIFY), SSL_SUCCESS);
  69999. if (smimeTestFile != XBADFILE) {
  70000. XFCLOSE(smimeTestFile);
  70001. smimeTestFile = XBADFILE;
  70002. }
  70003. if (bcont) BIO_free(bcont);
  70004. bcont = NULL;
  70005. wolfSSL_PKCS7_free(pkcs7);
  70006. pkcs7 = NULL;
  70007. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  70008. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  70009. ExpectFalse(smimeTestFile == XBADFILE);
  70010. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70011. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70012. ExpectNotNull(pkcs7);
  70013. out = wolfSSL_BIO_new(BIO_s_mem());
  70014. ExpectNotNull(out);
  70015. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  70016. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  70017. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  70018. /* Content-Type should not show up at beginning of output buffer */
  70019. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  70020. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  70021. BIO_free(out);
  70022. BIO_free(bio);
  70023. if (bcont) BIO_free(bcont);
  70024. wolfSSL_PKCS7_free(pkcs7);
  70025. #endif
  70026. return EXPECT_RESULT();
  70027. }
  70028. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  70029. static int test_wolfSSL_SMIME_write_PKCS7(void)
  70030. {
  70031. EXPECT_DECLS;
  70032. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  70033. PKCS7* p7 = NULL;
  70034. PKCS7* p7Ver = NULL;
  70035. int flags = 0;
  70036. byte data[] = "Test data to encode.";
  70037. const char* cert = "./certs/server-cert.pem";
  70038. const char* key = "./certs/server-key.pem";
  70039. const char* ca = "./certs/ca-cert.pem";
  70040. WOLFSSL_BIO* certBio = NULL;
  70041. WOLFSSL_BIO* keyBio = NULL;
  70042. WOLFSSL_BIO* caBio = NULL;
  70043. WOLFSSL_BIO* inBio = NULL;
  70044. WOLFSSL_BIO* outBio = NULL;
  70045. WOLFSSL_BIO* content = NULL;
  70046. X509* signCert = NULL;
  70047. EVP_PKEY* signKey = NULL;
  70048. X509* caCert = NULL;
  70049. X509_STORE* store = NULL;
  70050. /* read signer cert/key into BIO */
  70051. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  70052. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  70053. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  70054. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  70055. /* read CA cert into store (for verify) */
  70056. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  70057. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  70058. ExpectNotNull(store = X509_STORE_new());
  70059. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  70060. /* generate and verify SMIME: not detached */
  70061. {
  70062. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70063. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70064. flags = PKCS7_STREAM;
  70065. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70066. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70067. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70068. /* bad arg: out NULL */
  70069. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  70070. /* bad arg: pkcs7 NULL */
  70071. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  70072. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70073. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70074. BIO_free(content);
  70075. content = NULL;
  70076. BIO_free(inBio);
  70077. inBio = NULL;
  70078. BIO_free(outBio);
  70079. outBio = NULL;
  70080. PKCS7_free(p7Ver);
  70081. p7Ver = NULL;
  70082. PKCS7_free(p7);
  70083. p7 = NULL;
  70084. }
  70085. /* generate and verify SMIME: not detached, add Content-Type */
  70086. {
  70087. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70088. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70089. flags = PKCS7_STREAM | PKCS7_TEXT;
  70090. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70091. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70092. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70093. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70094. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70095. BIO_free(content);
  70096. content = NULL;
  70097. BIO_free(inBio);
  70098. inBio = NULL;
  70099. BIO_free(outBio);
  70100. outBio = NULL;
  70101. PKCS7_free(p7Ver);
  70102. p7Ver = NULL;
  70103. PKCS7_free(p7);
  70104. p7 = NULL;
  70105. }
  70106. /* generate and verify SMIME: detached */
  70107. {
  70108. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70109. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70110. flags = PKCS7_DETACHED | PKCS7_STREAM;
  70111. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70112. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70113. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70114. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70115. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70116. BIO_free(content);
  70117. content = NULL;
  70118. BIO_free(inBio);
  70119. inBio = NULL;
  70120. BIO_free(outBio);
  70121. outBio = NULL;
  70122. PKCS7_free(p7Ver);
  70123. p7Ver = NULL;
  70124. PKCS7_free(p7);
  70125. p7 = NULL;
  70126. }
  70127. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  70128. {
  70129. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70130. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70131. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  70132. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70133. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70134. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70135. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70136. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70137. BIO_free(content);
  70138. content = NULL;
  70139. BIO_free(inBio);
  70140. inBio = NULL;
  70141. BIO_free(outBio);
  70142. outBio = NULL;
  70143. PKCS7_free(p7Ver);
  70144. p7Ver = NULL;
  70145. PKCS7_free(p7);
  70146. p7 = NULL;
  70147. }
  70148. X509_STORE_free(store);
  70149. X509_free(caCert);
  70150. X509_free(signCert);
  70151. EVP_PKEY_free(signKey);
  70152. BIO_free(keyBio);
  70153. BIO_free(certBio);
  70154. BIO_free(caBio);
  70155. #endif
  70156. return EXPECT_RESULT();
  70157. }
  70158. #endif /* HAVE_SMIME */
  70159. #endif /* !NO_BIO */
  70160. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  70161. * returns 0) */
  70162. static int test_X509_STORE_No_SSL_CTX(void)
  70163. {
  70164. EXPECT_DECLS;
  70165. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  70166. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  70167. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  70168. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  70169. defined(HAVE_CRL) && !defined(NO_RSA)
  70170. X509_STORE * store = NULL;
  70171. X509_STORE_CTX * storeCtx = NULL;
  70172. X509_CRL * crl = NULL;
  70173. X509 * ca = NULL;
  70174. X509 * cert = NULL;
  70175. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  70176. const char srvCert[] = "./certs/server-cert.pem";
  70177. const char caCert[] = "./certs/ca-cert.pem";
  70178. const char caDir[] = "./certs/crl/hash_pem";
  70179. XFILE fp = XBADFILE;
  70180. X509_LOOKUP * lookup = NULL;
  70181. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70182. /* Set up store with CA */
  70183. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70184. SSL_FILETYPE_PEM)));
  70185. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70186. /* Add CRL lookup directory to store
  70187. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  70188. * of crl.pem */
  70189. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70190. X509_LOOKUP_hash_dir())));
  70191. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  70192. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  70193. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70194. SSL_SUCCESS);
  70195. /* Add CRL to store NOT containing the verified certificate, which
  70196. * forces use of the CRL lookup directory */
  70197. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70198. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70199. NULL, NULL));
  70200. if (fp != XBADFILE)
  70201. XFCLOSE(fp);
  70202. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70203. /* Create verification context outside of an SSL session */
  70204. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70205. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70206. SSL_FILETYPE_PEM)));
  70207. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70208. /* Perform verification, which should NOT indicate CRL missing due to the
  70209. * store CM's X509 store pointer being NULL */
  70210. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  70211. X509_CRL_free(crl);
  70212. X509_STORE_free(store);
  70213. X509_STORE_CTX_free(storeCtx);
  70214. X509_free(cert);
  70215. X509_free(ca);
  70216. #endif
  70217. return EXPECT_RESULT();
  70218. }
  70219. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  70220. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  70221. static int test_X509_LOOKUP_add_dir(void)
  70222. {
  70223. EXPECT_DECLS;
  70224. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  70225. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  70226. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  70227. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  70228. defined(HAVE_CRL) && !defined(NO_RSA)
  70229. X509_STORE * store = NULL;
  70230. X509_STORE_CTX * storeCtx = NULL;
  70231. X509_CRL * crl = NULL;
  70232. X509 * ca = NULL;
  70233. X509 * cert = NULL;
  70234. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  70235. const char srvCert[] = "./certs/server-cert.pem";
  70236. const char caCert[] = "./certs/ca-cert.pem";
  70237. const char caDir[] = "./certs/crl/hash_der";
  70238. XFILE fp = XBADFILE;
  70239. X509_LOOKUP * lookup = NULL;
  70240. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70241. /* Set up store with CA */
  70242. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70243. SSL_FILETYPE_PEM)));
  70244. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70245. /* Add CRL lookup directory to store.
  70246. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  70247. * of crl.der */
  70248. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70249. X509_LOOKUP_hash_dir())));
  70250. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  70251. SSL_SUCCESS);
  70252. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70253. SSL_SUCCESS);
  70254. /* Add CRL to store NOT containing the verified certificate, which
  70255. * forces use of the CRL lookup directory */
  70256. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70257. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70258. NULL, NULL));
  70259. if (fp != XBADFILE) {
  70260. XFCLOSE(fp);
  70261. fp = XBADFILE;
  70262. }
  70263. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70264. /* Create verification context outside of an SSL session */
  70265. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70266. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70267. SSL_FILETYPE_PEM)));
  70268. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70269. /* Perform verification, which should NOT return CRL missing */
  70270. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  70271. X509_CRL_free(crl);
  70272. crl = NULL;
  70273. X509_STORE_free(store);
  70274. store = NULL;
  70275. X509_STORE_CTX_free(storeCtx);
  70276. storeCtx = NULL;
  70277. X509_free(cert);
  70278. cert = NULL;
  70279. X509_free(ca);
  70280. ca = NULL;
  70281. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  70282. * We should get CRL_MISSING at the end, because the lookup
  70283. * dir has only ASN1 CRLs. */
  70284. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70285. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70286. SSL_FILETYPE_PEM)));
  70287. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70288. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70289. X509_LOOKUP_hash_dir())));
  70290. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  70291. SSL_SUCCESS);
  70292. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70293. SSL_SUCCESS);
  70294. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70295. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70296. NULL, NULL));
  70297. if (fp != XBADFILE) {
  70298. XFCLOSE(fp);
  70299. fp = XBADFILE;
  70300. }
  70301. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70302. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70303. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70304. SSL_FILETYPE_PEM)));
  70305. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70306. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  70307. * in dir containing only ASN1/DER. */
  70308. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70309. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  70310. X509_V_ERR_UNABLE_TO_GET_CRL);
  70311. X509_CRL_free(crl);
  70312. X509_STORE_free(store);
  70313. X509_STORE_CTX_free(storeCtx);
  70314. X509_free(cert);
  70315. X509_free(ca);
  70316. #endif
  70317. return EXPECT_RESULT();
  70318. }
  70319. /*----------------------------------------------------------------------------*
  70320. | Certificate Failure Checks
  70321. *----------------------------------------------------------------------------*/
  70322. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  70323. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  70324. #if !defined(NO_RSA) || defined(HAVE_ECC)
  70325. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  70326. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  70327. int type)
  70328. {
  70329. int ret;
  70330. WOLFSSL_CERT_MANAGER* cm = NULL;
  70331. switch (type) {
  70332. case TESTING_RSA:
  70333. #ifdef NO_RSA
  70334. fprintf(stderr, "RSA disabled, skipping test\n");
  70335. return ASN_SIG_CONFIRM_E;
  70336. #else
  70337. break;
  70338. #endif
  70339. case TESTING_ECC:
  70340. #ifndef HAVE_ECC
  70341. fprintf(stderr, "ECC disabled, skipping test\n");
  70342. return ASN_SIG_CONFIRM_E;
  70343. #else
  70344. break;
  70345. #endif
  70346. default:
  70347. fprintf(stderr, "Bad function argument\n");
  70348. return BAD_FUNC_ARG;
  70349. }
  70350. cm = wolfSSL_CertManagerNew();
  70351. if (cm == NULL) {
  70352. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  70353. return -1;
  70354. }
  70355. #ifndef NO_FILESYSTEM
  70356. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  70357. if (ret != WOLFSSL_SUCCESS) {
  70358. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  70359. wolfSSL_CertManagerFree(cm);
  70360. return ret;
  70361. }
  70362. #else
  70363. (void)ca;
  70364. #endif
  70365. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  70366. WOLFSSL_FILETYPE_ASN1);
  70367. /* Let ExpectIntEQ handle return code */
  70368. wolfSSL_CertManagerFree(cm);
  70369. return ret;
  70370. }
  70371. #endif
  70372. #if !defined(NO_FILESYSTEM)
  70373. static int test_RsaSigFailure_cm(void)
  70374. {
  70375. EXPECT_DECLS;
  70376. #ifndef NO_RSA
  70377. const char* ca_cert = "./certs/ca-cert.pem";
  70378. const char* server_cert = "./certs/server-cert.der";
  70379. byte* cert_buf = NULL;
  70380. size_t cert_sz = 0;
  70381. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70382. if ((cert_buf != NULL) && (cert_sz > 0)) {
  70383. /* corrupt DER - invert last byte, which is signature */
  70384. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70385. /* test bad cert */
  70386. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70387. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70388. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70389. #elif defined(NO_ASN_CRYPT)
  70390. /* RSA verify is not called when ASN crypt support is disabled */
  70391. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70392. WOLFSSL_SUCCESS);
  70393. #else
  70394. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70395. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70396. #endif
  70397. }
  70398. /* load_file() uses malloc. */
  70399. if (cert_buf != NULL) {
  70400. free(cert_buf);
  70401. }
  70402. #endif /* !NO_RSA */
  70403. return EXPECT_RESULT();
  70404. }
  70405. static int test_EccSigFailure_cm(void)
  70406. {
  70407. EXPECT_DECLS;
  70408. #ifdef HAVE_ECC
  70409. /* self-signed ECC cert, so use server cert as CA */
  70410. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  70411. const char* server_cert = "./certs/server-ecc.der";
  70412. byte* cert_buf = NULL;
  70413. size_t cert_sz = 0;
  70414. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70415. if (cert_buf != NULL && cert_sz > 0) {
  70416. /* corrupt DER - invert last byte, which is signature */
  70417. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70418. /* test bad cert */
  70419. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70420. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70421. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70422. #elif defined(NO_ASN_CRYPT)
  70423. /* ECC verify is not called when ASN crypt support is disabled */
  70424. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70425. WOLFSSL_SUCCESS);
  70426. #else
  70427. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70428. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70429. #endif
  70430. }
  70431. /* load_file() uses malloc. */
  70432. if (cert_buf != NULL) {
  70433. free(cert_buf);
  70434. }
  70435. #ifdef FP_ECC
  70436. wc_ecc_fp_free();
  70437. #endif
  70438. #endif /* HAVE_ECC */
  70439. return EXPECT_RESULT();
  70440. }
  70441. #endif /* !NO_FILESYSTEM */
  70442. #endif /* NO_CERTS */
  70443. #ifdef WOLFSSL_TLS13
  70444. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  70445. #ifdef WC_SHA384_DIGEST_SIZE
  70446. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  70447. #else
  70448. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  70449. #endif
  70450. #endif
  70451. #ifdef WOLFSSL_EARLY_DATA
  70452. static const char earlyData[] = "Early Data";
  70453. static char earlyDataBuffer[1];
  70454. #endif
  70455. static int test_tls13_apis(void)
  70456. {
  70457. EXPECT_DECLS;
  70458. int ret;
  70459. #ifndef WOLFSSL_NO_TLS12
  70460. #ifndef NO_WOLFSSL_CLIENT
  70461. WOLFSSL_CTX* clientTls12Ctx = NULL;
  70462. WOLFSSL* clientTls12Ssl = NULL;
  70463. #endif
  70464. #ifndef NO_WOLFSSL_SERVER
  70465. WOLFSSL_CTX* serverTls12Ctx = NULL;
  70466. WOLFSSL* serverTls12Ssl = NULL;
  70467. #endif
  70468. #endif
  70469. #ifndef NO_WOLFSSL_CLIENT
  70470. WOLFSSL_CTX* clientCtx = NULL;
  70471. WOLFSSL* clientSsl = NULL;
  70472. #endif
  70473. #ifndef NO_WOLFSSL_SERVER
  70474. WOLFSSL_CTX* serverCtx = NULL;
  70475. WOLFSSL* serverSsl = NULL;
  70476. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70477. const char* ourCert = svrCertFile;
  70478. const char* ourKey = svrKeyFile;
  70479. #endif
  70480. #endif
  70481. int required;
  70482. #ifdef WOLFSSL_EARLY_DATA
  70483. int outSz;
  70484. #endif
  70485. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  70486. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  70487. #ifdef WOLFSSL_HAVE_KYBER
  70488. #ifndef WOLFSSL_NO_KYBER512
  70489. WOLFSSL_KYBER_LEVEL1
  70490. #elif !defined(WOLFSSL_NO_KYBER768)
  70491. WOLFSSL_KYBER_LEVEL3
  70492. #else
  70493. WOLFSSL_KYBER_LEVEL5
  70494. #endif
  70495. #else
  70496. WOLFSSL_ECC_SECP256R1
  70497. #endif
  70498. };
  70499. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  70500. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  70501. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  70502. int numGroups = 2;
  70503. #endif
  70504. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70505. char groupList[] =
  70506. #ifdef HAVE_CURVE25519
  70507. "X25519:"
  70508. #endif
  70509. #ifdef HAVE_CURVE448
  70510. "X448:"
  70511. #endif
  70512. #ifndef NO_ECC_SECP
  70513. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  70514. "P-521:secp521r1:"
  70515. #endif
  70516. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  70517. "P-384:secp384r1:"
  70518. #endif
  70519. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  70520. "P-256:secp256r1"
  70521. #if defined(WOLFSSL_HAVE_KYBER)
  70522. #ifndef WOLFSSL_NO_KYBER512
  70523. ":P256_KYBER_LEVEL1"
  70524. #elif !defined(WOLFSSL_NO_KYBER768)
  70525. ":P256_KYBER_LEVEL3"
  70526. #else
  70527. ":P256_KYBER_LEVEL5"
  70528. #endif
  70529. #endif
  70530. #endif
  70531. #endif /* !defined(NO_ECC_SECP) */
  70532. #if defined(WOLFSSL_HAVE_KYBER)
  70533. #ifndef WOLFSSL_NO_KYBER512
  70534. ":KYBER_LEVEL1"
  70535. #elif !defined(WOLFSSL_NO_KYBER768)
  70536. ":KYBER_LEVEL3"
  70537. #else
  70538. ":KYBER_LEVEL5"
  70539. #endif
  70540. #endif
  70541. "";
  70542. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  70543. #if defined(WOLFSSL_HAVE_KYBER)
  70544. int kyberLevel;
  70545. #endif
  70546. (void)ret;
  70547. #ifndef WOLFSSL_NO_TLS12
  70548. #ifndef NO_WOLFSSL_CLIENT
  70549. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  70550. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  70551. #endif
  70552. #ifndef NO_WOLFSSL_SERVER
  70553. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  70554. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70555. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  70556. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  70557. WOLFSSL_FILETYPE_PEM);
  70558. #endif
  70559. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  70560. #endif
  70561. #endif
  70562. #ifndef NO_WOLFSSL_CLIENT
  70563. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  70564. clientSsl = wolfSSL_new(clientCtx);
  70565. #endif
  70566. #ifndef NO_WOLFSSL_SERVER
  70567. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  70568. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70569. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  70570. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  70571. #endif
  70572. serverSsl = wolfSSL_new(serverCtx);
  70573. ExpectNotNull(serverSsl);
  70574. #endif
  70575. #ifdef WOLFSSL_SEND_HRR_COOKIE
  70576. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70577. #ifndef NO_WOLFSSL_CLIENT
  70578. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70579. #endif
  70580. #ifndef NO_WOLFSSL_SERVER
  70581. #ifndef WOLFSSL_NO_TLS12
  70582. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  70583. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70584. #endif
  70585. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  70586. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  70587. WOLFSSL_SUCCESS);
  70588. #endif
  70589. #endif
  70590. #ifdef HAVE_SUPPORTED_CURVES
  70591. #ifdef HAVE_ECC
  70592. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70594. #ifndef NO_WOLFSSL_SERVER
  70595. do {
  70596. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  70597. #ifdef WOLFSSL_ASYNC_CRYPT
  70598. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70599. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  70600. #endif
  70601. }
  70602. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70603. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70604. #endif
  70605. #ifndef NO_WOLFSSL_CLIENT
  70606. #ifndef WOLFSSL_NO_TLS12
  70607. do {
  70608. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  70609. #ifdef WOLFSSL_ASYNC_CRYPT
  70610. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70611. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  70612. #endif
  70613. }
  70614. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70615. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70616. #endif
  70617. do {
  70618. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  70619. #ifdef WOLFSSL_ASYNC_CRYPT
  70620. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70621. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  70622. #endif
  70623. }
  70624. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70625. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70626. #endif
  70627. #elif defined(HAVE_CURVE25519)
  70628. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70629. #ifndef NO_WOLFSSL_SERVER
  70630. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  70631. WOLFSSL_SUCCESS);
  70632. #endif
  70633. #ifndef NO_WOLFSSL_CLIENT
  70634. #ifndef WOLFSSL_NO_TLS12
  70635. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  70636. WOLFSSL_SUCCESS);
  70637. #endif
  70638. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  70639. WOLFSSL_SUCCESS);
  70640. #endif
  70641. #elif defined(HAVE_CURVE448)
  70642. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70643. #ifndef NO_WOLFSSL_SERVER
  70644. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  70645. WOLFSSL_SUCCESS);
  70646. #endif
  70647. #ifndef NO_WOLFSSL_CLIENT
  70648. #ifndef WOLFSSL_NO_TLS12
  70649. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  70650. WOLFSSL_SUCCESS);
  70651. #endif
  70652. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  70653. WOLFSSL_SUCCESS);
  70654. #endif
  70655. #else
  70656. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70657. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70658. #ifndef NO_WOLFSSL_CLIENT
  70659. #ifndef WOLFSSL_NO_TLS12
  70660. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  70661. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70662. #endif
  70663. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  70664. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70665. #endif
  70666. #endif
  70667. #if defined(WOLFSSL_HAVE_KYBER)
  70668. #ifndef WOLFSSL_NO_KYBER768
  70669. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  70670. #elif !defined(WOLFSSL_NO_KYBER1024)
  70671. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  70672. #else
  70673. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  70674. #endif
  70675. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70676. #ifndef NO_WOLFSSL_SERVER
  70677. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  70678. WOLFSSL_SUCCESS);
  70679. #endif
  70680. #ifndef NO_WOLFSSL_CLIENT
  70681. #ifndef WOLFSSL_NO_TLS12
  70682. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  70683. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70684. #endif
  70685. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  70686. WOLFSSL_SUCCESS);
  70687. #endif
  70688. #endif
  70689. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70690. #ifndef NO_WOLFSSL_SERVER
  70691. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70692. #endif
  70693. #ifndef NO_WOLFSSL_CLIENT
  70694. #ifndef WOLFSSL_NO_TLS12
  70695. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  70696. #endif
  70697. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  70698. #endif
  70699. #endif /* HAVE_SUPPORTED_CURVES */
  70700. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70701. #ifndef NO_WOLFSSL_CLIENT
  70702. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70703. #endif
  70704. #ifndef NO_WOLFSSL_SERVER
  70705. #ifndef WOLFSSL_NO_TLS12
  70706. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70707. #endif
  70708. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  70709. #endif
  70710. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70711. #ifndef NO_WOLFSSL_CLIENT
  70712. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70713. #endif
  70714. #ifndef NO_WOLFSSL_SERVER
  70715. #ifndef WOLFSSL_NO_TLS12
  70716. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70717. #endif
  70718. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  70719. #endif
  70720. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70721. #ifndef NO_WOLFSSL_CLIENT
  70722. #ifndef WOLFSSL_NO_TLS12
  70723. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70724. #endif
  70725. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  70726. #endif
  70727. #ifndef NO_WOLFSSL_SERVER
  70728. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  70729. #endif
  70730. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70731. #ifndef NO_WOLFSSL_CLIENT
  70732. #ifndef WOLFSSL_NO_TLS12
  70733. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70734. #endif
  70735. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  70736. #endif
  70737. #ifndef NO_WOLFSSL_SERVER
  70738. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  70739. #endif
  70740. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70741. #ifndef NO_WOLFSSL_CLIENT
  70742. #ifndef WOLFSSL_NO_TLS12
  70743. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70744. #endif
  70745. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70746. #endif
  70747. #ifndef NO_WOLFSSL_SERVER
  70748. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70749. #endif
  70750. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70751. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70752. #ifndef NO_WOLFSSL_CLIENT
  70753. #ifndef WOLFSSL_NO_TLS12
  70754. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  70755. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70756. #endif
  70757. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70758. #endif
  70759. #ifndef NO_WOLFSSL_SERVER
  70760. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70761. #endif
  70762. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  70763. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70764. #ifndef NO_WOLFSSL_SERVER
  70765. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70766. #endif
  70767. #ifndef NO_WOLFSSL_CLIENT
  70768. #ifndef WOLFSSL_NO_TLS12
  70769. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  70770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70771. #endif
  70772. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  70773. #endif
  70774. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70775. #ifndef NO_WOLFSSL_SERVER
  70776. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70777. #endif
  70778. #ifndef NO_WOLFSSL_CLIENT
  70779. #ifndef WOLFSSL_NO_TLS12
  70780. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  70781. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70782. #endif
  70783. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  70784. #endif
  70785. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70786. #ifndef NO_WOLFSSL_CLIENT
  70787. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70788. #endif
  70789. #ifndef NO_WOLFSSL_SERVER
  70790. #ifndef WOLFSSL_NO_TLS12
  70791. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  70792. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70793. #endif
  70794. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70795. #endif
  70796. #endif
  70797. #ifdef HAVE_ECC
  70798. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  70799. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70800. #ifndef NO_WOLFSSL_SERVER
  70801. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70802. #endif
  70803. #ifndef NO_WOLFSSL_CLIENT
  70804. #ifndef WOLFSSL_NO_TLS12
  70805. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70806. #endif
  70807. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70808. #endif
  70809. #endif
  70810. #ifdef HAVE_SUPPORTED_CURVES
  70811. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70812. #ifndef NO_WOLFSSL_CLIENT
  70813. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70814. #endif
  70815. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70816. #ifndef NO_WOLFSSL_CLIENT
  70817. #ifndef WOLFSSL_NO_TLS12
  70818. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  70819. WOLFSSL_SUCCESS);
  70820. #endif
  70821. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  70822. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70823. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  70824. WOLFSSL_SUCCESS);
  70825. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  70826. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70827. #endif
  70828. #ifndef NO_WOLFSSL_SERVER
  70829. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  70830. WOLFSSL_SUCCESS);
  70831. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  70832. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70833. #endif
  70834. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70835. #ifndef NO_WOLFSSL_CLIENT
  70836. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70837. #endif
  70838. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70839. #ifndef NO_WOLFSSL_CLIENT
  70840. #ifndef WOLFSSL_NO_TLS12
  70841. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  70842. WOLFSSL_SUCCESS);
  70843. #endif
  70844. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  70845. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70846. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  70847. WOLFSSL_SUCCESS);
  70848. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  70849. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70850. #endif
  70851. #ifndef NO_WOLFSSL_SERVER
  70852. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  70853. WOLFSSL_SUCCESS);
  70854. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  70855. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70856. #endif
  70857. #ifdef OPENSSL_EXTRA
  70858. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70859. #ifndef NO_WOLFSSL_CLIENT
  70860. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  70861. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70862. #endif
  70863. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  70864. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70865. #ifndef NO_WOLFSSL_CLIENT
  70866. #ifndef WOLFSSL_NO_TLS12
  70867. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  70868. WOLFSSL_SUCCESS);
  70869. #endif
  70870. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  70871. WOLFSSL_SUCCESS);
  70872. #endif
  70873. #ifndef NO_WOLFSSL_SERVER
  70874. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  70875. WOLFSSL_SUCCESS);
  70876. #endif
  70877. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70878. #ifndef NO_WOLFSSL_CLIENT
  70879. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70880. #endif
  70881. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70882. #ifndef NO_WOLFSSL_CLIENT
  70883. #ifndef WOLFSSL_NO_TLS12
  70884. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  70885. WOLFSSL_SUCCESS);
  70886. #endif
  70887. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  70888. WOLFSSL_SUCCESS);
  70889. #endif
  70890. #ifndef NO_WOLFSSL_SERVER
  70891. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  70892. WOLFSSL_SUCCESS);
  70893. #endif
  70894. #endif /* OPENSSL_EXTRA */
  70895. #endif /* HAVE_SUPPORTED_CURVES */
  70896. #endif /* HAVE_ECC */
  70897. #ifdef WOLFSSL_EARLY_DATA
  70898. #ifndef OPENSSL_EXTRA
  70899. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70900. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70901. #else
  70902. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70903. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70904. #endif
  70905. #ifndef NO_WOLFSSL_CLIENT
  70906. #ifndef OPENSSL_EXTRA
  70907. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70908. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70909. #else
  70910. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70911. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70912. #endif
  70913. #endif
  70914. #ifndef NO_WOLFSSL_SERVER
  70915. #ifndef WOLFSSL_NO_TLS12
  70916. #ifndef OPENSSL_EXTRA
  70917. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70919. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70920. #else
  70921. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70923. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70924. #endif
  70925. #endif
  70926. #ifndef OPENSSL_EXTRA
  70927. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70928. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  70929. WOLFSSL_SUCCESS);
  70930. #else
  70931. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  70932. #endif
  70933. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  70934. #else
  70935. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  70936. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  70937. #endif
  70938. #endif
  70939. #ifndef OPENSSL_EXTRA
  70940. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70941. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70942. #else
  70943. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70944. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70945. #endif
  70946. #ifndef NO_WOLFSSL_CLIENT
  70947. #ifndef OPENSSL_EXTRA
  70948. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70949. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70950. #else
  70951. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  70952. #endif
  70953. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  70954. #else
  70955. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70956. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  70957. #endif
  70958. #endif
  70959. #ifndef NO_WOLFSSL_SERVER
  70960. #ifndef WOLFSSL_NO_TLS12
  70961. #ifndef OPENSSL_EXTRA
  70962. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70963. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70964. #else
  70965. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70966. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70967. #endif
  70968. #endif
  70969. #ifndef OPENSSL_EXTRA
  70970. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70971. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  70972. #else
  70973. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  70974. #endif
  70975. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  70976. #else
  70977. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  70978. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  70979. #endif
  70980. #endif
  70981. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  70982. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70983. #ifndef NO_WOLFSSL_CLIENT
  70984. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  70985. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70986. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  70987. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70988. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70989. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70990. #endif
  70991. #ifndef NO_WOLFSSL_SERVER
  70992. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  70993. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70994. #endif
  70995. #ifndef NO_WOLFSSL_CLIENT
  70996. #ifndef WOLFSSL_NO_TLS12
  70997. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  70998. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70999. #endif
  71000. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  71001. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71002. #endif
  71003. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  71004. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71005. #ifndef NO_WOLFSSL_SERVER
  71006. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  71007. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71008. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  71009. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71010. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71011. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71012. #endif
  71013. #ifndef NO_WOLFSSL_CLIENT
  71014. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  71015. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  71016. #endif
  71017. #ifndef NO_WOLFSSL_SERVER
  71018. #ifndef WOLFSSL_NO_TLS12
  71019. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  71020. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71021. #endif
  71022. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71023. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71024. #endif
  71025. #endif
  71026. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  71027. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  71028. #endif
  71029. #ifndef NO_WOLFSSL_SERVER
  71030. wolfSSL_free(serverSsl);
  71031. wolfSSL_CTX_free(serverCtx);
  71032. #endif
  71033. #ifndef NO_WOLFSSL_CLIENT
  71034. wolfSSL_free(clientSsl);
  71035. wolfSSL_CTX_free(clientCtx);
  71036. #endif
  71037. #ifndef WOLFSSL_NO_TLS12
  71038. #ifndef NO_WOLFSSL_SERVER
  71039. wolfSSL_free(serverTls12Ssl);
  71040. wolfSSL_CTX_free(serverTls12Ctx);
  71041. #endif
  71042. #ifndef NO_WOLFSSL_CLIENT
  71043. wolfSSL_free(clientTls12Ssl);
  71044. wolfSSL_CTX_free(clientTls12Ctx);
  71045. #endif
  71046. #endif
  71047. return EXPECT_RESULT();
  71048. }
  71049. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71050. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71051. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71052. /* Called when writing. */
  71053. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71054. {
  71055. (void)ssl;
  71056. (void)buf;
  71057. (void)sz;
  71058. (void)ctx;
  71059. /* Force error return from wolfSSL_accept_TLSv13(). */
  71060. return WANT_WRITE;
  71061. }
  71062. /* Called when reading. */
  71063. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71064. {
  71065. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  71066. int len = (int)msg->length;
  71067. (void)ssl;
  71068. (void)sz;
  71069. /* Pass back as much of message as will fit in buffer. */
  71070. if (len > sz)
  71071. len = sz;
  71072. XMEMCPY(buf, msg->buffer, len);
  71073. /* Move over returned data. */
  71074. msg->buffer += len;
  71075. msg->length -= len;
  71076. /* Amount actually copied. */
  71077. return len;
  71078. }
  71079. #endif
  71080. static int test_tls13_cipher_suites(void)
  71081. {
  71082. EXPECT_DECLS;
  71083. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71084. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71085. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71086. WOLFSSL_CTX* ctx = NULL;
  71087. WOLFSSL *ssl = NULL;
  71088. int i;
  71089. byte clientHello[] = {
  71090. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  71091. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  71092. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  71093. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  71094. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  71095. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  71096. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  71097. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  71098. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71099. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  71100. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  71101. 0x13, 0x01,
  71102. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  71103. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  71104. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  71105. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  71106. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  71107. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  71108. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  71109. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  71110. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  71111. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  71112. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  71113. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  71114. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  71115. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  71116. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  71117. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  71118. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  71119. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  71120. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  71121. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  71122. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  71123. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  71124. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  71125. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  71126. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  71127. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  71128. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  71129. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  71130. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  71131. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  71132. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  71133. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  71134. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  71135. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  71136. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  71137. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71138. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71139. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  71140. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  71141. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  71142. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  71143. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  71144. };
  71145. WOLFSSL_BUFFER_INFO msg;
  71146. /* Offset into ClientHello message data of first cipher suite. */
  71147. const int csOff = 78;
  71148. /* Server cipher list. */
  71149. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  71150. /* Suite list with duplicates. */
  71151. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  71152. "TLS13-AES128-GCM-SHA256:"
  71153. "TLS13-AES256-GCM-SHA384:"
  71154. "TLS13-AES256-GCM-SHA384:"
  71155. "TLS13-AES128-GCM-SHA256";
  71156. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  71157. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71158. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71159. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71160. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71161. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  71162. #endif
  71163. /* Set up wolfSSL context. */
  71164. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  71165. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  71166. WOLFSSL_FILETYPE_PEM));
  71167. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  71168. WOLFSSL_FILETYPE_PEM));
  71169. /* Read from 'msg'. */
  71170. wolfSSL_SetIORecv(ctx, CsRecv);
  71171. /* No where to send to - dummy sender. */
  71172. wolfSSL_SetIOSend(ctx, CsSend);
  71173. /* Test cipher suite list with many copies of a cipher suite. */
  71174. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71175. msg.buffer = clientHello;
  71176. msg.length = (unsigned int)sizeof(clientHello);
  71177. wolfSSL_SetIOReadCtx(ssl, &msg);
  71178. /* Force server to have as many occurrences of same cipher suite as
  71179. * possible. */
  71180. if (ssl != NULL) {
  71181. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  71182. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  71183. for (i = 0; i < suites->suiteSz; i += 2) {
  71184. suites->suites[i + 0] = TLS13_BYTE;
  71185. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  71186. }
  71187. }
  71188. /* Test multiple occurrences of same cipher suite. */
  71189. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71190. wolfSSL_free(ssl);
  71191. ssl = NULL;
  71192. /* Set client order opposite to server order:
  71193. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  71194. clientHello[csOff + 0] = TLS13_BYTE;
  71195. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  71196. clientHello[csOff + 2] = TLS13_BYTE;
  71197. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  71198. /* Test server order negotiation. */
  71199. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71200. msg.buffer = clientHello;
  71201. msg.length = (unsigned int)sizeof(clientHello);
  71202. wolfSSL_SetIOReadCtx(ssl, &msg);
  71203. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  71204. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  71205. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  71206. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71207. /* Check refined order - server order. */
  71208. ExpectIntEQ(ssl->suites->suiteSz, 4);
  71209. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  71210. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  71211. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  71212. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  71213. wolfSSL_free(ssl);
  71214. ssl = NULL;
  71215. /* Test client order negotiation. */
  71216. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71217. msg.buffer = clientHello;
  71218. msg.length = (unsigned int)sizeof(clientHello);
  71219. wolfSSL_SetIOReadCtx(ssl, &msg);
  71220. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  71221. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  71222. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  71223. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  71224. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71225. /* Check refined order - client order. */
  71226. ExpectIntEQ(ssl->suites->suiteSz, 4);
  71227. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  71228. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  71229. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  71230. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  71231. wolfSSL_free(ssl);
  71232. ssl = NULL;
  71233. /* Check duplicate detection is working. */
  71234. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  71235. ExpectIntEQ(ctx->suites->suiteSz, 4);
  71236. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  71237. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  71238. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  71239. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  71240. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  71241. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  71242. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  71243. ExpectIntEQ(ctx->suites->suiteSz, 4);
  71244. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  71245. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  71246. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  71247. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  71248. #endif
  71249. wolfSSL_CTX_free(ctx);
  71250. #endif
  71251. return EXPECT_RESULT();
  71252. }
  71253. #endif
  71254. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  71255. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  71256. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  71257. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  71258. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  71259. const unsigned char* priv, unsigned int privSz,
  71260. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  71261. unsigned char* out, unsigned int* outlen,
  71262. void* ctx)
  71263. {
  71264. int result;
  71265. /* Test fail when context associated with WOLFSSL is NULL */
  71266. if (ctx == NULL) {
  71267. return -1;
  71268. }
  71269. (void)ssl;
  71270. /* return 0 on success */
  71271. PRIVATE_KEY_UNLOCK();
  71272. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  71273. PRIVATE_KEY_LOCK();
  71274. return result;
  71275. }
  71276. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  71277. EXPECT_DECLS;
  71278. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  71279. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  71280. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  71281. WOLFSSL_SUCCESS);
  71282. #endif
  71283. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  71284. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  71285. WOLFSSL_SUCCESS);
  71286. #endif
  71287. return EXPECT_RESULT();
  71288. }
  71289. static int test_dh_ssl_setup(WOLFSSL* ssl)
  71290. {
  71291. EXPECT_DECLS;
  71292. static int dh_test_ctx = 1;
  71293. int ret;
  71294. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  71295. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  71296. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71297. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71298. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71299. }
  71300. return EXPECT_RESULT();
  71301. }
  71302. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  71303. {
  71304. EXPECT_DECLS;
  71305. int ret;
  71306. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  71307. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  71308. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71309. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71310. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71311. }
  71312. return EXPECT_RESULT();
  71313. }
  71314. #endif
  71315. static int test_DhCallbacks(void)
  71316. {
  71317. EXPECT_DECLS;
  71318. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  71319. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  71320. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  71321. WOLFSSL_CTX *ctx = NULL;
  71322. WOLFSSL *ssl = NULL;
  71323. int test;
  71324. test_ssl_cbf func_cb_client;
  71325. test_ssl_cbf func_cb_server;
  71326. /* Test that DH callback APIs work. */
  71327. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  71328. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71329. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  71330. /* load client ca cert */
  71331. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  71332. WOLFSSL_SUCCESS);
  71333. /* test with NULL arguments */
  71334. wolfSSL_SetDhAgreeCtx(NULL, &test);
  71335. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  71336. /* test success case */
  71337. test = 1;
  71338. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71339. wolfSSL_SetDhAgreeCtx(ssl, &test);
  71340. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  71341. wolfSSL_free(ssl);
  71342. wolfSSL_CTX_free(ctx);
  71343. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71344. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71345. /* set callbacks to use DH functions */
  71346. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71347. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  71348. func_cb_client.method = wolfTLSv1_2_client_method;
  71349. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71350. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  71351. func_cb_server.method = wolfTLSv1_2_server_method;
  71352. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71353. &func_cb_server, NULL), TEST_SUCCESS);
  71354. /* Test fail */
  71355. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71356. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71357. /* set callbacks to use DH functions */
  71358. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71359. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  71360. func_cb_client.method = wolfTLSv1_2_client_method;
  71361. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71362. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  71363. func_cb_server.method = wolfTLSv1_2_server_method;
  71364. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71365. &func_cb_server, NULL), -1001);
  71366. #endif
  71367. return EXPECT_RESULT();
  71368. }
  71369. #endif /* HAVE_PK_CALLBACKS */
  71370. #ifdef HAVE_HASHDRBG
  71371. #ifdef TEST_RESEED_INTERVAL
  71372. static int test_wc_RNG_GenerateBlock_Reseed(void)
  71373. {
  71374. EXPECT_DECLS;
  71375. int i;
  71376. WC_RNG rng;
  71377. byte key[32];
  71378. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71379. ExpectIntEQ(wc_InitRng(&rng), 0);
  71380. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  71381. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71382. }
  71383. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71384. return EXPECT_RESULT();
  71385. }
  71386. #endif /* TEST_RESEED_INTERVAL */
  71387. static int test_wc_RNG_GenerateBlock(void)
  71388. {
  71389. EXPECT_DECLS;
  71390. int i;
  71391. WC_RNG rng;
  71392. byte key[32];
  71393. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71394. ExpectIntEQ(wc_InitRng(&rng), 0);
  71395. for (i = 0; i < 10; i++) {
  71396. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71397. }
  71398. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71399. return EXPECT_RESULT();
  71400. }
  71401. #endif /* HAVE_HASHDRBG */
  71402. /*
  71403. * Testing get_rand_digit
  71404. */
  71405. static int test_get_rand_digit(void)
  71406. {
  71407. EXPECT_DECLS;
  71408. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  71409. WC_RNG rng;
  71410. mp_digit d;
  71411. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71412. ExpectIntEQ(wc_InitRng(&rng), 0);
  71413. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  71414. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71415. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71416. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71417. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71418. #endif
  71419. return EXPECT_RESULT();
  71420. } /* End test_get_rand_digit*/
  71421. /*
  71422. * Testing get_digit_count
  71423. */
  71424. static int test_get_digit_count(void)
  71425. {
  71426. EXPECT_DECLS;
  71427. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  71428. mp_int a;
  71429. XMEMSET(&a, 0, sizeof(mp_int));
  71430. ExpectIntEQ(mp_init(&a), 0);
  71431. ExpectIntEQ(get_digit_count(NULL), 0);
  71432. ExpectIntEQ(get_digit_count(&a), 0);
  71433. mp_clear(&a);
  71434. #endif
  71435. return EXPECT_RESULT();
  71436. } /* End test_get_digit_count*/
  71437. /*
  71438. * Testing mp_cond_copy
  71439. */
  71440. static int test_mp_cond_copy(void)
  71441. {
  71442. EXPECT_DECLS;
  71443. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  71444. defined(WOLFSSL_PUBLIC_MP)
  71445. mp_int a;
  71446. mp_int b;
  71447. int copy = 0;
  71448. XMEMSET(&a, 0, sizeof(mp_int));
  71449. XMEMSET(&b, 0, sizeof(mp_int));
  71450. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71451. ExpectIntEQ(mp_init(&b), MP_OKAY);
  71452. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71453. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71454. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71455. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  71456. mp_clear(&a);
  71457. mp_clear(&b);
  71458. #endif
  71459. return EXPECT_RESULT();
  71460. } /* End test_mp_cond_copy*/
  71461. /*
  71462. * Testing mp_rand
  71463. */
  71464. static int test_mp_rand(void)
  71465. {
  71466. EXPECT_DECLS;
  71467. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  71468. mp_int a;
  71469. WC_RNG rng;
  71470. int digits = 1;
  71471. XMEMSET(&a, 0, sizeof(mp_int));
  71472. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71473. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71474. ExpectIntEQ(wc_InitRng(&rng), 0);
  71475. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  71476. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71477. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71478. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  71479. mp_clear(&a);
  71480. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71481. #endif
  71482. return EXPECT_RESULT();
  71483. } /* End test_mp_rand*/
  71484. /*
  71485. * Testing get_digit
  71486. */
  71487. static int test_get_digit(void)
  71488. {
  71489. EXPECT_DECLS;
  71490. #if defined(WOLFSSL_PUBLIC_MP)
  71491. mp_int a;
  71492. int n = 0;
  71493. XMEMSET(&a, 0, sizeof(mp_int));
  71494. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71495. ExpectIntEQ(get_digit(NULL, n), 0);
  71496. ExpectIntEQ(get_digit(&a, n), 0);
  71497. mp_clear(&a);
  71498. #endif
  71499. return EXPECT_RESULT();
  71500. } /* End test_get_digit*/
  71501. /*
  71502. * Testing wc_export_int
  71503. */
  71504. static int test_wc_export_int(void)
  71505. {
  71506. EXPECT_DECLS;
  71507. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  71508. defined(WOLFSSL_PUBLIC_MP)
  71509. mp_int mp;
  71510. byte buf[32];
  71511. word32 keySz = (word32)sizeof(buf);
  71512. word32 len = (word32)sizeof(buf);
  71513. XMEMSET(&mp, 0, sizeof(mp_int));
  71514. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  71515. ExpectIntEQ(mp_set(&mp, 1234), 0);
  71516. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71517. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71518. len = sizeof(buf)-1;
  71519. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71520. WC_NO_ERR_TRACE(BUFFER_E));
  71521. len = sizeof(buf);
  71522. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  71523. len = 4; /* test input too small */
  71524. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  71525. len = sizeof(buf);
  71526. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  71527. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  71528. ExpectIntEQ(len, 5);
  71529. mp_clear(&mp);
  71530. #endif
  71531. return EXPECT_RESULT();
  71532. } /* End test_wc_export_int*/
  71533. static int test_wc_InitRngNonce(void)
  71534. {
  71535. EXPECT_DECLS;
  71536. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71537. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71538. HAVE_FIPS_VERSION >= 2))
  71539. WC_RNG rng;
  71540. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71541. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71542. word32 nonceSz = sizeof(nonce);
  71543. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  71544. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71545. #endif
  71546. return EXPECT_RESULT();
  71547. } /* End test_wc_InitRngNonce*/
  71548. /*
  71549. * Testing wc_InitRngNonce_ex
  71550. */
  71551. static int test_wc_InitRngNonce_ex(void)
  71552. {
  71553. EXPECT_DECLS;
  71554. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71555. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71556. HAVE_FIPS_VERSION >= 2))
  71557. WC_RNG rng;
  71558. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71559. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71560. word32 nonceSz = sizeof(nonce);
  71561. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  71562. 0);
  71563. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71564. #endif
  71565. return EXPECT_RESULT();
  71566. } /* End test_wc_InitRngNonce_ex */
  71567. static int test_wolfSSL_X509_CRL(void)
  71568. {
  71569. EXPECT_DECLS;
  71570. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  71571. X509_CRL *crl = NULL;
  71572. char pem[][100] = {
  71573. "./certs/crl/crl.pem",
  71574. "./certs/crl/crl2.pem",
  71575. "./certs/crl/caEccCrl.pem",
  71576. "./certs/crl/eccCliCRL.pem",
  71577. "./certs/crl/eccSrvCRL.pem",
  71578. ""
  71579. };
  71580. #ifndef NO_BIO
  71581. BIO *bio = NULL;
  71582. #endif
  71583. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71584. char der[][100] = {
  71585. "./certs/crl/crl.der",
  71586. "./certs/crl/crl2.der",
  71587. ""};
  71588. #endif
  71589. XFILE fp = XBADFILE;
  71590. int i;
  71591. for (i = 0; pem[i][0] != '\0'; i++)
  71592. {
  71593. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71594. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71595. NULL, NULL));
  71596. ExpectNotNull(crl);
  71597. X509_CRL_free(crl);
  71598. if (fp != XBADFILE) {
  71599. XFCLOSE(fp);
  71600. fp = XBADFILE;
  71601. }
  71602. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71603. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  71604. NULL));
  71605. if (EXPECT_FAIL()) {
  71606. crl = NULL;
  71607. }
  71608. ExpectNotNull(crl);
  71609. X509_CRL_free(crl);
  71610. crl = NULL;
  71611. if (fp != XBADFILE) {
  71612. XFCLOSE(fp);
  71613. fp = XBADFILE;
  71614. }
  71615. }
  71616. #ifndef NO_BIO
  71617. for (i = 0; pem[i][0] != '\0'; i++)
  71618. {
  71619. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  71620. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  71621. X509_CRL_free(crl);
  71622. crl = NULL;
  71623. BIO_free(bio);
  71624. bio = NULL;
  71625. }
  71626. #endif
  71627. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71628. for (i = 0; der[i][0] != '\0'; i++) {
  71629. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  71630. ExpectTrue((fp != XBADFILE));
  71631. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  71632. ExpectNotNull(crl);
  71633. X509_CRL_free(crl);
  71634. if (fp != XBADFILE) {
  71635. XFCLOSE(fp);
  71636. fp = XBADFILE;
  71637. }
  71638. fp = XFOPEN(der[i], "rb");
  71639. ExpectTrue((fp != XBADFILE));
  71640. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  71641. if (EXPECT_FAIL()) {
  71642. crl = NULL;
  71643. }
  71644. ExpectNotNull(crl);
  71645. X509_CRL_free(crl);
  71646. crl = NULL;
  71647. if (fp != XBADFILE) {
  71648. XFCLOSE(fp);
  71649. fp = XBADFILE;
  71650. }
  71651. }
  71652. #endif
  71653. #endif
  71654. return EXPECT_RESULT();
  71655. }
  71656. static int test_wolfSSL_X509_load_crl_file(void)
  71657. {
  71658. EXPECT_DECLS;
  71659. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71660. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71661. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  71662. int i;
  71663. char pem[][100] = {
  71664. "./certs/crl/crl.pem",
  71665. "./certs/crl/crl2.pem",
  71666. "./certs/crl/caEccCrl.pem",
  71667. "./certs/crl/eccCliCRL.pem",
  71668. "./certs/crl/eccSrvCRL.pem",
  71669. #ifdef WC_RSA_PSS
  71670. "./certs/crl/crl_rsapss.pem",
  71671. #endif
  71672. ""
  71673. };
  71674. char der[][100] = {
  71675. "./certs/crl/crl.der",
  71676. "./certs/crl/crl2.der",
  71677. ""
  71678. };
  71679. WOLFSSL_X509_STORE* store = NULL;
  71680. WOLFSSL_X509_LOOKUP* lookup = NULL;
  71681. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71682. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71683. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71684. X509_FILETYPE_PEM), 1);
  71685. #ifdef WC_RSA_PSS
  71686. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  71687. X509_FILETYPE_PEM), 1);
  71688. #endif
  71689. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71690. X509_FILETYPE_PEM), 1);
  71691. if (store) {
  71692. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71693. WOLFSSL_FILETYPE_PEM), 1);
  71694. /* since store hasn't yet known the revoked cert*/
  71695. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71696. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71697. }
  71698. for (i = 0; pem[i][0] != '\0'; i++) {
  71699. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  71700. 1);
  71701. }
  71702. if (store) {
  71703. /* since store knows crl list */
  71704. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71705. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71706. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71707. #ifdef WC_RSA_PSS
  71708. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71709. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  71710. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71711. #endif
  71712. }
  71713. /* once feeing store */
  71714. X509_STORE_free(store);
  71715. store = NULL;
  71716. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71717. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71718. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71719. X509_FILETYPE_PEM), 1);
  71720. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71721. X509_FILETYPE_PEM), 1);
  71722. if (store) {
  71723. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71724. WOLFSSL_FILETYPE_PEM), 1);
  71725. /* since store hasn't yet known the revoked cert*/
  71726. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71727. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71728. }
  71729. for (i = 0; der[i][0] != '\0'; i++) {
  71730. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  71731. 1);
  71732. }
  71733. if (store) {
  71734. /* since store knows crl list */
  71735. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71736. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71737. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71738. }
  71739. /* test for incorrect parameter */
  71740. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  71741. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  71742. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  71743. X509_STORE_free(store);
  71744. store = NULL;
  71745. #endif
  71746. return EXPECT_RESULT();
  71747. }
  71748. static int test_wolfSSL_i2d_X509(void)
  71749. {
  71750. EXPECT_DECLS;
  71751. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  71752. const unsigned char* cert_buf = server_cert_der_2048;
  71753. unsigned char* out = NULL;
  71754. unsigned char* tmp = NULL;
  71755. X509* cert = NULL;
  71756. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  71757. /* Pointer should be advanced */
  71758. ExpectPtrGT(cert_buf, server_cert_der_2048);
  71759. ExpectIntGT(i2d_X509(cert, &out), 0);
  71760. ExpectNotNull(out);
  71761. tmp = out;
  71762. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  71763. ExpectPtrGT(tmp, out);
  71764. if (out != NULL)
  71765. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  71766. X509_free(cert);
  71767. #endif
  71768. return EXPECT_RESULT();
  71769. }
  71770. static int test_wolfSSL_d2i_X509_REQ(void)
  71771. {
  71772. EXPECT_DECLS;
  71773. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71774. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  71775. !defined(WOLFSSL_SP_MATH)
  71776. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  71777. * were generated by libest
  71778. * ./certs/csr.attr.der contains sample attributes
  71779. * ./certs/csr.ext.der contains sample extensions */
  71780. const char* csrFile = "./certs/csr.signed.der";
  71781. const char* csrPopFile = "./certs/csr.attr.der";
  71782. const char* csrExtFile = "./certs/csr.ext.der";
  71783. /* ./certs/csr.dsa.pem is generated using
  71784. * openssl req -newkey dsa:certs/dsaparams.pem \
  71785. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  71786. * -outform PEM
  71787. * with the passphrase "wolfSSL"
  71788. */
  71789. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71790. const char* csrDsaFile = "./certs/csr.dsa.pem";
  71791. XFILE f = XBADFILE;
  71792. #endif
  71793. BIO* bio = NULL;
  71794. X509* req = NULL;
  71795. EVP_PKEY *pub_key = NULL;
  71796. {
  71797. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  71798. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71799. /*
  71800. * Extract the public key from the CSR
  71801. */
  71802. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71803. /*
  71804. * Verify the signature in the CSR
  71805. */
  71806. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71807. X509_free(req);
  71808. req = NULL;
  71809. BIO_free(bio);
  71810. bio = NULL;
  71811. EVP_PKEY_free(pub_key);
  71812. pub_key = NULL;
  71813. }
  71814. {
  71815. #ifdef OPENSSL_ALL
  71816. X509_ATTRIBUTE* attr = NULL;
  71817. ASN1_TYPE *at = NULL;
  71818. #endif
  71819. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  71820. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71821. /*
  71822. * Extract the public key from the CSR
  71823. */
  71824. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71825. /*
  71826. * Verify the signature in the CSR
  71827. */
  71828. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71829. #ifdef OPENSSL_ALL
  71830. /*
  71831. * Obtain the challenge password from the CSR
  71832. */
  71833. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71834. -1), 1);
  71835. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  71836. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71837. ExpectNotNull(at->value.asn1_string);
  71838. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  71839. "2xIE+qqp/rhyTXP+");
  71840. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  71841. #endif
  71842. X509_free(req);
  71843. req = NULL;
  71844. BIO_free(bio);
  71845. bio = NULL;
  71846. EVP_PKEY_free(pub_key);
  71847. pub_key = NULL;
  71848. }
  71849. {
  71850. #ifdef OPENSSL_ALL
  71851. X509_ATTRIBUTE* attr = NULL;
  71852. ASN1_TYPE *at = NULL;
  71853. STACK_OF(X509_EXTENSION) *exts = NULL;
  71854. #endif
  71855. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  71856. /* This CSR contains an Extension Request attribute so
  71857. * we test extension parsing in a CSR attribute here. */
  71858. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71859. /*
  71860. * Extract the public key from the CSR
  71861. */
  71862. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71863. /*
  71864. * Verify the signature in the CSR
  71865. */
  71866. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71867. #ifdef OPENSSL_ALL
  71868. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  71869. req));
  71870. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  71871. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  71872. /*
  71873. * Obtain the challenge password from the CSR
  71874. */
  71875. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71876. -1), 0);
  71877. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  71878. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71879. ExpectNotNull(at->value.asn1_string);
  71880. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  71881. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  71882. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  71883. #endif
  71884. X509_free(req);
  71885. req = NULL;
  71886. BIO_free(bio);
  71887. bio = NULL;
  71888. EVP_PKEY_free(pub_key);
  71889. pub_key = NULL;
  71890. }
  71891. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71892. {
  71893. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  71894. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  71895. /*
  71896. * Extract the public key from the CSR
  71897. */
  71898. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71899. /*
  71900. * Verify the signature in the CSR
  71901. */
  71902. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71903. X509_free(req);
  71904. req = NULL;
  71905. BIO_free(bio);
  71906. /* Run the same test, but with a file pointer instead of a BIO.
  71907. * (PEM_read_X509_REQ)*/
  71908. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  71909. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  71910. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71911. X509_free(req);
  71912. EVP_PKEY_free(pub_key);
  71913. }
  71914. #endif /* !NO_DSA && !HAVE_SELFTEST */
  71915. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  71916. return EXPECT_RESULT();
  71917. }
  71918. static int test_wolfSSL_PEM_read_X509(void)
  71919. {
  71920. EXPECT_DECLS;
  71921. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71922. !defined(NO_RSA)
  71923. X509 *x509 = NULL;
  71924. XFILE fp = XBADFILE;
  71925. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  71926. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  71927. X509_free(x509);
  71928. if (fp != XBADFILE)
  71929. XFCLOSE(fp);
  71930. #endif
  71931. return EXPECT_RESULT();
  71932. }
  71933. static int test_wolfSSL_PEM_read(void)
  71934. {
  71935. EXPECT_DECLS;
  71936. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  71937. const char* filename = "./certs/server-keyEnc.pem";
  71938. XFILE fp = XBADFILE;
  71939. char* name = NULL;
  71940. char* header = NULL;
  71941. byte* data = NULL;
  71942. long len;
  71943. EVP_CIPHER_INFO cipher;
  71944. WOLFSSL_BIO* bio = NULL;
  71945. byte* fileData = NULL;
  71946. size_t fileDataSz = 0;
  71947. byte* out;
  71948. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  71949. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  71950. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  71951. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  71952. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  71953. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71954. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71955. ExpectIntGT(XSTRLEN(header), 0);
  71956. ExpectIntGT(len, 0);
  71957. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71958. name = NULL;
  71959. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71960. header = NULL;
  71961. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71962. data = NULL;
  71963. BIO_free(bio);
  71964. bio = NULL;
  71965. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  71966. /* Fail cases. */
  71967. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71968. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71969. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71970. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71971. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71972. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71973. ExpectIntGT(XSTRLEN(header), 0);
  71974. ExpectIntGT(len, 0);
  71975. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71976. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71977. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71978. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71979. DYNAMIC_TYPE_TMP_BUFFER));
  71980. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71981. if (fp != XBADFILE) {
  71982. XFCLOSE(fp);
  71983. fp = XBADFILE;
  71984. }
  71985. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71986. /* Fail cases. */
  71987. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  71988. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  71989. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  71990. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  71991. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71992. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71993. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71994. /* Fail cases. */
  71995. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  71996. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  71997. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  71998. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  71999. /* Pass case */
  72000. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  72001. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72002. name = NULL;
  72003. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72004. header = NULL;
  72005. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72006. data = NULL;
  72007. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  72008. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  72009. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72010. ExpectIntGT(XSTRLEN(header), 0);
  72011. ExpectIntGT(len, 0);
  72012. /* Fail cases. */
  72013. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72014. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72015. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72016. #ifndef NO_DES3
  72017. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  72018. #endif
  72019. /* Fail cases. */
  72020. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  72021. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72022. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  72023. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72024. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  72025. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72026. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  72027. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72028. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  72029. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72030. #if !defined(NO_DES3) && !defined(NO_MD5)
  72031. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72032. (void*)"yassl123"), WOLFSSL_SUCCESS);
  72033. #else
  72034. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72035. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72036. #endif
  72037. BIO_free(bio);
  72038. bio = NULL;
  72039. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72040. fileData = NULL;
  72041. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72042. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72043. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72044. name = NULL;
  72045. header = NULL;
  72046. data = NULL;
  72047. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  72048. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  72049. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72050. ExpectIntEQ(XSTRLEN(header), 0);
  72051. ExpectIntGT(len, 0);
  72052. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  72053. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  72054. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  72055. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  72056. DYNAMIC_TYPE_TMP_BUFFER));
  72057. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  72058. if (fp != XBADFILE)
  72059. XFCLOSE(fp);
  72060. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  72061. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  72062. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  72063. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  72064. BIO_free(bio);
  72065. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72066. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72067. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72068. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72069. #endif
  72070. return EXPECT_RESULT();
  72071. }
  72072. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  72073. {
  72074. EXPECT_DECLS;
  72075. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72076. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72077. const byte iv[12] = { 0 };
  72078. const byte key[16] = { 0 };
  72079. const byte cleartext[16] = { 0 };
  72080. const byte aad[] = {
  72081. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  72082. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  72083. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  72084. 0x4f
  72085. };
  72086. byte out1Part[16];
  72087. byte outTag1Part[16];
  72088. byte out2Part[16];
  72089. byte outTag2Part[16];
  72090. byte decryptBuf[16];
  72091. int len = 0;
  72092. int tlen;
  72093. EVP_CIPHER_CTX* ctx = NULL;
  72094. /* ENCRYPT */
  72095. /* Send AAD and data in 1 part */
  72096. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72097. tlen = 0;
  72098. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72099. 1);
  72100. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72101. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72102. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  72103. sizeof(cleartext)), 1);
  72104. tlen += len;
  72105. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  72106. tlen += len;
  72107. ExpectIntEQ(tlen, sizeof(cleartext));
  72108. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72109. outTag1Part), 1);
  72110. EVP_CIPHER_CTX_free(ctx);
  72111. ctx = NULL;
  72112. /* DECRYPT */
  72113. /* Send AAD and data in 1 part */
  72114. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72115. tlen = 0;
  72116. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72117. 1);
  72118. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72119. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72120. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  72121. sizeof(cleartext)), 1);
  72122. tlen += len;
  72123. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72124. outTag1Part), 1);
  72125. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  72126. tlen += len;
  72127. ExpectIntEQ(tlen, sizeof(cleartext));
  72128. EVP_CIPHER_CTX_free(ctx);
  72129. ctx = NULL;
  72130. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72131. /* ENCRYPT */
  72132. /* Send AAD and data in 2 parts */
  72133. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72134. tlen = 0;
  72135. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72136. 1);
  72137. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72138. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72139. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72140. 1);
  72141. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  72142. tlen += len;
  72143. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  72144. sizeof(cleartext) - 1), 1);
  72145. tlen += len;
  72146. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  72147. tlen += len;
  72148. ExpectIntEQ(tlen, sizeof(cleartext));
  72149. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72150. outTag2Part), 1);
  72151. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  72152. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  72153. EVP_CIPHER_CTX_free(ctx);
  72154. ctx = NULL;
  72155. /* DECRYPT */
  72156. /* Send AAD and data in 2 parts */
  72157. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72158. tlen = 0;
  72159. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72160. 1);
  72161. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72162. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72163. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72164. 1);
  72165. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  72166. tlen += len;
  72167. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  72168. sizeof(cleartext) - 1), 1);
  72169. tlen += len;
  72170. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72171. outTag1Part), 1);
  72172. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  72173. tlen += len;
  72174. ExpectIntEQ(tlen, sizeof(cleartext));
  72175. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72176. /* Test AAD reuse */
  72177. EVP_CIPHER_CTX_free(ctx);
  72178. #endif
  72179. return EXPECT_RESULT();
  72180. }
  72181. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  72182. {
  72183. EXPECT_DECLS;
  72184. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72185. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72186. /* Zero length plain text */
  72187. byte key[] = {
  72188. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72189. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72190. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72191. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72192. }; /* align */
  72193. byte iv[] = {
  72194. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72195. }; /* align */
  72196. byte plaintxt[1];
  72197. int ivSz = 12;
  72198. int plaintxtSz = 0;
  72199. unsigned char tag[16];
  72200. unsigned char tag_kat[] = {
  72201. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  72202. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  72203. };
  72204. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72205. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72206. int ciphertxtSz = 0;
  72207. int decryptedtxtSz = 0;
  72208. int len = 0;
  72209. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72210. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72211. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  72212. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72213. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72214. plaintxtSz));
  72215. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72216. ciphertxtSz += len;
  72217. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  72218. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72219. ExpectIntEQ(0, ciphertxtSz);
  72220. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  72221. EVP_CIPHER_CTX_init(de);
  72222. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  72223. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72224. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72225. decryptedtxtSz = len;
  72226. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  72227. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72228. decryptedtxtSz += len;
  72229. ExpectIntEQ(0, decryptedtxtSz);
  72230. EVP_CIPHER_CTX_free(en);
  72231. EVP_CIPHER_CTX_free(de);
  72232. #endif
  72233. return EXPECT_RESULT();
  72234. }
  72235. static int test_wolfssl_EVP_aes_gcm(void)
  72236. {
  72237. EXPECT_DECLS;
  72238. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72239. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72240. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72241. byte *key = (byte*)"01234567890123456789012345678901";
  72242. /* A 128 bit IV */
  72243. byte *iv = (byte*)"0123456789012345";
  72244. int ivSz = AES_BLOCK_SIZE;
  72245. /* Message to be encrypted */
  72246. byte *plaintxt = (byte*)"for things to change you have to change";
  72247. /* Additional non-confidential data */
  72248. byte *aad = (byte*)"Don't spend major time on minor things.";
  72249. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72250. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72251. int aadSz = (int)XSTRLEN((char*)aad);
  72252. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72253. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72254. int ciphertxtSz = 0;
  72255. int decryptedtxtSz = 0;
  72256. int len = 0;
  72257. int i = 0;
  72258. EVP_CIPHER_CTX en[2];
  72259. EVP_CIPHER_CTX de[2];
  72260. for (i = 0; i < 2; i++) {
  72261. EVP_CIPHER_CTX_init(&en[i]);
  72262. if (i == 0) {
  72263. /* Default uses 96-bits IV length */
  72264. #ifdef WOLFSSL_AES_128
  72265. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  72266. key, iv));
  72267. #elif defined(WOLFSSL_AES_192)
  72268. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72269. key, iv));
  72270. #elif defined(WOLFSSL_AES_256)
  72271. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72272. key, iv));
  72273. #endif
  72274. }
  72275. else {
  72276. #ifdef WOLFSSL_AES_128
  72277. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  72278. NULL, NULL));
  72279. #elif defined(WOLFSSL_AES_192)
  72280. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72281. NULL, NULL));
  72282. #elif defined(WOLFSSL_AES_256)
  72283. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72284. NULL, NULL));
  72285. #endif
  72286. /* non-default must to set the IV length first */
  72287. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  72288. ivSz, NULL));
  72289. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72290. }
  72291. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72292. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72293. plaintxtSz));
  72294. ciphertxtSz = len;
  72295. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72296. ciphertxtSz += len;
  72297. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  72298. AES_BLOCK_SIZE, tag));
  72299. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72300. EVP_CIPHER_CTX_init(&de[i]);
  72301. if (i == 0) {
  72302. /* Default uses 96-bits IV length */
  72303. #ifdef WOLFSSL_AES_128
  72304. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72305. key, iv));
  72306. #elif defined(WOLFSSL_AES_192)
  72307. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72308. key, iv));
  72309. #elif defined(WOLFSSL_AES_256)
  72310. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72311. key, iv));
  72312. #endif
  72313. }
  72314. else {
  72315. #ifdef WOLFSSL_AES_128
  72316. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72317. NULL, NULL));
  72318. #elif defined(WOLFSSL_AES_192)
  72319. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72320. NULL, NULL));
  72321. #elif defined(WOLFSSL_AES_256)
  72322. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72323. NULL, NULL));
  72324. #endif
  72325. /* non-default must to set the IV length first */
  72326. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72327. ivSz, NULL));
  72328. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72329. }
  72330. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72331. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72332. ciphertxtSz));
  72333. decryptedtxtSz = len;
  72334. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72335. AES_BLOCK_SIZE, tag));
  72336. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72337. decryptedtxtSz += len;
  72338. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72339. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72340. /* modify tag*/
  72341. if (i == 0) {
  72342. /* Default uses 96-bits IV length */
  72343. #ifdef WOLFSSL_AES_128
  72344. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72345. key, iv));
  72346. #elif defined(WOLFSSL_AES_192)
  72347. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72348. key, iv));
  72349. #elif defined(WOLFSSL_AES_256)
  72350. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72351. key, iv));
  72352. #endif
  72353. }
  72354. else {
  72355. #ifdef WOLFSSL_AES_128
  72356. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72357. NULL, NULL));
  72358. #elif defined(WOLFSSL_AES_192)
  72359. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72360. NULL, NULL));
  72361. #elif defined(WOLFSSL_AES_256)
  72362. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72363. NULL, NULL));
  72364. #endif
  72365. /* non-default must to set the IV length first */
  72366. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72367. ivSz, NULL));
  72368. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72369. }
  72370. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72371. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72372. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72373. AES_BLOCK_SIZE, tag));
  72374. /* fail due to wrong tag */
  72375. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72376. ciphertxtSz));
  72377. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72378. ExpectIntEQ(0, len);
  72379. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72380. }
  72381. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72382. return EXPECT_RESULT();
  72383. }
  72384. static int test_wolfssl_EVP_aria_gcm(void)
  72385. {
  72386. int res = TEST_SKIPPED;
  72387. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  72388. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72389. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72390. byte *key = (byte*)"01234567890123456789012345678901";
  72391. /* A 128 bit IV */
  72392. byte *iv = (byte*)"0123456789012345";
  72393. int ivSz = ARIA_BLOCK_SIZE;
  72394. /* Message to be encrypted */
  72395. const int plaintxtSz = 40;
  72396. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72397. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  72398. /* Additional non-confidential data */
  72399. byte *aad = (byte*)"Don't spend major time on minor things.";
  72400. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  72401. int aadSz = (int)XSTRLEN((char*)aad);
  72402. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72403. byte decryptedtxt[plaintxtSz];
  72404. int ciphertxtSz = 0;
  72405. int decryptedtxtSz = 0;
  72406. int len = 0;
  72407. int i = 0;
  72408. #define TEST_ARIA_GCM_COUNT 6
  72409. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  72410. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  72411. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  72412. EVP_CIPHER_CTX_init(&en[i]);
  72413. switch (i) {
  72414. case 0:
  72415. /* Default uses 96-bits IV length */
  72416. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  72417. break;
  72418. case 1:
  72419. /* Default uses 96-bits IV length */
  72420. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  72421. break;
  72422. case 2:
  72423. /* Default uses 96-bits IV length */
  72424. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  72425. break;
  72426. case 3:
  72427. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72428. /* non-default must to set the IV length first */
  72429. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72430. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72431. break;
  72432. case 4:
  72433. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72434. /* non-default must to set the IV length first */
  72435. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72436. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72437. break;
  72438. case 5:
  72439. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72440. /* non-default must to set the IV length first */
  72441. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72442. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72443. break;
  72444. }
  72445. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  72446. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72447. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  72448. ciphertxtSz = len;
  72449. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72450. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  72451. ciphertxtSz += len;
  72452. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  72453. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72454. EVP_CIPHER_CTX_init(&de[i]);
  72455. switch (i) {
  72456. case 0:
  72457. /* Default uses 96-bits IV length */
  72458. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  72459. break;
  72460. case 1:
  72461. /* Default uses 96-bits IV length */
  72462. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  72463. break;
  72464. case 2:
  72465. /* Default uses 96-bits IV length */
  72466. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  72467. break;
  72468. case 3:
  72469. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72470. /* non-default must to set the IV length first */
  72471. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72472. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72473. break;
  72474. case 4:
  72475. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72476. /* non-default must to set the IV length first */
  72477. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72478. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72479. break;
  72480. case 5:
  72481. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72482. /* non-default must to set the IV length first */
  72483. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72484. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72485. break;
  72486. }
  72487. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72488. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72489. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72490. decryptedtxtSz = len;
  72491. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72492. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72493. decryptedtxtSz += len;
  72494. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  72495. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72496. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72497. /* modify tag*/
  72498. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72499. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72500. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72501. /* fail due to wrong tag */
  72502. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72503. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72504. AssertIntEQ(0, len);
  72505. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72506. }
  72507. res = TEST_RES_CHECK(1);
  72508. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72509. return res;
  72510. }
  72511. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  72512. {
  72513. EXPECT_DECLS;
  72514. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72515. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72516. /* Zero length plain text */
  72517. byte key[] = {
  72518. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72519. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72520. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72522. }; /* align */
  72523. byte iv[] = {
  72524. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72525. }; /* align */
  72526. byte plaintxt[1];
  72527. int ivSz = 12;
  72528. int plaintxtSz = 0;
  72529. unsigned char tag[16];
  72530. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72531. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72532. int ciphertxtSz = 0;
  72533. int decryptedtxtSz = 0;
  72534. int len = 0;
  72535. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72536. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72537. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  72538. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72539. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72540. plaintxtSz));
  72541. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72542. ciphertxtSz += len;
  72543. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72544. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72545. ExpectIntEQ(0, ciphertxtSz);
  72546. EVP_CIPHER_CTX_init(de);
  72547. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  72548. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72549. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72550. decryptedtxtSz = len;
  72551. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72552. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72553. decryptedtxtSz += len;
  72554. ExpectIntEQ(0, decryptedtxtSz);
  72555. EVP_CIPHER_CTX_free(en);
  72556. EVP_CIPHER_CTX_free(de);
  72557. #endif
  72558. return EXPECT_RESULT();
  72559. }
  72560. static int test_wolfssl_EVP_aes_ccm(void)
  72561. {
  72562. EXPECT_DECLS;
  72563. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72564. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72565. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72566. byte *key = (byte*)"01234567890123456789012345678901";
  72567. /* A 128 bit IV */
  72568. byte *iv = (byte*)"0123456789012";
  72569. int ivSz = (int)XSTRLEN((char*)iv);
  72570. /* Message to be encrypted */
  72571. byte *plaintxt = (byte*)"for things to change you have to change";
  72572. /* Additional non-confidential data */
  72573. byte *aad = (byte*)"Don't spend major time on minor things.";
  72574. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72575. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72576. int aadSz = (int)XSTRLEN((char*)aad);
  72577. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72578. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72579. int ciphertxtSz = 0;
  72580. int decryptedtxtSz = 0;
  72581. int len = 0;
  72582. int i = 0;
  72583. int ret;
  72584. EVP_CIPHER_CTX en[2];
  72585. EVP_CIPHER_CTX de[2];
  72586. for (i = 0; i < 2; i++) {
  72587. EVP_CIPHER_CTX_init(&en[i]);
  72588. if (i == 0) {
  72589. /* Default uses 96-bits IV length */
  72590. #ifdef WOLFSSL_AES_128
  72591. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72592. key, iv));
  72593. #elif defined(WOLFSSL_AES_192)
  72594. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72595. key, iv));
  72596. #elif defined(WOLFSSL_AES_256)
  72597. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72598. key, iv));
  72599. #endif
  72600. }
  72601. else {
  72602. #ifdef WOLFSSL_AES_128
  72603. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72604. NULL, NULL));
  72605. #elif defined(WOLFSSL_AES_192)
  72606. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72607. NULL, NULL));
  72608. #elif defined(WOLFSSL_AES_256)
  72609. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72610. NULL, NULL));
  72611. #endif
  72612. /* non-default must to set the IV length first */
  72613. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72614. ivSz, NULL));
  72615. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72616. }
  72617. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72618. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72619. plaintxtSz));
  72620. ciphertxtSz = len;
  72621. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72622. ciphertxtSz += len;
  72623. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72624. AES_BLOCK_SIZE, tag));
  72625. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  72626. ExpectIntEQ(ret, 1);
  72627. EVP_CIPHER_CTX_init(&de[i]);
  72628. if (i == 0) {
  72629. /* Default uses 96-bits IV length */
  72630. #ifdef WOLFSSL_AES_128
  72631. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72632. key, iv));
  72633. #elif defined(WOLFSSL_AES_192)
  72634. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72635. key, iv));
  72636. #elif defined(WOLFSSL_AES_256)
  72637. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72638. key, iv));
  72639. #endif
  72640. }
  72641. else {
  72642. #ifdef WOLFSSL_AES_128
  72643. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72644. NULL, NULL));
  72645. #elif defined(WOLFSSL_AES_192)
  72646. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72647. NULL, NULL));
  72648. #elif defined(WOLFSSL_AES_256)
  72649. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72650. NULL, NULL));
  72651. #endif
  72652. /* non-default must to set the IV length first */
  72653. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72654. ivSz, NULL));
  72655. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72656. }
  72657. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72658. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72659. ciphertxtSz));
  72660. decryptedtxtSz = len;
  72661. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72662. AES_BLOCK_SIZE, tag));
  72663. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72664. decryptedtxtSz += len;
  72665. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72666. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72667. /* modify tag*/
  72668. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72669. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72670. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72671. AES_BLOCK_SIZE, tag));
  72672. /* fail due to wrong tag */
  72673. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72674. ciphertxtSz));
  72675. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72676. ExpectIntEQ(0, len);
  72677. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  72678. ExpectIntEQ(ret, 1);
  72679. }
  72680. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  72681. return EXPECT_RESULT();
  72682. }
  72683. static int test_wolfssl_EVP_chacha20_poly1305(void)
  72684. {
  72685. EXPECT_DECLS;
  72686. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  72687. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  72688. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  72689. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72690. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  72691. byte cipherText[sizeof(plainText)];
  72692. byte decryptedText[sizeof(plainText)];
  72693. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  72694. EVP_CIPHER_CTX* ctx = NULL;
  72695. int outSz;
  72696. XMEMSET(key, 0, sizeof(key));
  72697. XMEMSET(iv, 0, sizeof(iv));
  72698. /* Encrypt. */
  72699. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72700. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72701. NULL), WOLFSSL_SUCCESS);
  72702. /* Invalid IV length. */
  72703. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72704. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72705. /* Valid IV length. */
  72706. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72707. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72708. /* Invalid tag length. */
  72709. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72710. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72711. /* Valid tag length. */
  72712. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72713. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  72714. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72715. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72716. WOLFSSL_SUCCESS);
  72717. ExpectIntEQ(outSz, sizeof(aad));
  72718. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72719. sizeof(plainText)), WOLFSSL_SUCCESS);
  72720. ExpectIntEQ(outSz, sizeof(plainText));
  72721. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72722. ExpectIntEQ(outSz, 0);
  72723. /* Invalid tag length. */
  72724. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72725. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72726. /* Valid tag length. */
  72727. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72728. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72729. EVP_CIPHER_CTX_free(ctx);
  72730. ctx = NULL;
  72731. /* Decrypt. */
  72732. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72733. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72734. NULL), WOLFSSL_SUCCESS);
  72735. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72736. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72737. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72738. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72739. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72740. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72741. WOLFSSL_SUCCESS);
  72742. ExpectIntEQ(outSz, sizeof(aad));
  72743. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72744. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72745. ExpectIntEQ(outSz, sizeof(cipherText));
  72746. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72747. WOLFSSL_SUCCESS);
  72748. ExpectIntEQ(outSz, 0);
  72749. EVP_CIPHER_CTX_free(ctx);
  72750. ctx = NULL;
  72751. /* Test partial Inits. CipherInit() allow setting of key and iv
  72752. * in separate calls. */
  72753. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72754. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  72755. key, NULL, 1), WOLFSSL_SUCCESS);
  72756. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72757. WOLFSSL_SUCCESS);
  72758. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  72759. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  72760. ExpectIntEQ(outSz, sizeof(aad));
  72761. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72762. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72763. ExpectIntEQ(outSz, sizeof(cipherText));
  72764. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72765. WOLFSSL_SUCCESS);
  72766. ExpectIntEQ(outSz, 0);
  72767. EVP_CIPHER_CTX_free(ctx);
  72768. #endif
  72769. return EXPECT_RESULT();
  72770. }
  72771. static int test_wolfssl_EVP_chacha20(void)
  72772. {
  72773. EXPECT_DECLS;
  72774. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  72775. byte key[CHACHA_MAX_KEY_SZ];
  72776. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  72777. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72778. byte cipherText[sizeof(plainText)];
  72779. byte decryptedText[sizeof(plainText)];
  72780. EVP_CIPHER_CTX* ctx = NULL;
  72781. int outSz;
  72782. XMEMSET(key, 0, sizeof(key));
  72783. XMEMSET(iv, 0, sizeof(iv));
  72784. /* Encrypt. */
  72785. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72786. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72787. NULL), WOLFSSL_SUCCESS);
  72788. /* Any tag length must fail - not an AEAD cipher. */
  72789. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72790. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72791. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72792. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72793. sizeof(plainText)), WOLFSSL_SUCCESS);
  72794. ExpectIntEQ(outSz, sizeof(plainText));
  72795. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72796. ExpectIntEQ(outSz, 0);
  72797. EVP_CIPHER_CTX_free(ctx);
  72798. ctx = NULL;
  72799. /* Decrypt. */
  72800. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72801. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72802. NULL), WOLFSSL_SUCCESS);
  72803. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72804. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72805. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72806. ExpectIntEQ(outSz, sizeof(cipherText));
  72807. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72808. WOLFSSL_SUCCESS);
  72809. ExpectIntEQ(outSz, 0);
  72810. EVP_CIPHER_CTX_free(ctx);
  72811. ctx = NULL;
  72812. /* Test partial Inits. CipherInit() allow setting of key and iv
  72813. * in separate calls. */
  72814. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72815. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  72816. key, NULL, 1), WOLFSSL_SUCCESS);
  72817. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72818. WOLFSSL_SUCCESS);
  72819. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72820. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72821. ExpectIntEQ(outSz, sizeof(cipherText));
  72822. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72823. WOLFSSL_SUCCESS);
  72824. ExpectIntEQ(outSz, 0);
  72825. EVP_CIPHER_CTX_free(ctx);
  72826. #endif
  72827. return EXPECT_RESULT();
  72828. }
  72829. static int test_wolfssl_EVP_sm4_ecb(void)
  72830. {
  72831. int res = TEST_SKIPPED;
  72832. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  72833. EXPECT_DECLS;
  72834. byte key[SM4_KEY_SIZE];
  72835. byte plainText[SM4_BLOCK_SIZE] = {
  72836. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72837. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72838. };
  72839. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72840. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72841. EVP_CIPHER_CTX* ctx;
  72842. int outSz;
  72843. XMEMSET(key, 0, sizeof(key));
  72844. /* Encrypt. */
  72845. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72846. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72847. WOLFSSL_SUCCESS);
  72848. /* Any tag length must fail - not an AEAD cipher. */
  72849. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72850. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72851. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  72852. WOLFSSL_SUCCESS);
  72853. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72854. sizeof(plainText)), WOLFSSL_SUCCESS);
  72855. ExpectIntEQ(outSz, sizeof(plainText));
  72856. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72857. WOLFSSL_SUCCESS);
  72858. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72859. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72860. EVP_CIPHER_CTX_free(ctx);
  72861. /* Decrypt. */
  72862. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72863. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72864. WOLFSSL_SUCCESS);
  72865. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  72866. WOLFSSL_SUCCESS);
  72867. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72868. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72869. ExpectIntEQ(outSz, sizeof(plainText));
  72870. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72871. WOLFSSL_SUCCESS);
  72872. ExpectIntEQ(outSz, 0);
  72873. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72874. EVP_CIPHER_CTX_free(ctx);
  72875. res = EXPECT_RESULT();
  72876. #endif
  72877. return res;
  72878. }
  72879. static int test_wolfssl_EVP_sm4_cbc(void)
  72880. {
  72881. int res = TEST_SKIPPED;
  72882. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  72883. EXPECT_DECLS;
  72884. byte key[SM4_KEY_SIZE];
  72885. byte iv[SM4_BLOCK_SIZE];
  72886. byte plainText[SM4_BLOCK_SIZE] = {
  72887. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72888. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72889. };
  72890. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72891. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72892. EVP_CIPHER_CTX* ctx;
  72893. int outSz;
  72894. XMEMSET(key, 0, sizeof(key));
  72895. XMEMSET(iv, 0, sizeof(iv));
  72896. /* Encrypt. */
  72897. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72898. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72899. WOLFSSL_SUCCESS);
  72900. /* Any tag length must fail - not an AEAD cipher. */
  72901. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72902. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72903. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72904. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72905. sizeof(plainText)), WOLFSSL_SUCCESS);
  72906. ExpectIntEQ(outSz, sizeof(plainText));
  72907. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72908. WOLFSSL_SUCCESS);
  72909. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72910. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72911. EVP_CIPHER_CTX_free(ctx);
  72912. /* Decrypt. */
  72913. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72914. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72915. WOLFSSL_SUCCESS);
  72916. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72917. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72918. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72919. ExpectIntEQ(outSz, sizeof(plainText));
  72920. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72921. WOLFSSL_SUCCESS);
  72922. ExpectIntEQ(outSz, 0);
  72923. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72924. EVP_CIPHER_CTX_free(ctx);
  72925. /* Test partial Inits. CipherInit() allow setting of key and iv
  72926. * in separate calls. */
  72927. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72928. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  72929. WOLFSSL_SUCCESS);
  72930. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  72931. WOLFSSL_SUCCESS);
  72932. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72933. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72934. ExpectIntEQ(outSz, sizeof(plainText));
  72935. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72936. WOLFSSL_SUCCESS);
  72937. ExpectIntEQ(outSz, 0);
  72938. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72939. EVP_CIPHER_CTX_free(ctx);
  72940. res = EXPECT_RESULT();
  72941. #endif
  72942. return res;
  72943. }
  72944. static int test_wolfssl_EVP_sm4_ctr(void)
  72945. {
  72946. int res = TEST_SKIPPED;
  72947. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  72948. EXPECT_DECLS;
  72949. byte key[SM4_KEY_SIZE];
  72950. byte iv[SM4_BLOCK_SIZE];
  72951. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72952. byte cipherText[sizeof(plainText)];
  72953. byte decryptedText[sizeof(plainText)];
  72954. EVP_CIPHER_CTX* ctx;
  72955. int outSz;
  72956. XMEMSET(key, 0, sizeof(key));
  72957. XMEMSET(iv, 0, sizeof(iv));
  72958. /* Encrypt. */
  72959. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72960. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72961. WOLFSSL_SUCCESS);
  72962. /* Any tag length must fail - not an AEAD cipher. */
  72963. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72964. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72965. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72966. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72967. sizeof(plainText)), WOLFSSL_SUCCESS);
  72968. ExpectIntEQ(outSz, sizeof(plainText));
  72969. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72970. ExpectIntEQ(outSz, 0);
  72971. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72972. EVP_CIPHER_CTX_free(ctx);
  72973. /* Decrypt. */
  72974. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72975. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72976. WOLFSSL_SUCCESS);
  72977. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72978. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72979. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72980. ExpectIntEQ(outSz, sizeof(cipherText));
  72981. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72982. WOLFSSL_SUCCESS);
  72983. ExpectIntEQ(outSz, 0);
  72984. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72985. EVP_CIPHER_CTX_free(ctx);
  72986. /* Test partial Inits. CipherInit() allow setting of key and iv
  72987. * in separate calls. */
  72988. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72989. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  72990. WOLFSSL_SUCCESS);
  72991. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72992. WOLFSSL_SUCCESS);
  72993. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72994. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72995. ExpectIntEQ(outSz, sizeof(cipherText));
  72996. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72997. WOLFSSL_SUCCESS);
  72998. ExpectIntEQ(outSz, 0);
  72999. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73000. EVP_CIPHER_CTX_free(ctx);
  73001. res = EXPECT_RESULT();
  73002. #endif
  73003. return res;
  73004. }
  73005. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  73006. {
  73007. int res = TEST_SKIPPED;
  73008. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73009. /* Zero length plain text */
  73010. EXPECT_DECLS;
  73011. byte key[] = {
  73012. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73013. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73014. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73015. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73016. }; /* align */
  73017. byte iv[] = {
  73018. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73019. }; /* align */
  73020. byte plaintxt[1];
  73021. int ivSz = 12;
  73022. int plaintxtSz = 0;
  73023. unsigned char tag[16];
  73024. unsigned char tag_kat[16] = {
  73025. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  73026. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  73027. };
  73028. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73029. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73030. int ciphertxtSz = 0;
  73031. int decryptedtxtSz = 0;
  73032. int len = 0;
  73033. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73034. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73035. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  73036. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73037. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73038. plaintxtSz));
  73039. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73040. ciphertxtSz += len;
  73041. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  73042. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73043. ExpectIntEQ(0, ciphertxtSz);
  73044. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  73045. EVP_CIPHER_CTX_init(de);
  73046. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  73047. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73048. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73049. decryptedtxtSz = len;
  73050. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  73051. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73052. decryptedtxtSz += len;
  73053. ExpectIntEQ(0, decryptedtxtSz);
  73054. EVP_CIPHER_CTX_free(en);
  73055. EVP_CIPHER_CTX_free(de);
  73056. res = EXPECT_RESULT();
  73057. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73058. return res;
  73059. }
  73060. static int test_wolfssl_EVP_sm4_gcm(void)
  73061. {
  73062. int res = TEST_SKIPPED;
  73063. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73064. EXPECT_DECLS;
  73065. byte *key = (byte*)"0123456789012345";
  73066. /* A 128 bit IV */
  73067. byte *iv = (byte*)"0123456789012345";
  73068. int ivSz = SM4_BLOCK_SIZE;
  73069. /* Message to be encrypted */
  73070. byte *plaintxt = (byte*)"for things to change you have to change";
  73071. /* Additional non-confidential data */
  73072. byte *aad = (byte*)"Don't spend major time on minor things.";
  73073. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  73074. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73075. int aadSz = (int)XSTRLEN((char*)aad);
  73076. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73077. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73078. int ciphertxtSz = 0;
  73079. int decryptedtxtSz = 0;
  73080. int len = 0;
  73081. int i = 0;
  73082. EVP_CIPHER_CTX en[2];
  73083. EVP_CIPHER_CTX de[2];
  73084. for (i = 0; i < 2; i++) {
  73085. EVP_CIPHER_CTX_init(&en[i]);
  73086. if (i == 0) {
  73087. /* Default uses 96-bits IV length */
  73088. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  73089. iv));
  73090. }
  73091. else {
  73092. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  73093. NULL));
  73094. /* non-default must to set the IV length first */
  73095. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  73096. ivSz, NULL));
  73097. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73098. }
  73099. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73100. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73101. plaintxtSz));
  73102. ciphertxtSz = len;
  73103. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73104. ciphertxtSz += len;
  73105. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  73106. SM4_BLOCK_SIZE, tag));
  73107. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73108. EVP_CIPHER_CTX_init(&de[i]);
  73109. if (i == 0) {
  73110. /* Default uses 96-bits IV length */
  73111. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  73112. iv));
  73113. }
  73114. else {
  73115. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  73116. NULL));
  73117. /* non-default must to set the IV length first */
  73118. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73119. ivSz, NULL));
  73120. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73121. }
  73122. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73123. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73124. ciphertxtSz));
  73125. decryptedtxtSz = len;
  73126. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73127. SM4_BLOCK_SIZE, tag));
  73128. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73129. decryptedtxtSz += len;
  73130. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73131. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73132. /* modify tag*/
  73133. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73134. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73135. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73136. SM4_BLOCK_SIZE, tag));
  73137. /* fail due to wrong tag */
  73138. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73139. ciphertxtSz));
  73140. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73141. ExpectIntEQ(0, len);
  73142. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73143. }
  73144. res = EXPECT_RESULT();
  73145. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73146. return res;
  73147. }
  73148. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  73149. {
  73150. int res = TEST_SKIPPED;
  73151. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  73152. /* Zero length plain text */
  73153. EXPECT_DECLS;
  73154. byte key[] = {
  73155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73156. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73157. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73159. }; /* align */
  73160. byte iv[] = {
  73161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73162. }; /* align */
  73163. byte plaintxt[1];
  73164. int ivSz = 12;
  73165. int plaintxtSz = 0;
  73166. unsigned char tag[16];
  73167. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73168. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73169. int ciphertxtSz = 0;
  73170. int decryptedtxtSz = 0;
  73171. int len = 0;
  73172. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73173. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73174. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  73175. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73176. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73177. plaintxtSz));
  73178. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73179. ciphertxtSz += len;
  73180. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  73181. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73182. ExpectIntEQ(0, ciphertxtSz);
  73183. EVP_CIPHER_CTX_init(de);
  73184. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  73185. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73186. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73187. decryptedtxtSz = len;
  73188. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  73189. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73190. decryptedtxtSz += len;
  73191. ExpectIntEQ(0, decryptedtxtSz);
  73192. EVP_CIPHER_CTX_free(en);
  73193. EVP_CIPHER_CTX_free(de);
  73194. res = EXPECT_RESULT();
  73195. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  73196. return res;
  73197. }
  73198. static int test_wolfssl_EVP_sm4_ccm(void)
  73199. {
  73200. int res = TEST_SKIPPED;
  73201. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  73202. EXPECT_DECLS;
  73203. byte *key = (byte*)"0123456789012345";
  73204. byte *iv = (byte*)"0123456789012";
  73205. int ivSz = (int)XSTRLEN((char*)iv);
  73206. /* Message to be encrypted */
  73207. byte *plaintxt = (byte*)"for things to change you have to change";
  73208. /* Additional non-confidential data */
  73209. byte *aad = (byte*)"Don't spend major time on minor things.";
  73210. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  73211. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73212. int aadSz = (int)XSTRLEN((char*)aad);
  73213. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73214. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73215. int ciphertxtSz = 0;
  73216. int decryptedtxtSz = 0;
  73217. int len = 0;
  73218. int i = 0;
  73219. EVP_CIPHER_CTX en[2];
  73220. EVP_CIPHER_CTX de[2];
  73221. for (i = 0; i < 2; i++) {
  73222. EVP_CIPHER_CTX_init(&en[i]);
  73223. if (i == 0) {
  73224. /* Default uses 96-bits IV length */
  73225. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  73226. iv));
  73227. }
  73228. else {
  73229. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  73230. NULL));
  73231. /* non-default must to set the IV length first */
  73232. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  73233. ivSz, NULL));
  73234. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73235. }
  73236. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73237. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73238. plaintxtSz));
  73239. ciphertxtSz = len;
  73240. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73241. ciphertxtSz += len;
  73242. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  73243. SM4_BLOCK_SIZE, tag));
  73244. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73245. EVP_CIPHER_CTX_init(&de[i]);
  73246. if (i == 0) {
  73247. /* Default uses 96-bits IV length */
  73248. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  73249. iv));
  73250. }
  73251. else {
  73252. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  73253. NULL));
  73254. /* non-default must to set the IV length first */
  73255. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  73256. ivSz, NULL));
  73257. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73258. }
  73259. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73260. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73261. ciphertxtSz));
  73262. decryptedtxtSz = len;
  73263. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73264. SM4_BLOCK_SIZE, tag));
  73265. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73266. decryptedtxtSz += len;
  73267. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73268. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73269. /* modify tag*/
  73270. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73271. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73272. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73273. SM4_BLOCK_SIZE, tag));
  73274. /* fail due to wrong tag */
  73275. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73276. ciphertxtSz));
  73277. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73278. ExpectIntEQ(0, len);
  73279. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73280. }
  73281. res = EXPECT_RESULT();
  73282. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  73283. return res;
  73284. }
  73285. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  73286. {
  73287. EXPECT_DECLS;
  73288. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  73289. EVP_PKEY_CTX* ctx = NULL;
  73290. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  73291. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  73292. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  73293. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  73294. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  73295. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  73296. byte outKey[34];
  73297. size_t outKeySz = sizeof(outKey);
  73298. /* These expected outputs were gathered by running the same test below using
  73299. * OpenSSL. */
  73300. const byte extractAndExpand[] = {
  73301. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  73302. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  73303. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  73304. };
  73305. const byte extractOnly[] = {
  73306. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  73307. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  73308. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  73309. };
  73310. const byte expandOnly[] = {
  73311. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  73312. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  73313. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  73314. };
  73315. const byte extractAndExpandAddInfo[] = {
  73316. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  73317. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  73318. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  73319. };
  73320. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  73321. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  73322. /* NULL ctx. */
  73323. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73324. /* NULL md. */
  73325. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73326. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  73327. /* NULL ctx. */
  73328. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  73329. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73330. /* NULL salt is ok. */
  73331. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  73332. WOLFSSL_SUCCESS);
  73333. /* Salt length <= 0. */
  73334. /* Length 0 salt is ok. */
  73335. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  73336. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73337. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  73338. WOLFSSL_SUCCESS);
  73339. /* NULL ctx. */
  73340. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  73341. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73342. /* NULL key. */
  73343. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  73344. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73345. /* Key length <= 0 */
  73346. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73347. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73348. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  73349. WOLFSSL_SUCCESS);
  73350. /* NULL ctx. */
  73351. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  73352. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73353. /* NULL info is ok. */
  73354. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  73355. WOLFSSL_SUCCESS);
  73356. /* Info length <= 0 */
  73357. /* Length 0 info is ok. */
  73358. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  73359. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73360. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  73361. WOLFSSL_SUCCESS);
  73362. /* NULL ctx. */
  73363. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73364. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73365. /* Extract and expand (default). */
  73366. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73367. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  73368. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  73369. /* Extract only. */
  73370. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73371. WOLFSSL_SUCCESS);
  73372. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73373. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  73374. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  73375. outKeySz = sizeof(outKey);
  73376. /* Expand only. */
  73377. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  73378. WOLFSSL_SUCCESS);
  73379. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73380. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  73381. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  73382. outKeySz = sizeof(outKey);
  73383. /* Extract and expand with appended additional info. */
  73384. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  73385. WOLFSSL_SUCCESS);
  73386. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  73387. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  73388. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73389. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  73390. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  73391. EVP_PKEY_CTX_free(ctx);
  73392. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  73393. return EXPECT_RESULT();
  73394. }
  73395. #ifndef NO_BIO
  73396. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  73397. {
  73398. EXPECT_DECLS;
  73399. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73400. BIO* bio = NULL;
  73401. X509_INFO* info = NULL;
  73402. STACK_OF(X509_INFO)* sk = NULL;
  73403. char* subject = NULL;
  73404. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  73405. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73406. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  73407. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73408. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  73409. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  73410. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  73411. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  73412. /* using dereference to maintain testing for Apache port*/
  73413. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73414. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73415. 0, 0));
  73416. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  73417. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73418. X509_INFO_free(info);
  73419. info = NULL;
  73420. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73421. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73422. 0, 0));
  73423. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  73424. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73425. X509_INFO_free(info);
  73426. ExpectNull(info = sk_X509_INFO_pop(sk));
  73427. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  73428. BIO_free(bio);
  73429. #endif
  73430. return EXPECT_RESULT();
  73431. }
  73432. #endif /* !NO_BIO */
  73433. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  73434. {
  73435. EXPECT_DECLS;
  73436. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73437. X509 *x509 = NULL;
  73438. X509_NAME* name = NULL;
  73439. int idx = 0;
  73440. X509_NAME_ENTRY *ne = NULL;
  73441. ASN1_OBJECT *object = NULL;
  73442. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  73443. WOLFSSL_FILETYPE_PEM));
  73444. ExpectNotNull(name = X509_get_subject_name(x509));
  73445. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  73446. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  73447. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  73448. X509_free(x509);
  73449. #endif
  73450. return EXPECT_RESULT();
  73451. }
  73452. static int test_wolfSSL_X509_STORE_get1_certs(void)
  73453. {
  73454. EXPECT_DECLS;
  73455. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  73456. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73457. X509_STORE_CTX *storeCtx = NULL;
  73458. X509_STORE *store = NULL;
  73459. X509 *caX509 = NULL;
  73460. X509 *svrX509 = NULL;
  73461. X509_NAME *subject = NULL;
  73462. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  73463. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  73464. SSL_FILETYPE_PEM));
  73465. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  73466. SSL_FILETYPE_PEM)));
  73467. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  73468. ExpectNotNull(store = X509_STORE_new());
  73469. ExpectNotNull(subject = X509_get_subject_name(caX509));
  73470. /* Errors */
  73471. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  73472. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  73473. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  73474. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  73475. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  73476. SSL_SUCCESS);
  73477. /* Should find the cert */
  73478. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73479. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  73480. sk_X509_pop_free(certs, NULL);
  73481. certs = NULL;
  73482. /* Should not find the cert */
  73483. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  73484. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73485. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  73486. sk_X509_pop_free(certs, NULL);
  73487. certs = NULL;
  73488. X509_STORE_free(store);
  73489. X509_STORE_CTX_free(storeCtx);
  73490. X509_free(svrX509);
  73491. X509_free(caX509);
  73492. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  73493. return EXPECT_RESULT();
  73494. }
  73495. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73496. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73497. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73498. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  73499. X509_CRL** crl_out, X509* cert) {
  73500. X509_CRL *crl = NULL;
  73501. XFILE fp = XBADFILE;
  73502. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  73503. int ret = 0;
  73504. (void)ctx;
  73505. if (cert_issuer == NULL)
  73506. return 0;
  73507. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  73508. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  73509. XFCLOSE(fp);
  73510. if (crl != NULL) {
  73511. char* crl_issuer = X509_NAME_oneline(
  73512. X509_CRL_get_issuer(crl), NULL, 0);
  73513. if ((crl_issuer != NULL) &&
  73514. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  73515. *crl_out = X509_CRL_dup(crl);
  73516. if (*crl_out != NULL)
  73517. ret = 1;
  73518. }
  73519. OPENSSL_free(crl_issuer);
  73520. }
  73521. }
  73522. X509_CRL_free(crl);
  73523. OPENSSL_free(cert_issuer);
  73524. return ret;
  73525. }
  73526. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  73527. X509_CRL** crl_out, X509* cert) {
  73528. (void)ctx;
  73529. (void)cert;
  73530. *crl_out = NULL;
  73531. return 1;
  73532. }
  73533. #ifndef NO_WOLFSSL_STUB
  73534. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  73535. X509_CRL* crl) {
  73536. (void)ctx;
  73537. (void)crl;
  73538. return 1;
  73539. }
  73540. #endif
  73541. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  73542. X509_STORE_CTX* ctx) {
  73543. int cert_error = X509_STORE_CTX_get_error(ctx);
  73544. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  73545. int flags = X509_VERIFY_PARAM_get_flags(param);
  73546. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  73547. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  73548. /* Make sure the flags are set */
  73549. return 0;
  73550. }
  73551. /* Ignore CRL missing error */
  73552. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  73553. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  73554. #else
  73555. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  73556. #endif
  73557. return 1;
  73558. return ok;
  73559. }
  73560. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  73561. {
  73562. EXPECT_DECLS;
  73563. X509_STORE* cert_store = NULL;
  73564. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73565. WOLFSSL_SUCCESS);
  73566. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73567. X509_STORE_set_get_crl(cert_store,
  73568. test_wolfSSL_X509_STORE_set_get_crl_provider);
  73569. #ifndef NO_WOLFSSL_STUB
  73570. X509_STORE_set_check_crl(cert_store,
  73571. test_wolfSSL_X509_STORE_set_get_crl_check);
  73572. #endif
  73573. return EXPECT_RESULT();
  73574. }
  73575. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  73576. {
  73577. EXPECT_DECLS;
  73578. X509_STORE* cert_store = NULL;
  73579. X509_VERIFY_PARAM* param = NULL;
  73580. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  73581. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73582. WOLFSSL_SUCCESS);
  73583. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73584. X509_STORE_set_get_crl(cert_store,
  73585. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  73586. #ifndef NO_WOLFSSL_STUB
  73587. X509_STORE_set_check_crl(cert_store,
  73588. test_wolfSSL_X509_STORE_set_get_crl_check);
  73589. #endif
  73590. X509_STORE_set_verify_cb(cert_store,
  73591. test_wolfSSL_X509_STORE_set_get_crl_verify);
  73592. ExpectNotNull(X509_STORE_get0_param(cert_store));
  73593. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  73594. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  73595. X509_STORE_get0_param(cert_store)), 1);
  73596. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  73597. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73598. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  73599. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  73600. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73601. X509_VERIFY_PARAM_free(param);
  73602. return EXPECT_RESULT();
  73603. }
  73604. #endif
  73605. /* This test mimics the usage of the CRL provider in gRPC */
  73606. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  73607. {
  73608. EXPECT_DECLS;
  73609. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73610. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73611. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73612. test_ssl_cbf func_cb_client;
  73613. test_ssl_cbf func_cb_server;
  73614. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73615. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73616. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  73617. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73618. &func_cb_server, NULL), TEST_SUCCESS);
  73619. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73620. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73621. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  73622. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73623. &func_cb_server, NULL), TEST_SUCCESS);
  73624. #endif
  73625. return EXPECT_RESULT();
  73626. }
  73627. static int test_wolfSSL_dup_CA_list(void)
  73628. {
  73629. int res = TEST_SKIPPED;
  73630. #if defined(OPENSSL_ALL)
  73631. EXPECT_DECLS;
  73632. STACK_OF(X509_NAME) *originalStack = NULL;
  73633. STACK_OF(X509_NAME) *copyStack = NULL;
  73634. int originalCount = 0;
  73635. int copyCount = 0;
  73636. X509_NAME *name = NULL;
  73637. int i;
  73638. originalStack = sk_X509_NAME_new_null();
  73639. ExpectNotNull(originalStack);
  73640. for (i = 0; i < 3; i++) {
  73641. name = X509_NAME_new();
  73642. ExpectNotNull(name);
  73643. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  73644. if (EXPECT_FAIL()) {
  73645. X509_NAME_free(name);
  73646. }
  73647. }
  73648. copyStack = SSL_dup_CA_list(originalStack);
  73649. ExpectNotNull(copyStack);
  73650. originalCount = sk_X509_NAME_num(originalStack);
  73651. copyCount = sk_X509_NAME_num(copyStack);
  73652. ExpectIntEQ(originalCount, copyCount);
  73653. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  73654. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  73655. originalStack = NULL;
  73656. copyStack = NULL;
  73657. res = EXPECT_RESULT();
  73658. #endif /* OPENSSL_ALL */
  73659. return res;
  73660. }
  73661. static int test_ForceZero(void)
  73662. {
  73663. EXPECT_DECLS;
  73664. unsigned char data[32];
  73665. unsigned int i, j, len;
  73666. /* Test case with 0 length */
  73667. ForceZero(data, 0);
  73668. /* Test ForceZero */
  73669. for (i = 0; i < sizeof(data); i++) {
  73670. for (len = 1; len < sizeof(data) - i; len++) {
  73671. for (j = 0; j < sizeof(data); j++)
  73672. data[j] = j + 1;
  73673. ForceZero(data + i, len);
  73674. for (j = 0; j < sizeof(data); j++) {
  73675. if (j < i || j >= i + len) {
  73676. ExpectIntNE(data[j], 0x00);
  73677. }
  73678. else {
  73679. ExpectIntEQ(data[j], 0x00);
  73680. }
  73681. }
  73682. }
  73683. }
  73684. return EXPECT_RESULT();
  73685. }
  73686. #ifndef NO_BIO
  73687. static int test_wolfSSL_X509_print(void)
  73688. {
  73689. EXPECT_DECLS;
  73690. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73691. !defined(NO_RSA) && defined(XSNPRINTF)
  73692. X509 *x509 = NULL;
  73693. BIO *bio = NULL;
  73694. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73695. const X509_ALGOR *cert_sig_alg = NULL;
  73696. #endif
  73697. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  73698. WOLFSSL_FILETYPE_PEM));
  73699. /* print to memory */
  73700. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73701. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73702. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  73703. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  73704. /* Will print IP address subject alt name. */
  73705. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  73706. #elif defined(NO_ASN_TIME)
  73707. /* Will print IP address subject alt name but not Validity. */
  73708. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  73709. #else
  73710. /* Will print IP address subject alt name. */
  73711. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  73712. #endif
  73713. #elif defined(NO_ASN_TIME)
  73714. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  73715. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  73716. #else
  73717. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  73718. #endif
  73719. BIO_free(bio);
  73720. bio = NULL;
  73721. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73722. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73723. /* Print signature */
  73724. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  73725. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  73726. #endif
  73727. /* print to stderr */
  73728. #if !defined(NO_WOLFSSL_DIR)
  73729. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73730. #endif
  73731. /* print again */
  73732. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  73733. X509_free(x509);
  73734. BIO_free(bio);
  73735. #endif
  73736. return EXPECT_RESULT();
  73737. }
  73738. static int test_wolfSSL_X509_CRL_print(void)
  73739. {
  73740. EXPECT_DECLS;
  73741. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  73742. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  73743. X509_CRL* crl = NULL;
  73744. BIO *bio = NULL;
  73745. XFILE fp = XBADFILE;
  73746. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  73747. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  73748. NULL, NULL));
  73749. if (fp != XBADFILE)
  73750. XFCLOSE(fp);
  73751. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73752. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  73753. X509_CRL_free(crl);
  73754. BIO_free(bio);
  73755. #endif
  73756. return EXPECT_RESULT();
  73757. }
  73758. static int test_wolfSSL_BIO_get_len(void)
  73759. {
  73760. EXPECT_DECLS;
  73761. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  73762. BIO *bio = NULL;
  73763. const char txt[] = "Some example text to push to the BIO.";
  73764. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73765. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  73766. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  73767. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  73768. BIO_free(bio);
  73769. bio = NULL;
  73770. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73771. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  73772. BIO_free(bio);
  73773. #endif
  73774. return EXPECT_RESULT();
  73775. }
  73776. #endif /* !NO_BIO */
  73777. static int test_wolfSSL_RSA(void)
  73778. {
  73779. EXPECT_DECLS;
  73780. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  73781. RSA* rsa = NULL;
  73782. const BIGNUM *n = NULL;
  73783. const BIGNUM *e = NULL;
  73784. const BIGNUM *d = NULL;
  73785. const BIGNUM *p = NULL;
  73786. const BIGNUM *q = NULL;
  73787. const BIGNUM *dmp1 = NULL;
  73788. const BIGNUM *dmq1 = NULL;
  73789. const BIGNUM *iqmp = NULL;
  73790. ExpectNotNull(rsa = RSA_new());
  73791. ExpectIntEQ(RSA_size(NULL), 0);
  73792. ExpectIntEQ(RSA_size(rsa), 0);
  73793. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  73794. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  73795. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  73796. #ifdef WOLFSSL_RSA_KEY_CHECK
  73797. ExpectIntEQ(RSA_check_key(rsa), 0);
  73798. #endif
  73799. RSA_free(rsa);
  73800. rsa = NULL;
  73801. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73802. ExpectIntEQ(RSA_size(rsa), 256);
  73803. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  73804. {
  73805. /* Test setting only subset of parameters */
  73806. RSA *rsa2 = NULL;
  73807. unsigned char hash[SHA256_DIGEST_LENGTH];
  73808. unsigned char signature[2048/8];
  73809. unsigned int signatureLen = 0;
  73810. XMEMSET(hash, 0, sizeof(hash));
  73811. RSA_get0_key(rsa, &n, &e, &d);
  73812. RSA_get0_factors(rsa, &p, &q);
  73813. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73814. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73815. &signatureLen, rsa), 1);
  73816. /* Quick sanity check */
  73817. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73818. signatureLen, rsa), 1);
  73819. /* Verifying */
  73820. ExpectNotNull(rsa2 = RSA_new());
  73821. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  73822. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73823. signatureLen, rsa2), 1);
  73824. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73825. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73826. signatureLen, rsa2), 1);
  73827. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73828. BN_dup(iqmp)), 1);
  73829. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73830. signatureLen, rsa2), 1);
  73831. RSA_free(rsa2);
  73832. rsa2 = NULL;
  73833. /* Signing */
  73834. XMEMSET(signature, 0, sizeof(signature));
  73835. ExpectNotNull(rsa2 = RSA_new());
  73836. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  73837. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73838. &signatureLen, rsa2), 1);
  73839. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73840. signatureLen, rsa), 1);
  73841. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73842. XMEMSET(signature, 0, sizeof(signature));
  73843. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73844. &signatureLen, rsa2), 1);
  73845. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73846. signatureLen, rsa), 1);
  73847. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73848. BN_dup(iqmp)), 1);
  73849. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73850. &signatureLen, rsa2), 1);
  73851. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73852. signatureLen, rsa), 1);
  73853. RSA_free(rsa2);
  73854. rsa2 = NULL;
  73855. }
  73856. #endif
  73857. #ifdef WOLFSSL_RSA_KEY_CHECK
  73858. ExpectIntEQ(RSA_check_key(NULL), 0);
  73859. ExpectIntEQ(RSA_check_key(rsa), 1);
  73860. #endif
  73861. /* sanity check */
  73862. ExpectIntEQ(RSA_bits(NULL), 0);
  73863. /* key */
  73864. ExpectIntEQ(RSA_bits(rsa), 2048);
  73865. RSA_get0_key(rsa, &n, &e, &d);
  73866. ExpectPtrEq(rsa->n, n);
  73867. ExpectPtrEq(rsa->e, e);
  73868. ExpectPtrEq(rsa->d, d);
  73869. n = NULL;
  73870. e = NULL;
  73871. d = NULL;
  73872. ExpectNotNull(n = BN_new());
  73873. ExpectNotNull(e = BN_new());
  73874. ExpectNotNull(d = BN_new());
  73875. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  73876. if (EXPECT_FAIL()) {
  73877. BN_free((BIGNUM*)n);
  73878. BN_free((BIGNUM*)e);
  73879. BN_free((BIGNUM*)d);
  73880. }
  73881. ExpectPtrEq(rsa->n, n);
  73882. ExpectPtrEq(rsa->e, e);
  73883. ExpectPtrEq(rsa->d, d);
  73884. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  73885. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  73886. /* crt_params */
  73887. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73888. ExpectPtrEq(rsa->dmp1, dmp1);
  73889. ExpectPtrEq(rsa->dmq1, dmq1);
  73890. ExpectPtrEq(rsa->iqmp, iqmp);
  73891. dmp1 = NULL;
  73892. dmq1 = NULL;
  73893. iqmp = NULL;
  73894. ExpectNotNull(dmp1 = BN_new());
  73895. ExpectNotNull(dmq1 = BN_new());
  73896. ExpectNotNull(iqmp = BN_new());
  73897. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73898. (BIGNUM*)iqmp), 1);
  73899. if (EXPECT_FAIL()) {
  73900. BN_free((BIGNUM*)dmp1);
  73901. BN_free((BIGNUM*)dmq1);
  73902. BN_free((BIGNUM*)iqmp);
  73903. }
  73904. ExpectPtrEq(rsa->dmp1, dmp1);
  73905. ExpectPtrEq(rsa->dmq1, dmq1);
  73906. ExpectPtrEq(rsa->iqmp, iqmp);
  73907. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  73908. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73909. (BIGNUM*)iqmp), 0);
  73910. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  73911. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  73912. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  73913. ExpectNull(dmp1);
  73914. ExpectNull(dmq1);
  73915. ExpectNull(iqmp);
  73916. /* factors */
  73917. RSA_get0_factors(rsa, NULL, NULL);
  73918. RSA_get0_factors(rsa, &p, &q);
  73919. ExpectPtrEq(rsa->p, p);
  73920. ExpectPtrEq(rsa->q, q);
  73921. p = NULL;
  73922. q = NULL;
  73923. ExpectNotNull(p = BN_new());
  73924. ExpectNotNull(q = BN_new());
  73925. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  73926. if (EXPECT_FAIL()) {
  73927. BN_free((BIGNUM*)p);
  73928. BN_free((BIGNUM*)q);
  73929. }
  73930. ExpectPtrEq(rsa->p, p);
  73931. ExpectPtrEq(rsa->q, q);
  73932. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  73933. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  73934. RSA_get0_factors(NULL, NULL, NULL);
  73935. RSA_get0_factors(NULL, &p, &q);
  73936. ExpectNull(p);
  73937. ExpectNull(q);
  73938. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  73939. ExpectIntEQ(RSA_bits(rsa), 21);
  73940. RSA_free(rsa);
  73941. rsa = NULL;
  73942. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  73943. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  73944. ExpectIntEQ(RSA_size(rsa), 384);
  73945. ExpectIntEQ(RSA_bits(rsa), 3072);
  73946. RSA_free(rsa);
  73947. rsa = NULL;
  73948. #endif
  73949. /* remove for now with odd key size until adjusting rsa key size check with
  73950. wc_MakeRsaKey()
  73951. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  73952. RSA_free(rsa);
  73953. rsa = NULL;
  73954. */
  73955. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  73956. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  73957. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  73958. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  73959. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  73960. {
  73961. byte buff[FOURK_BUF];
  73962. byte der[FOURK_BUF];
  73963. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  73964. XFILE f = XBADFILE;
  73965. int bytes = 0;
  73966. /* test loading encrypted RSA private pem w/o password */
  73967. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  73968. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  73969. if (f != XBADFILE)
  73970. XFCLOSE(f);
  73971. XMEMSET(der, 0, sizeof(der));
  73972. /* test that error value is returned with no password */
  73973. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  73974. 0);
  73975. }
  73976. #endif
  73977. #endif
  73978. return EXPECT_RESULT();
  73979. }
  73980. static int test_wolfSSL_RSA_DER(void)
  73981. {
  73982. EXPECT_DECLS;
  73983. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  73984. RSA *rsa = NULL;
  73985. int i;
  73986. const unsigned char *buff = NULL;
  73987. unsigned char *newBuff = NULL;
  73988. struct tbl_s
  73989. {
  73990. const unsigned char *der;
  73991. int sz;
  73992. } tbl[] = {
  73993. #ifdef USE_CERT_BUFFERS_1024
  73994. {client_key_der_1024, sizeof_client_key_der_1024},
  73995. {server_key_der_1024, sizeof_server_key_der_1024},
  73996. #endif
  73997. #ifdef USE_CERT_BUFFERS_2048
  73998. {client_key_der_2048, sizeof_client_key_der_2048},
  73999. {server_key_der_2048, sizeof_server_key_der_2048},
  74000. #endif
  74001. {NULL, 0}
  74002. };
  74003. /* Public Key DER */
  74004. struct tbl_s pub[] = {
  74005. #ifdef USE_CERT_BUFFERS_1024
  74006. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  74007. #endif
  74008. #ifdef USE_CERT_BUFFERS_2048
  74009. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  74010. #endif
  74011. {NULL, 0}
  74012. };
  74013. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  74014. buff = pub[0].der;
  74015. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  74016. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  74017. buff = tbl[0].der;
  74018. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  74019. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74020. rsa = RSA_new();
  74021. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  74022. RSA_free(rsa);
  74023. rsa = NULL;
  74024. for (i = 0; tbl[i].der != NULL; i++)
  74025. {
  74026. /* Passing in pointer results in pointer moving. */
  74027. buff = tbl[i].der;
  74028. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  74029. ExpectNotNull(rsa);
  74030. RSA_free(rsa);
  74031. rsa = NULL;
  74032. }
  74033. for (i = 0; tbl[i].der != NULL; i++)
  74034. {
  74035. /* Passing in pointer results in pointer moving. */
  74036. buff = tbl[i].der;
  74037. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  74038. ExpectNotNull(rsa);
  74039. RSA_free(rsa);
  74040. rsa = NULL;
  74041. }
  74042. for (i = 0; pub[i].der != NULL; i++)
  74043. {
  74044. buff = pub[i].der;
  74045. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  74046. ExpectNotNull(rsa);
  74047. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  74048. newBuff = NULL;
  74049. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  74050. ExpectNotNull(newBuff);
  74051. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  74052. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  74053. RSA_free(rsa);
  74054. rsa = NULL;
  74055. }
  74056. #endif
  74057. return EXPECT_RESULT();
  74058. }
  74059. static int test_wolfSSL_RSA_print(void)
  74060. {
  74061. EXPECT_DECLS;
  74062. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74063. !defined(NO_STDIO_FILESYSTEM) && \
  74064. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  74065. !defined(NO_BIO) && defined(XFPRINTF)
  74066. BIO *bio = NULL;
  74067. WOLFSSL_RSA* rsa = NULL;
  74068. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74069. ExpectNotNull(rsa = RSA_new());
  74070. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  74071. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  74072. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  74073. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  74074. /* Some very large number of indent spaces. */
  74075. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  74076. /* RSA is empty. */
  74077. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  74078. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  74079. RSA_free(rsa);
  74080. rsa = NULL;
  74081. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74082. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  74083. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  74084. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  74085. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  74086. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  74087. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  74088. BIO_free(bio);
  74089. RSA_free(rsa);
  74090. #endif
  74091. return EXPECT_RESULT();
  74092. }
  74093. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  74094. {
  74095. EXPECT_DECLS;
  74096. #ifndef NO_RSA
  74097. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74098. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  74099. RSA *rsa = NULL;
  74100. const unsigned char *derBuf = client_key_der_2048;
  74101. unsigned char em[256] = {0}; /* len = 2048/8 */
  74102. /* Random data simulating a hash */
  74103. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  74104. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74105. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74106. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74107. };
  74108. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74109. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  74110. RSA_PSS_SALTLEN_DIGEST), 0);
  74111. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  74112. RSA_PSS_SALTLEN_DIGEST), 0);
  74113. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  74114. RSA_PSS_SALTLEN_DIGEST), 0);
  74115. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  74116. RSA_PSS_SALTLEN_DIGEST), 0);
  74117. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  74118. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  74119. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74120. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  74121. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74122. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  74123. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74124. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  74125. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74126. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74127. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74128. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  74129. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74130. RSA_PSS_SALTLEN_DIGEST), 1);
  74131. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74132. RSA_PSS_SALTLEN_DIGEST), 1);
  74133. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74134. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74135. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74136. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74137. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74138. RSA_PSS_SALTLEN_MAX), 1);
  74139. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74140. RSA_PSS_SALTLEN_MAX), 1);
  74141. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  74142. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  74143. RSA_free(rsa);
  74144. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  74145. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74146. #endif
  74147. return EXPECT_RESULT();
  74148. }
  74149. static int test_wolfSSL_RSA_sign_sha3(void)
  74150. {
  74151. EXPECT_DECLS;
  74152. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  74153. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74154. RSA* rsa = NULL;
  74155. const unsigned char *derBuf = client_key_der_2048;
  74156. unsigned char sigRet[256] = {0};
  74157. unsigned int sigLen = sizeof(sigRet);
  74158. /* Random data simulating a hash */
  74159. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  74160. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74161. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74162. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74163. };
  74164. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74165. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  74166. rsa), 1);
  74167. RSA_free(rsa);
  74168. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74169. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  74170. return EXPECT_RESULT();
  74171. }
  74172. static int test_wolfSSL_RSA_get0_key(void)
  74173. {
  74174. EXPECT_DECLS;
  74175. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74176. RSA *rsa = NULL;
  74177. const BIGNUM* n = NULL;
  74178. const BIGNUM* e = NULL;
  74179. const BIGNUM* d = NULL;
  74180. const unsigned char* der;
  74181. int derSz;
  74182. #ifdef USE_CERT_BUFFERS_1024
  74183. der = client_key_der_1024;
  74184. derSz = sizeof_client_key_der_1024;
  74185. #elif defined(USE_CERT_BUFFERS_2048)
  74186. der = client_key_der_2048;
  74187. derSz = sizeof_client_key_der_2048;
  74188. #else
  74189. der = NULL;
  74190. derSz = 0;
  74191. #endif
  74192. if (der != NULL) {
  74193. RSA_get0_key(NULL, NULL, NULL, NULL);
  74194. RSA_get0_key(rsa, NULL, NULL, NULL);
  74195. RSA_get0_key(NULL, &n, &e, &d);
  74196. ExpectNull(n);
  74197. ExpectNull(e);
  74198. ExpectNull(d);
  74199. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  74200. ExpectNotNull(rsa);
  74201. RSA_get0_key(rsa, NULL, NULL, NULL);
  74202. RSA_get0_key(rsa, &n, NULL, NULL);
  74203. ExpectNotNull(n);
  74204. RSA_get0_key(rsa, NULL, &e, NULL);
  74205. ExpectNotNull(e);
  74206. RSA_get0_key(rsa, NULL, NULL, &d);
  74207. ExpectNotNull(d);
  74208. RSA_get0_key(rsa, &n, &e, &d);
  74209. ExpectNotNull(n);
  74210. ExpectNotNull(e);
  74211. ExpectNotNull(d);
  74212. RSA_free(rsa);
  74213. }
  74214. #endif
  74215. return EXPECT_RESULT();
  74216. }
  74217. static int test_wolfSSL_RSA_meth(void)
  74218. {
  74219. EXPECT_DECLS;
  74220. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74221. RSA *rsa = NULL;
  74222. RSA_METHOD *rsa_meth = NULL;
  74223. #ifdef WOLFSSL_KEY_GEN
  74224. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74225. RSA_free(rsa);
  74226. rsa = NULL;
  74227. #else
  74228. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74229. #endif
  74230. ExpectNotNull(RSA_get_default_method());
  74231. wolfSSL_RSA_meth_free(NULL);
  74232. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  74233. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  74234. RSA_METHOD_FLAG_NO_CHECK));
  74235. #ifndef NO_WOLFSSL_STUB
  74236. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  74237. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  74238. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  74239. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  74240. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  74241. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  74242. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  74243. #endif
  74244. ExpectIntEQ(RSA_flags(NULL), 0);
  74245. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  74246. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  74247. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  74248. ExpectNotNull(rsa = RSA_new());
  74249. /* No method set. */
  74250. ExpectIntEQ(RSA_flags(rsa), 0);
  74251. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74252. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74253. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74254. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  74255. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  74256. if (EXPECT_FAIL()) {
  74257. wolfSSL_RSA_meth_free(rsa_meth);
  74258. }
  74259. ExpectNull(RSA_get_method(NULL));
  74260. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  74261. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  74262. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74263. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74264. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  74265. RSA_METHOD_FLAG_NO_CHECK);
  74266. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74267. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74268. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  74269. /* rsa_meth is freed here */
  74270. RSA_free(rsa);
  74271. #endif
  74272. return EXPECT_RESULT();
  74273. }
  74274. static int test_wolfSSL_RSA_verify(void)
  74275. {
  74276. EXPECT_DECLS;
  74277. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  74278. #ifndef NO_BIO
  74279. XFILE fp = XBADFILE;
  74280. RSA *pKey = NULL;
  74281. RSA *pubKey = NULL;
  74282. X509 *cert = NULL;
  74283. const char *text = "Hello wolfSSL !";
  74284. unsigned char hash[SHA256_DIGEST_LENGTH];
  74285. unsigned char signature[2048/8];
  74286. unsigned int signatureLength;
  74287. byte *buf = NULL;
  74288. BIO *bio = NULL;
  74289. SHA256_CTX c;
  74290. EVP_PKEY *evpPkey = NULL;
  74291. EVP_PKEY *evpPubkey = NULL;
  74292. size_t sz;
  74293. /* generate hash */
  74294. SHA256_Init(&c);
  74295. SHA256_Update(&c, text, strlen(text));
  74296. SHA256_Final(hash, &c);
  74297. #ifdef WOLFSSL_SMALL_STACK_CACHE
  74298. /* workaround for small stack cache case */
  74299. wc_Sha256Free((wc_Sha256*)&c);
  74300. #endif
  74301. /* read privete key file */
  74302. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  74303. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  74304. ExpectTrue((sz = XFTELL(fp)) > 0);
  74305. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  74306. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  74307. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  74308. if (fp != XBADFILE) {
  74309. XFCLOSE(fp);
  74310. fp = XBADFILE;
  74311. }
  74312. /* read private key and sign hash data */
  74313. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  74314. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  74315. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  74316. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  74317. signature, &signatureLength, pKey), SSL_SUCCESS);
  74318. /* read public key and verify signed data */
  74319. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  74320. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  74321. if (fp != XBADFILE)
  74322. XFCLOSE(fp);
  74323. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  74324. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  74325. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74326. signatureLength, pubKey), SSL_SUCCESS);
  74327. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  74328. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74329. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  74330. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74331. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  74332. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74333. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74334. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74335. RSA_free(pKey);
  74336. EVP_PKEY_free(evpPkey);
  74337. RSA_free(pubKey);
  74338. EVP_PKEY_free(evpPubkey);
  74339. X509_free(cert);
  74340. BIO_free(bio);
  74341. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  74342. #endif
  74343. #endif
  74344. return EXPECT_RESULT();
  74345. }
  74346. static int test_wolfSSL_RSA_sign(void)
  74347. {
  74348. EXPECT_DECLS;
  74349. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74350. RSA *rsa;
  74351. unsigned char hash[SHA256_DIGEST_LENGTH];
  74352. #ifdef USE_CERT_BUFFERS_1024
  74353. const unsigned char* privDer = client_key_der_1024;
  74354. size_t privDerSz = sizeof_client_key_der_1024;
  74355. const unsigned char* pubDer = client_keypub_der_1024;
  74356. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74357. unsigned char signature[1024/8];
  74358. #else
  74359. const unsigned char* privDer = client_key_der_2048;
  74360. size_t privDerSz = sizeof_client_key_der_2048;
  74361. const unsigned char* pubDer = client_keypub_der_2048;
  74362. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74363. unsigned char signature[2048/8];
  74364. #endif
  74365. unsigned int signatureLen;
  74366. const unsigned char* der;
  74367. XMEMSET(hash, 0, sizeof(hash));
  74368. der = privDer;
  74369. rsa = NULL;
  74370. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74371. /* Invalid parameters. */
  74372. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  74373. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  74374. &signatureLen, rsa), 0);
  74375. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  74376. &signatureLen, rsa), 0);
  74377. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  74378. &signatureLen, rsa), 0);
  74379. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74380. NULL, rsa), 0);
  74381. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74382. &signatureLen, NULL), 0);
  74383. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74384. &signatureLen, rsa), 1);
  74385. RSA_free(rsa);
  74386. der = pubDer;
  74387. rsa = NULL;
  74388. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74389. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74390. signatureLen, rsa), 1);
  74391. RSA_free(rsa);
  74392. #endif
  74393. return EXPECT_RESULT();
  74394. }
  74395. static int test_wolfSSL_RSA_sign_ex(void)
  74396. {
  74397. EXPECT_DECLS;
  74398. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74399. RSA *rsa = NULL;
  74400. unsigned char hash[SHA256_DIGEST_LENGTH];
  74401. #ifdef USE_CERT_BUFFERS_1024
  74402. const unsigned char* privDer = client_key_der_1024;
  74403. size_t privDerSz = sizeof_client_key_der_1024;
  74404. const unsigned char* pubDer = client_keypub_der_1024;
  74405. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74406. unsigned char signature[1024/8];
  74407. #else
  74408. const unsigned char* privDer = client_key_der_2048;
  74409. size_t privDerSz = sizeof_client_key_der_2048;
  74410. const unsigned char* pubDer = client_keypub_der_2048;
  74411. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74412. unsigned char signature[2048/8];
  74413. #endif
  74414. unsigned int signatureLen;
  74415. const unsigned char* der;
  74416. unsigned char encodedHash[51];
  74417. unsigned int encodedHashLen;
  74418. const unsigned char expEncHash[] = {
  74419. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  74420. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  74421. 0x00, 0x04, 0x20,
  74422. /* Hash data */
  74423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74425. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74426. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74427. };
  74428. XMEMSET(hash, 0, sizeof(hash));
  74429. ExpectNotNull(rsa = wolfSSL_RSA_new());
  74430. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74431. &signatureLen, rsa, 1), 0);
  74432. wolfSSL_RSA_free(rsa);
  74433. der = privDer;
  74434. rsa = NULL;
  74435. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74436. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  74437. -1), 0);
  74438. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  74439. signature, &signatureLen, rsa, 1), 0);
  74440. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74441. &signatureLen, rsa, 1), 0);
  74442. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74443. &signatureLen, rsa, 1), 0);
  74444. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74445. NULL, rsa, 1), 0);
  74446. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74447. &signatureLen, NULL, 1), 0);
  74448. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74449. &signatureLen, rsa, -1), 0);
  74450. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74451. &signatureLen, rsa, 0), 0);
  74452. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74453. &signatureLen, rsa, 0), 0);
  74454. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74455. NULL, rsa, 0), 0);
  74456. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74457. &signatureLen, rsa, 1), 1);
  74458. /* Test returning encoded hash. */
  74459. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  74460. &encodedHashLen, rsa, 0), 1);
  74461. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  74462. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  74463. RSA_free(rsa);
  74464. der = pubDer;
  74465. rsa = NULL;
  74466. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74467. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74468. signatureLen, rsa), 1);
  74469. RSA_free(rsa);
  74470. #endif
  74471. return EXPECT_RESULT();
  74472. }
  74473. static int test_wolfSSL_RSA_public_decrypt(void)
  74474. {
  74475. EXPECT_DECLS;
  74476. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74477. RSA *rsa;
  74478. unsigned char msg[SHA256_DIGEST_LENGTH];
  74479. #ifdef USE_CERT_BUFFERS_1024
  74480. const unsigned char* pubDer = client_keypub_der_1024;
  74481. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74482. unsigned char decMsg[1024/8];
  74483. const unsigned char encMsg[] = {
  74484. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74485. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74486. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74487. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74488. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74489. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74490. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74491. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74492. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74493. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74494. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74495. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74496. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74497. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74498. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74499. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74500. };
  74501. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74502. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74503. defined(WC_RSA_NO_PADDING)
  74504. const unsigned char encMsgNoPad[] = {
  74505. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74506. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74507. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74508. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74509. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74510. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74511. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74512. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74513. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74514. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74515. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74516. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74517. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74518. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74519. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74520. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74521. };
  74522. #endif
  74523. #else
  74524. const unsigned char* pubDer = client_keypub_der_2048;
  74525. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74526. unsigned char decMsg[2048/8];
  74527. const unsigned char encMsg[] = {
  74528. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74529. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74530. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74531. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74532. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74533. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74534. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74535. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74536. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74537. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74538. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74539. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74540. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74541. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74542. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74543. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74544. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74545. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74546. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74547. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74548. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74549. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74550. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74551. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74552. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74553. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74554. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74555. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74556. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74557. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74558. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74559. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74560. };
  74561. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74562. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74563. defined(WC_RSA_NO_PADDING)
  74564. const unsigned char encMsgNoPad[] = {
  74565. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74566. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74567. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74568. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74569. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74570. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74571. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74572. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74573. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74574. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74575. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74576. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74577. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74578. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74579. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74580. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74581. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74582. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74583. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74584. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74585. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74586. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74587. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74588. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74589. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74590. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74591. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74592. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74593. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74594. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74595. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74596. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74597. };
  74598. #endif
  74599. #endif
  74600. const unsigned char* der;
  74601. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74602. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74603. defined(WC_RSA_NO_PADDING)
  74604. int i;
  74605. #endif
  74606. XMEMSET(msg, 0, sizeof(msg));
  74607. der = pubDer;
  74608. rsa = NULL;
  74609. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74610. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  74611. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  74612. RSA_PKCS1_PADDING), -1);
  74613. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  74614. RSA_PKCS1_PADDING), -1);
  74615. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74616. RSA_PKCS1_PADDING), -1);
  74617. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  74618. RSA_PKCS1_PADDING), -1);
  74619. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74620. RSA_PKCS1_PSS_PADDING), -1);
  74621. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74622. RSA_PKCS1_PADDING), 32);
  74623. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  74624. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74625. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74626. defined(WC_RSA_NO_PADDING)
  74627. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  74628. rsa, RSA_NO_PADDING), sizeof(decMsg));
  74629. /* Zeros before actual data. */
  74630. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  74631. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74632. }
  74633. /* Check actual data. */
  74634. XMEMSET(msg, 0x01, sizeof(msg));
  74635. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74636. #endif
  74637. RSA_free(rsa);
  74638. #endif
  74639. return EXPECT_RESULT();
  74640. }
  74641. static int test_wolfSSL_RSA_private_encrypt(void)
  74642. {
  74643. EXPECT_DECLS;
  74644. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74645. RSA *rsa;
  74646. unsigned char msg[SHA256_DIGEST_LENGTH];
  74647. #ifdef USE_CERT_BUFFERS_1024
  74648. const unsigned char* privDer = client_key_der_1024;
  74649. size_t privDerSz = sizeof_client_key_der_1024;
  74650. unsigned char encMsg[1024/8];
  74651. const unsigned char expEncMsg[] = {
  74652. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74653. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74654. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74655. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74656. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74657. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74658. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74659. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74660. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74661. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74662. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74663. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74664. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74665. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74666. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74667. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74668. };
  74669. #ifdef WC_RSA_NO_PADDING
  74670. const unsigned char expEncMsgNoPad[] = {
  74671. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74672. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74673. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74674. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74675. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74676. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74677. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74678. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74679. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74680. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74681. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74682. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74683. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74684. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74685. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74686. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74687. };
  74688. #endif
  74689. #else
  74690. const unsigned char* privDer = client_key_der_2048;
  74691. size_t privDerSz = sizeof_client_key_der_2048;
  74692. unsigned char encMsg[2048/8];
  74693. const unsigned char expEncMsg[] = {
  74694. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74695. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74696. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74697. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74698. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74699. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74700. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74701. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74702. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74703. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74704. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74705. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74706. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74707. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74708. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74709. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74710. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74711. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74712. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74713. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74714. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74715. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74716. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74717. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74718. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74719. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74720. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74721. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74722. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74723. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74724. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74725. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74726. };
  74727. #ifdef WC_RSA_NO_PADDING
  74728. const unsigned char expEncMsgNoPad[] = {
  74729. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74730. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74731. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74732. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74733. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74734. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74735. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74736. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74737. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74738. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74739. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74740. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74741. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74742. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74743. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74744. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74745. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74746. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74747. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74748. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74749. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74750. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74751. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74752. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74753. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74754. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74755. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74756. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74757. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74758. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74759. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74760. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74761. };
  74762. #endif
  74763. #endif
  74764. const unsigned char* der;
  74765. XMEMSET(msg, 0x00, sizeof(msg));
  74766. der = privDer;
  74767. rsa = NULL;
  74768. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74769. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  74770. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  74771. -1);
  74772. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74773. RSA_PKCS1_PADDING), -1);
  74774. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  74775. RSA_PKCS1_PADDING), -1);
  74776. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  74777. RSA_PKCS1_PADDING), -1);
  74778. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74779. RSA_PKCS1_PSS_PADDING), -1);
  74780. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74781. RSA_PKCS1_PADDING), sizeof(encMsg));
  74782. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  74783. #ifdef WC_RSA_NO_PADDING
  74784. /* Non-zero message. */
  74785. XMEMSET(msg, 0x01, sizeof(msg));
  74786. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74787. RSA_NO_PADDING), sizeof(encMsg));
  74788. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  74789. #endif
  74790. RSA_free(rsa);
  74791. #endif
  74792. return EXPECT_RESULT();
  74793. }
  74794. static int test_wolfSSL_RSA_public_encrypt(void)
  74795. {
  74796. EXPECT_DECLS;
  74797. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74798. RSA* rsa = NULL;
  74799. const unsigned char msg[2048/8] = { 0 };
  74800. unsigned char encMsg[2048/8];
  74801. ExpectNotNull(rsa = RSA_new());
  74802. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  74803. RSA_PKCS1_PADDING), -1);
  74804. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74805. RSA_PKCS1_PADDING), -1);
  74806. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  74807. RSA_PKCS1_PADDING), -1);
  74808. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  74809. RSA_PKCS1_PADDING), -1);
  74810. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74811. RSA_PKCS1_PSS_PADDING), -1);
  74812. /* Empty RSA key. */
  74813. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74814. RSA_PKCS1_PADDING), -1);
  74815. RSA_free(rsa);
  74816. #endif
  74817. return EXPECT_RESULT();
  74818. }
  74819. static int test_wolfSSL_RSA_private_decrypt(void)
  74820. {
  74821. EXPECT_DECLS;
  74822. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74823. RSA* rsa = NULL;
  74824. unsigned char msg[2048/8];
  74825. const unsigned char encMsg[2048/8] = { 0 };
  74826. ExpectNotNull(rsa = RSA_new());
  74827. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  74828. RSA_PKCS1_PADDING), -1);
  74829. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  74830. RSA_PKCS1_PADDING), -1);
  74831. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74832. RSA_PKCS1_PADDING), -1);
  74833. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  74834. RSA_PKCS1_PADDING), -1);
  74835. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74836. RSA_PKCS1_PSS_PADDING), -1);
  74837. /* Empty RSA key. */
  74838. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74839. RSA_PKCS1_PADDING), -1);
  74840. RSA_free(rsa);
  74841. #endif
  74842. return EXPECT_RESULT();
  74843. }
  74844. static int test_wolfSSL_RSA_GenAdd(void)
  74845. {
  74846. EXPECT_DECLS;
  74847. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74848. RSA *rsa;
  74849. #ifdef USE_CERT_BUFFERS_1024
  74850. const unsigned char* privDer = client_key_der_1024;
  74851. size_t privDerSz = sizeof_client_key_der_1024;
  74852. const unsigned char* pubDer = client_keypub_der_1024;
  74853. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74854. #else
  74855. const unsigned char* privDer = client_key_der_2048;
  74856. size_t privDerSz = sizeof_client_key_der_2048;
  74857. const unsigned char* pubDer = client_keypub_der_2048;
  74858. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74859. #endif
  74860. const unsigned char* der;
  74861. der = privDer;
  74862. rsa = NULL;
  74863. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74864. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  74865. #ifndef RSA_LOW_MEM
  74866. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  74867. #else
  74868. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  74869. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74870. #endif
  74871. RSA_free(rsa);
  74872. der = pubDer;
  74873. rsa = NULL;
  74874. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74875. /* Need private values. */
  74876. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74877. RSA_free(rsa);
  74878. #endif
  74879. return EXPECT_RESULT();
  74880. }
  74881. static int test_wolfSSL_RSA_blinding_on(void)
  74882. {
  74883. EXPECT_DECLS;
  74884. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  74885. RSA *rsa;
  74886. WOLFSSL_BN_CTX *bnCtx = NULL;
  74887. #ifdef USE_CERT_BUFFERS_1024
  74888. const unsigned char* privDer = client_key_der_1024;
  74889. size_t privDerSz = sizeof_client_key_der_1024;
  74890. #else
  74891. const unsigned char* privDer = client_key_der_2048;
  74892. size_t privDerSz = sizeof_client_key_der_2048;
  74893. #endif
  74894. const unsigned char* der;
  74895. der = privDer;
  74896. rsa = NULL;
  74897. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74898. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  74899. /* Does nothing so all parameters are valid. */
  74900. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  74901. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  74902. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  74903. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  74904. wolfSSL_BN_CTX_free(bnCtx);
  74905. RSA_free(rsa);
  74906. #endif
  74907. return EXPECT_RESULT();
  74908. }
  74909. static int test_wolfSSL_RSA_ex_data(void)
  74910. {
  74911. EXPECT_DECLS;
  74912. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74913. RSA* rsa = NULL;
  74914. unsigned char data[1];
  74915. ExpectNotNull(rsa = RSA_new());
  74916. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  74917. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74918. #ifdef MAX_EX_DATA
  74919. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  74920. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  74921. #endif
  74922. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  74923. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  74924. #ifdef HAVE_EX_DATA
  74925. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  74926. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  74927. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  74928. #else
  74929. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  74930. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  74931. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74932. #endif
  74933. RSA_free(rsa);
  74934. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74935. return EXPECT_RESULT();
  74936. }
  74937. static int test_wolfSSL_RSA_LoadDer(void)
  74938. {
  74939. EXPECT_DECLS;
  74940. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  74941. defined(OPENSSL_EXTRA_X509_SMALL))
  74942. RSA *rsa = NULL;
  74943. #ifdef USE_CERT_BUFFERS_1024
  74944. const unsigned char* privDer = client_key_der_1024;
  74945. size_t privDerSz = sizeof_client_key_der_1024;
  74946. #else
  74947. const unsigned char* privDer = client_key_der_2048;
  74948. size_t privDerSz = sizeof_client_key_der_2048;
  74949. #endif
  74950. ExpectNotNull(rsa = RSA_new());
  74951. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  74952. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  74953. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  74954. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  74955. RSA_free(rsa);
  74956. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74957. return EXPECT_RESULT();
  74958. }
  74959. /* Local API. */
  74960. static int test_wolfSSL_RSA_To_Der(void)
  74961. {
  74962. EXPECT_DECLS;
  74963. #ifdef WOLFSSL_TEST_STATIC_BUILD
  74964. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74965. RSA* rsa;
  74966. #ifdef USE_CERT_BUFFERS_1024
  74967. const unsigned char* privDer = client_key_der_1024;
  74968. size_t privDerSz = sizeof_client_key_der_1024;
  74969. const unsigned char* pubDer = client_keypub_der_1024;
  74970. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74971. unsigned char out[sizeof(client_key_der_1024)];
  74972. #else
  74973. const unsigned char* privDer = client_key_der_2048;
  74974. size_t privDerSz = sizeof_client_key_der_2048;
  74975. const unsigned char* pubDer = client_keypub_der_2048;
  74976. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74977. unsigned char out[sizeof(client_key_der_2048)];
  74978. #endif
  74979. const unsigned char* der;
  74980. unsigned char* outDer = NULL;
  74981. der = privDer;
  74982. rsa = NULL;
  74983. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74984. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74985. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74986. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  74987. outDer = out;
  74988. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74989. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  74990. outDer = NULL;
  74991. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74992. ExpectNotNull(outDer);
  74993. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  74994. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  74995. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  74996. outDer = out;
  74997. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  74998. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  74999. RSA_free(rsa);
  75000. ExpectNotNull(rsa = RSA_new());
  75001. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75002. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75003. RSA_free(rsa);
  75004. der = pubDer;
  75005. rsa = NULL;
  75006. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75007. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75008. RSA_free(rsa);
  75009. #endif
  75010. #endif
  75011. return EXPECT_RESULT();
  75012. }
  75013. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75014. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  75015. {
  75016. EXPECT_DECLS;
  75017. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  75018. XFILE file = XBADFILE;
  75019. const char* fname = "./certs/server-keyPub.pem";
  75020. RSA *rsa = NULL;
  75021. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  75022. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  75023. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  75024. ExpectIntEQ(RSA_size(rsa), 256);
  75025. RSA_free(rsa);
  75026. if (file != XBADFILE)
  75027. XFCLOSE(file);
  75028. #endif
  75029. return EXPECT_RESULT();
  75030. }
  75031. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75032. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  75033. {
  75034. EXPECT_DECLS;
  75035. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  75036. defined(WOLFSSL_KEY_GEN)
  75037. RSA* rsa = NULL;
  75038. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  75039. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  75040. /* Valid but stub so returns 0. */
  75041. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  75042. #endif
  75043. return EXPECT_RESULT();
  75044. }
  75045. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  75046. {
  75047. EXPECT_DECLS;
  75048. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75049. (defined(WOLFSSL_PEM_TO_DER) || \
  75050. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  75051. RSA* rsa = NULL;
  75052. #ifdef USE_CERT_BUFFERS_1024
  75053. const unsigned char* privDer = client_key_der_1024;
  75054. size_t privDerSz = sizeof_client_key_der_1024;
  75055. #else
  75056. const unsigned char* privDer = client_key_der_2048;
  75057. size_t privDerSz = sizeof_client_key_der_2048;
  75058. #endif
  75059. const unsigned char* der;
  75060. #ifndef NO_AES
  75061. unsigned char passwd[] = "password";
  75062. #endif
  75063. ExpectNotNull(rsa = RSA_new());
  75064. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75065. NULL, NULL), 0);
  75066. RSA_free(rsa);
  75067. der = privDer;
  75068. rsa = NULL;
  75069. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75070. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  75071. NULL, NULL), 0);
  75072. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  75073. NULL, NULL), 0);
  75074. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75075. NULL, NULL), 1);
  75076. #ifndef NO_AES
  75077. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75078. NULL, 0, NULL, NULL), 1);
  75079. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75080. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  75081. #endif
  75082. RSA_free(rsa);
  75083. #endif
  75084. return EXPECT_RESULT();
  75085. }
  75086. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  75087. {
  75088. EXPECT_DECLS;
  75089. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75090. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  75091. RSA* rsa = NULL;
  75092. #ifdef USE_CERT_BUFFERS_1024
  75093. const unsigned char* privDer = client_key_der_1024;
  75094. size_t privDerSz = sizeof_client_key_der_1024;
  75095. #else
  75096. const unsigned char* privDer = client_key_der_2048;
  75097. size_t privDerSz = sizeof_client_key_der_2048;
  75098. #endif
  75099. const unsigned char* der;
  75100. #ifndef NO_AES
  75101. unsigned char passwd[] = "password";
  75102. #endif
  75103. unsigned char* pem = NULL;
  75104. int plen;
  75105. ExpectNotNull(rsa = RSA_new());
  75106. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75107. &plen), 0);
  75108. RSA_free(rsa);
  75109. der = privDer;
  75110. rsa = NULL;
  75111. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75112. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  75113. &plen), 0);
  75114. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  75115. &plen), 0);
  75116. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75117. NULL), 0);
  75118. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75119. &plen), 1);
  75120. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75121. pem = NULL;
  75122. #ifndef NO_AES
  75123. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75124. NULL, 0, &pem, &plen), 1);
  75125. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75126. pem = NULL;
  75127. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75128. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  75129. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75130. #endif
  75131. RSA_free(rsa);
  75132. #endif
  75133. return EXPECT_RESULT();
  75134. }
  75135. static int test_wolfSSL_DH(void)
  75136. {
  75137. EXPECT_DECLS;
  75138. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75139. DH *dh = NULL;
  75140. BIGNUM* p;
  75141. BIGNUM* q;
  75142. BIGNUM* g;
  75143. BIGNUM* pub = NULL;
  75144. BIGNUM* priv = NULL;
  75145. #if defined(OPENSSL_ALL)
  75146. #if !defined(HAVE_FIPS) || \
  75147. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  75148. FILE* f = NULL;
  75149. unsigned char buf[268];
  75150. const unsigned char* pt = buf;
  75151. long len = 0;
  75152. dh = NULL;
  75153. XMEMSET(buf, 0, sizeof(buf));
  75154. /* Test 2048 bit parameters */
  75155. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  75156. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75157. if (f != XBADFILE)
  75158. XFCLOSE(f);
  75159. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  75160. ExpectNotNull(dh->p);
  75161. ExpectNotNull(dh->g);
  75162. ExpectTrue(pt == buf);
  75163. ExpectIntEQ(DH_generate_key(dh), 1);
  75164. /* first, test for expected successful key agreement. */
  75165. if (EXPECT_SUCCESS()) {
  75166. DH *dh2 = NULL;
  75167. unsigned char buf2[268];
  75168. int sz1 = 0, sz2 = 0;
  75169. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  75170. ExpectIntEQ(DH_generate_key(dh2), 1);
  75171. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  75172. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  75173. ExpectIntEQ(sz1, sz2);
  75174. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75175. ExpectIntNE(sz1 = DH_size(dh), 0);
  75176. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  75177. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  75178. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75179. if (dh2 != NULL)
  75180. DH_free(dh2);
  75181. }
  75182. ExpectIntEQ(DH_generate_key(dh), 1);
  75183. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  75184. ExpectNotNull(pub = BN_new());
  75185. ExpectIntEQ(BN_set_word(pub, 1), 1);
  75186. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  75187. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  75188. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  75189. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  75190. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  75191. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  75192. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  75193. BN_free(pub);
  75194. pub = NULL;
  75195. DH_get0_pqg(dh, (const BIGNUM**)&p,
  75196. (const BIGNUM**)&q,
  75197. (const BIGNUM**)&g);
  75198. ExpectPtrEq(p, dh->p);
  75199. ExpectPtrEq(q, dh->q);
  75200. ExpectPtrEq(g, dh->g);
  75201. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  75202. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  75203. ExpectPtrEq(pub, dh->pub_key);
  75204. ExpectPtrEq(priv, dh->priv_key);
  75205. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  75206. ExpectPtrEq(pub, dh->pub_key);
  75207. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  75208. ExpectPtrEq(priv, dh->priv_key);
  75209. pub = NULL;
  75210. priv = NULL;
  75211. ExpectNotNull(pub = BN_new());
  75212. ExpectNotNull(priv = BN_new());
  75213. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  75214. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  75215. if (EXPECT_FAIL()) {
  75216. BN_free(pub);
  75217. BN_free(priv);
  75218. }
  75219. pub = NULL;
  75220. priv = NULL;
  75221. ExpectNotNull(pub = BN_new());
  75222. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  75223. if (EXPECT_FAIL()) {
  75224. BN_free(pub);
  75225. }
  75226. ExpectNotNull(priv = BN_new());
  75227. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  75228. if (EXPECT_FAIL()) {
  75229. BN_free(priv);
  75230. }
  75231. ExpectPtrEq(pub, dh->pub_key);
  75232. ExpectPtrEq(priv, dh->priv_key);
  75233. pub = NULL;
  75234. priv = NULL;
  75235. DH_free(dh);
  75236. dh = NULL;
  75237. ExpectNotNull(dh = DH_new());
  75238. p = NULL;
  75239. ExpectNotNull(p = BN_new());
  75240. ExpectIntEQ(BN_set_word(p, 1), 1);
  75241. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  75242. ExpectNotNull(pub = BN_new());
  75243. ExpectNotNull(priv = BN_new());
  75244. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  75245. if (EXPECT_FAIL()) {
  75246. BN_free(pub);
  75247. BN_free(priv);
  75248. }
  75249. pub = NULL;
  75250. priv = NULL;
  75251. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  75252. BN_free(p);
  75253. p = NULL;
  75254. DH_free(dh);
  75255. dh = NULL;
  75256. #ifdef WOLFSSL_KEY_GEN
  75257. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  75258. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  75259. DH_free(dh);
  75260. dh = NULL;
  75261. #endif
  75262. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  75263. #endif /* OPENSSL_ALL */
  75264. (void)dh;
  75265. (void)p;
  75266. (void)q;
  75267. (void)g;
  75268. (void)pub;
  75269. (void)priv;
  75270. ExpectNotNull(dh = wolfSSL_DH_new());
  75271. /* invalid parameters test */
  75272. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  75273. (const BIGNUM**)&q,
  75274. (const BIGNUM**)&g);
  75275. DH_get0_pqg(dh, NULL,
  75276. (const BIGNUM**)&q,
  75277. (const BIGNUM**)&g);
  75278. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  75279. DH_get0_pqg(dh, NULL, NULL, NULL);
  75280. DH_get0_pqg(dh, (const BIGNUM**)&p,
  75281. (const BIGNUM**)&q,
  75282. (const BIGNUM**)&g);
  75283. ExpectPtrEq(p, NULL);
  75284. ExpectPtrEq(q, NULL);
  75285. ExpectPtrEq(g, NULL);
  75286. DH_free(dh);
  75287. dh = NULL;
  75288. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  75289. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  75290. #if defined(OPENSSL_ALL) || \
  75291. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75292. dh = wolfSSL_DH_new();
  75293. ExpectNotNull(dh);
  75294. p = wolfSSL_BN_new();
  75295. ExpectNotNull(p);
  75296. ExpectIntEQ(BN_set_word(p, 11), 1);
  75297. g = wolfSSL_BN_new();
  75298. ExpectNotNull(g);
  75299. ExpectIntEQ(BN_set_word(g, 2), 1);
  75300. q = wolfSSL_BN_new();
  75301. ExpectNotNull(q);
  75302. ExpectIntEQ(BN_set_word(q, 5), 1);
  75303. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  75304. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  75305. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  75306. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  75307. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  75308. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  75309. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  75310. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  75311. /* Don't need q. */
  75312. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75313. if (EXPECT_FAIL()) {
  75314. BN_free(p);
  75315. BN_free(g);
  75316. }
  75317. p = NULL;
  75318. g = NULL;
  75319. /* Setting again will free the p and g. */
  75320. wolfSSL_BN_free(q);
  75321. q = NULL;
  75322. DH_free(dh);
  75323. dh = NULL;
  75324. dh = wolfSSL_DH_new();
  75325. ExpectNotNull(dh);
  75326. p = wolfSSL_BN_new();
  75327. ExpectNotNull(p);
  75328. ExpectIntEQ(BN_set_word(p, 11), 1);
  75329. g = wolfSSL_BN_new();
  75330. ExpectNotNull(g);
  75331. ExpectIntEQ(BN_set_word(g, 2), 1);
  75332. q = wolfSSL_BN_new();
  75333. ExpectNotNull(q);
  75334. ExpectIntEQ(BN_set_word(q, 5), 1);
  75335. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  75336. /* p, q and g are now owned by dh - don't free. */
  75337. if (EXPECT_FAIL()) {
  75338. BN_free(p);
  75339. BN_free(q);
  75340. BN_free(g);
  75341. }
  75342. p = NULL;
  75343. q = NULL;
  75344. g = NULL;
  75345. p = wolfSSL_BN_new();
  75346. ExpectNotNull(p);
  75347. ExpectIntEQ(BN_set_word(p, 11), 1);
  75348. g = wolfSSL_BN_new();
  75349. ExpectNotNull(g);
  75350. ExpectIntEQ(BN_set_word(g, 2), 1);
  75351. q = wolfSSL_BN_new();
  75352. ExpectNotNull(q);
  75353. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  75354. if (EXPECT_FAIL()) {
  75355. BN_free(p);
  75356. }
  75357. p = NULL;
  75358. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  75359. if (EXPECT_FAIL()) {
  75360. BN_free(q);
  75361. }
  75362. q = NULL;
  75363. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  75364. if (EXPECT_FAIL()) {
  75365. BN_free(g);
  75366. }
  75367. g = NULL;
  75368. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  75369. /* p, q and g are now owned by dh - don't free. */
  75370. DH_free(dh);
  75371. dh = NULL;
  75372. ExpectIntEQ(DH_generate_key(NULL), 0);
  75373. ExpectNotNull(dh = DH_new());
  75374. ExpectIntEQ(DH_generate_key(dh), 0);
  75375. p = wolfSSL_BN_new();
  75376. ExpectNotNull(p);
  75377. ExpectIntEQ(BN_set_word(p, 0), 1);
  75378. g = wolfSSL_BN_new();
  75379. ExpectNotNull(g);
  75380. ExpectIntEQ(BN_set_word(g, 2), 1);
  75381. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75382. if (EXPECT_FAIL()) {
  75383. BN_free(p);
  75384. BN_free(g);
  75385. }
  75386. p = NULL;
  75387. g = NULL;
  75388. ExpectIntEQ(DH_generate_key(dh), 0);
  75389. DH_free(dh);
  75390. dh = NULL;
  75391. #endif
  75392. #endif
  75393. /* Test DH_up_ref() */
  75394. dh = wolfSSL_DH_new();
  75395. ExpectNotNull(dh);
  75396. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75397. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  75398. DH_free(dh); /* decrease ref count */
  75399. DH_free(dh); /* free WOLFSSL_DH */
  75400. dh = NULL;
  75401. q = NULL;
  75402. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  75403. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  75404. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  75405. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  75406. #ifdef HAVE_FFDHE_2048
  75407. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75408. DH_free(dh);
  75409. dh = NULL;
  75410. q = NULL;
  75411. #endif
  75412. #ifdef HAVE_FFDHE_3072
  75413. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  75414. DH_free(dh);
  75415. dh = NULL;
  75416. q = NULL;
  75417. #endif
  75418. #ifdef HAVE_FFDHE_4096
  75419. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  75420. DH_free(dh);
  75421. dh = NULL;
  75422. q = NULL;
  75423. #endif
  75424. #else
  75425. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75426. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  75427. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  75428. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  75429. #endif /* OPENSSL_EXTRA && !NO_DH */
  75430. return EXPECT_RESULT();
  75431. }
  75432. static int test_wolfSSL_DH_dup(void)
  75433. {
  75434. EXPECT_DECLS;
  75435. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  75436. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  75437. defined(OPENSSL_EXTRA)
  75438. DH *dh = NULL;
  75439. DH *dhDup = NULL;
  75440. ExpectNotNull(dh = wolfSSL_DH_new());
  75441. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  75442. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  75443. #if defined(OPENSSL_ALL) || \
  75444. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75445. {
  75446. WOLFSSL_BIGNUM* p = NULL;
  75447. WOLFSSL_BIGNUM* g = NULL;
  75448. ExpectNotNull(p = wolfSSL_BN_new());
  75449. ExpectNotNull(g = wolfSSL_BN_new());
  75450. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  75451. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  75452. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75453. if (EXPECT_FAIL()) {
  75454. wolfSSL_BN_free(p);
  75455. wolfSSL_BN_free(g);
  75456. }
  75457. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  75458. wolfSSL_DH_free(dhDup);
  75459. }
  75460. #endif
  75461. wolfSSL_DH_free(dh);
  75462. #endif
  75463. #endif
  75464. return EXPECT_RESULT();
  75465. }
  75466. static int test_wolfSSL_DH_check(void)
  75467. {
  75468. EXPECT_DECLS;
  75469. #ifdef OPENSSL_ALL
  75470. #ifndef NO_DH
  75471. #ifndef NO_BIO
  75472. #ifndef NO_DSA
  75473. byte buf[6000];
  75474. char file[] = "./certs/dsaparams.pem";
  75475. XFILE f = XBADFILE;
  75476. int bytes = 0;
  75477. BIO* bio = NULL;
  75478. DSA* dsa = NULL;
  75479. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75480. static const byte dh2048[] = {
  75481. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75482. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75483. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75484. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75485. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75486. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75487. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75488. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75489. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75490. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75491. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75492. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75493. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75494. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75495. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75496. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75497. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75498. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75499. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75500. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75501. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75502. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75503. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75504. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75505. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75506. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75507. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75508. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75509. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75510. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75511. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75512. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75513. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75514. 0x93, 0x02, 0x01, 0x02
  75515. };
  75516. const byte* params;
  75517. #endif
  75518. DH* dh = NULL;
  75519. WOLFSSL_BIGNUM* p = NULL;
  75520. WOLFSSL_BIGNUM* g = NULL;
  75521. WOLFSSL_BIGNUM* pTmp = NULL;
  75522. WOLFSSL_BIGNUM* gTmp = NULL;
  75523. int codes = -1;
  75524. #ifndef NO_DSA
  75525. /* Initialize DH */
  75526. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  75527. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  75528. if (f != XBADFILE)
  75529. XFCLOSE(f);
  75530. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  75531. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  75532. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  75533. ExpectNotNull(dh);
  75534. BIO_free(bio);
  75535. DSA_free(dsa);
  75536. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75537. params = dh2048;
  75538. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  75539. (long)sizeof(dh2048)));
  75540. #else
  75541. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  75542. #endif
  75543. /* Test assumed to be valid dh.
  75544. * Should return WOLFSSL_SUCCESS
  75545. * codes should be 0
  75546. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  75547. */
  75548. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75549. ExpectIntEQ(codes, 0);
  75550. /* Test NULL dh: expected BAD_FUNC_ARG */
  75551. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  75552. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  75553. if (dh != NULL) {
  75554. pTmp = dh->p;
  75555. dh->p = NULL;
  75556. }
  75557. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75558. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75559. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75560. /* set dh->p back to normal so it won't fail on next tests */
  75561. if (dh != NULL) {
  75562. dh->p = pTmp;
  75563. pTmp = NULL;
  75564. }
  75565. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  75566. if (dh != NULL) {
  75567. gTmp = dh->g;
  75568. dh->g = NULL;
  75569. }
  75570. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75571. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75572. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  75573. if (dh != NULL) {
  75574. dh->g = gTmp;
  75575. gTmp = NULL;
  75576. }
  75577. /* Cleanup */
  75578. DH_free(dh);
  75579. dh = NULL;
  75580. dh = DH_new();
  75581. ExpectNotNull(dh);
  75582. /* Check empty DH. */
  75583. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75584. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75585. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  75586. /* Check non-prime valued p. */
  75587. ExpectNotNull(p = BN_new());
  75588. ExpectIntEQ(BN_set_word(p, 4), 1);
  75589. ExpectNotNull(g = BN_new());
  75590. ExpectIntEQ(BN_set_word(g, 2), 1);
  75591. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  75592. if (EXPECT_FAIL()) {
  75593. wolfSSL_BN_free(p);
  75594. wolfSSL_BN_free(g);
  75595. }
  75596. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75597. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75598. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75599. DH_free(dh);
  75600. dh = NULL;
  75601. #endif
  75602. #endif /* !NO_DH && !NO_DSA */
  75603. #endif
  75604. return EXPECT_RESULT();
  75605. }
  75606. static int test_wolfSSL_DH_prime(void)
  75607. {
  75608. EXPECT_DECLS;
  75609. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75610. WOLFSSL_BIGNUM* bn = NULL;
  75611. #if WOLFSSL_MAX_BN_BITS >= 768
  75612. WOLFSSL_BIGNUM* bn2 = NULL;
  75613. #endif
  75614. bn = wolfSSL_DH_768_prime(NULL);
  75615. #if WOLFSSL_MAX_BN_BITS >= 768
  75616. ExpectNotNull(bn);
  75617. bn2 = wolfSSL_DH_768_prime(bn);
  75618. ExpectNotNull(bn2);
  75619. ExpectTrue(bn == bn2);
  75620. wolfSSL_BN_free(bn);
  75621. bn = NULL;
  75622. #else
  75623. ExpectNull(bn);
  75624. #endif
  75625. bn = wolfSSL_DH_1024_prime(NULL);
  75626. #if WOLFSSL_MAX_BN_BITS >= 1024
  75627. ExpectNotNull(bn);
  75628. wolfSSL_BN_free(bn);
  75629. bn = NULL;
  75630. #else
  75631. ExpectNull(bn);
  75632. #endif
  75633. bn = wolfSSL_DH_2048_prime(NULL);
  75634. #if WOLFSSL_MAX_BN_BITS >= 2048
  75635. ExpectNotNull(bn);
  75636. wolfSSL_BN_free(bn);
  75637. bn = NULL;
  75638. #else
  75639. ExpectNull(bn);
  75640. #endif
  75641. bn = wolfSSL_DH_3072_prime(NULL);
  75642. #if WOLFSSL_MAX_BN_BITS >= 3072
  75643. ExpectNotNull(bn);
  75644. wolfSSL_BN_free(bn);
  75645. bn = NULL;
  75646. #else
  75647. ExpectNull(bn);
  75648. #endif
  75649. bn = wolfSSL_DH_4096_prime(NULL);
  75650. #if WOLFSSL_MAX_BN_BITS >= 4096
  75651. ExpectNotNull(bn);
  75652. wolfSSL_BN_free(bn);
  75653. bn = NULL;
  75654. #else
  75655. ExpectNull(bn);
  75656. #endif
  75657. bn = wolfSSL_DH_6144_prime(NULL);
  75658. #if WOLFSSL_MAX_BN_BITS >= 6144
  75659. ExpectNotNull(bn);
  75660. wolfSSL_BN_free(bn);
  75661. bn = NULL;
  75662. #else
  75663. ExpectNull(bn);
  75664. #endif
  75665. bn = wolfSSL_DH_8192_prime(NULL);
  75666. #if WOLFSSL_MAX_BN_BITS >= 8192
  75667. ExpectNotNull(bn);
  75668. wolfSSL_BN_free(bn);
  75669. bn = NULL;
  75670. #else
  75671. ExpectNull(bn);
  75672. #endif
  75673. #endif
  75674. return EXPECT_RESULT();
  75675. }
  75676. static int test_wolfSSL_DH_1536_prime(void)
  75677. {
  75678. EXPECT_DECLS;
  75679. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75680. BIGNUM* bn = NULL;
  75681. unsigned char bits[200];
  75682. int sz = 192; /* known binary size */
  75683. const byte expected[] = {
  75684. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75685. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  75686. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  75687. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  75688. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  75689. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  75690. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  75691. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  75692. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  75693. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  75694. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  75695. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  75696. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  75697. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  75698. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  75699. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  75700. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  75701. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  75702. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  75703. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  75704. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  75705. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  75706. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  75707. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75708. };
  75709. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  75710. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  75711. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  75712. BN_free(bn);
  75713. #endif
  75714. return EXPECT_RESULT();
  75715. }
  75716. static int test_wolfSSL_DH_get_2048_256(void)
  75717. {
  75718. EXPECT_DECLS;
  75719. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75720. WOLFSSL_DH* dh = NULL;
  75721. const WOLFSSL_BIGNUM* pBn;
  75722. const WOLFSSL_BIGNUM* gBn;
  75723. const WOLFSSL_BIGNUM* qBn;
  75724. const byte pExpected[] = {
  75725. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  75726. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  75727. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  75728. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  75729. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  75730. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  75731. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  75732. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  75733. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  75734. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  75735. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  75736. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  75737. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  75738. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  75739. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  75740. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  75741. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  75742. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  75743. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  75744. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  75745. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  75746. 0x1E, 0x1A, 0x15, 0x97
  75747. };
  75748. const byte gExpected[] = {
  75749. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  75750. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  75751. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  75752. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  75753. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  75754. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  75755. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  75756. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  75757. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  75758. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  75759. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  75760. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  75761. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  75762. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  75763. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  75764. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  75765. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  75766. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  75767. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  75768. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  75769. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  75770. 0x6C, 0xC4, 0x16, 0x59
  75771. };
  75772. const byte qExpected[] = {
  75773. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  75774. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  75775. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  75776. };
  75777. int pSz = 0;
  75778. int qSz = 0;
  75779. int gSz = 0;
  75780. byte* pReturned = NULL;
  75781. byte* qReturned = NULL;
  75782. byte* gReturned = NULL;
  75783. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  75784. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  75785. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  75786. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  75787. DYNAMIC_TYPE_TMP_BUFFER));
  75788. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  75789. ExpectIntEQ(pSz, sizeof(pExpected));
  75790. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  75791. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  75792. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  75793. DYNAMIC_TYPE_TMP_BUFFER));
  75794. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  75795. ExpectIntEQ(qSz, sizeof(qExpected));
  75796. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  75797. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  75798. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  75799. DYNAMIC_TYPE_TMP_BUFFER));
  75800. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  75801. ExpectIntEQ(gSz, sizeof(gExpected));
  75802. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  75803. wolfSSL_DH_free(dh);
  75804. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75805. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75806. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75807. #endif
  75808. return EXPECT_RESULT();
  75809. }
  75810. static int test_wolfSSL_PEM_write_DHparams(void)
  75811. {
  75812. EXPECT_DECLS;
  75813. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  75814. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  75815. DH* dh = NULL;
  75816. BIO* bio = NULL;
  75817. XFILE fp = XBADFILE;
  75818. byte pem[2048];
  75819. int pemSz = 0;
  75820. const char expected[] =
  75821. "-----BEGIN DH PARAMETERS-----\n"
  75822. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  75823. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  75824. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  75825. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  75826. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  75827. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  75828. "-----END DH PARAMETERS-----\n";
  75829. const char badPem[] =
  75830. "-----BEGIN DH PARAMETERS-----\n"
  75831. "-----END DH PARAMETERS-----\n";
  75832. const char emptySeqPem[] =
  75833. "-----BEGIN DH PARAMETERS-----\n"
  75834. "MAA=\n"
  75835. "-----END DH PARAMETERS-----\n";
  75836. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  75837. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75838. if (fp != XBADFILE) {
  75839. XFCLOSE(fp);
  75840. fp = XBADFILE;
  75841. }
  75842. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  75843. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75844. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75845. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  75846. (int)sizeof(badPem));
  75847. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75848. BIO_free(bio);
  75849. bio = NULL;
  75850. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75851. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75852. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  75853. (int)sizeof(emptySeqPem));
  75854. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75855. BIO_free(bio);
  75856. bio = NULL;
  75857. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75858. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  75859. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75860. BIO_free(bio);
  75861. bio = NULL;
  75862. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  75863. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  75864. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75865. DH_free(dh);
  75866. dh = NULL;
  75867. dh = wolfSSL_DH_new();
  75868. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75869. if (fp != XBADFILE) {
  75870. XFCLOSE(fp);
  75871. fp = XBADFILE;
  75872. }
  75873. wolfSSL_DH_free(dh);
  75874. dh = NULL;
  75875. /* check results */
  75876. XMEMSET(pem, 0, sizeof(pem));
  75877. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  75878. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75879. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  75880. if (fp != XBADFILE)
  75881. XFCLOSE(fp);
  75882. #endif
  75883. return EXPECT_RESULT();
  75884. }
  75885. static int test_wolfSSL_d2i_DHparams(void)
  75886. {
  75887. EXPECT_DECLS;
  75888. #ifdef OPENSSL_ALL
  75889. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75890. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75891. XFILE f = XBADFILE;
  75892. unsigned char buf[4096];
  75893. const unsigned char* pt = buf;
  75894. #ifdef HAVE_FFDHE_2048
  75895. const char* params1 = "./certs/dh2048.der";
  75896. #endif
  75897. #ifdef HAVE_FFDHE_3072
  75898. const char* params2 = "./certs/dh3072.der";
  75899. #endif
  75900. long len = 0;
  75901. WOLFSSL_DH* dh = NULL;
  75902. XMEMSET(buf, 0, sizeof(buf));
  75903. /* Test 2048 bit parameters */
  75904. #ifdef HAVE_FFDHE_2048
  75905. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75906. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75907. if (f != XBADFILE) {
  75908. XFCLOSE(f);
  75909. f = XBADFILE;
  75910. }
  75911. /* Valid case */
  75912. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75913. ExpectNotNull(dh->p);
  75914. ExpectNotNull(dh->g);
  75915. ExpectTrue(pt == buf);
  75916. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  75917. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  75918. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  75919. /* Invalid cases */
  75920. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75921. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75922. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  75923. DH_free(dh);
  75924. dh = NULL;
  75925. *buf = 0;
  75926. pt = buf;
  75927. #endif /* HAVE_FFDHE_2048 */
  75928. /* Test 3072 bit parameters */
  75929. #ifdef HAVE_FFDHE_3072
  75930. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75931. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75932. if (f != XBADFILE) {
  75933. XFCLOSE(f);
  75934. f = XBADFILE;
  75935. }
  75936. /* Valid case */
  75937. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  75938. ExpectNotNull(dh->p);
  75939. ExpectNotNull(dh->g);
  75940. ExpectTrue(pt != buf);
  75941. ExpectIntEQ(DH_generate_key(dh), 1);
  75942. /* Invalid cases */
  75943. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75944. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75945. DH_free(dh);
  75946. dh = NULL;
  75947. #endif /* HAVE_FFDHE_3072 */
  75948. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75949. #endif /* !NO_DH */
  75950. #endif
  75951. return EXPECT_RESULT();
  75952. }
  75953. static int test_wolfSSL_DH_LoadDer(void)
  75954. {
  75955. EXPECT_DECLS;
  75956. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  75957. defined(OPENSSL_EXTRA)
  75958. static const byte dh2048[] = {
  75959. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75960. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75961. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75962. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75963. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75964. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75965. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75966. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75967. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75968. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75969. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75970. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75971. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75972. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75973. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75974. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75975. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75976. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75977. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75978. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75979. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75980. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75981. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75982. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75983. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75984. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75985. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75986. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75987. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75988. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75989. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75990. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75991. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75992. 0x93, 0x02, 0x01, 0x02
  75993. };
  75994. WOLFSSL_DH* dh = NULL;
  75995. ExpectNotNull(dh = wolfSSL_DH_new());
  75996. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  75997. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  75998. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  75999. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  76000. wolfSSL_DH_free(dh);
  76001. #endif
  76002. return EXPECT_RESULT();
  76003. }
  76004. static int test_wolfSSL_i2d_DHparams(void)
  76005. {
  76006. EXPECT_DECLS;
  76007. #ifdef OPENSSL_ALL
  76008. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  76009. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76010. XFILE f = XBADFILE;
  76011. unsigned char buf[4096];
  76012. const unsigned char* pt;
  76013. unsigned char* pt2;
  76014. #ifdef HAVE_FFDHE_2048
  76015. const char* params1 = "./certs/dh2048.der";
  76016. #endif
  76017. #ifdef HAVE_FFDHE_3072
  76018. const char* params2 = "./certs/dh3072.der";
  76019. #endif
  76020. long len = 0;
  76021. WOLFSSL_DH* dh = NULL;
  76022. /* Test 2048 bit parameters */
  76023. #ifdef HAVE_FFDHE_2048
  76024. pt = buf;
  76025. pt2 = buf;
  76026. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  76027. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76028. if (f != XBADFILE) {
  76029. XFCLOSE(f);
  76030. f = XBADFILE;
  76031. }
  76032. /* Valid case */
  76033. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76034. ExpectTrue(pt == buf);
  76035. ExpectIntEQ(DH_generate_key(dh), 1);
  76036. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  76037. /* Invalid case */
  76038. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76039. /* Return length only */
  76040. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  76041. DH_free(dh);
  76042. dh = NULL;
  76043. *buf = 0;
  76044. #endif
  76045. /* Test 3072 bit parameters */
  76046. #ifdef HAVE_FFDHE_3072
  76047. pt = buf;
  76048. pt2 = buf;
  76049. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  76050. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76051. if (f != XBADFILE) {
  76052. XFCLOSE(f);
  76053. f = XBADFILE;
  76054. }
  76055. /* Valid case */
  76056. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76057. ExpectTrue(pt == buf);
  76058. ExpectIntEQ(DH_generate_key(dh), 1);
  76059. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  76060. /* Invalid case */
  76061. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76062. /* Return length only */
  76063. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  76064. DH_free(dh);
  76065. dh = NULL;
  76066. #endif
  76067. dh = DH_new();
  76068. ExpectNotNull(dh);
  76069. pt2 = buf;
  76070. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  76071. DH_free(dh);
  76072. dh = NULL;
  76073. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76074. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  76075. #endif
  76076. return EXPECT_RESULT();
  76077. }
  76078. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  76079. /*----------------------------------------------------------------------------*
  76080. | EC
  76081. *----------------------------------------------------------------------------*/
  76082. static int test_wolfSSL_EC_GROUP(void)
  76083. {
  76084. EXPECT_DECLS;
  76085. #ifdef OPENSSL_EXTRA
  76086. EC_GROUP *group = NULL;
  76087. EC_GROUP *group2 = NULL;
  76088. EC_GROUP *group3 = NULL;
  76089. #ifndef HAVE_ECC_BRAINPOOL
  76090. EC_GROUP *group4 = NULL;
  76091. #endif
  76092. WOLFSSL_BIGNUM* order = NULL;
  76093. int group_bits;
  76094. int i;
  76095. static const int knownEccNids[] = {
  76096. NID_X9_62_prime192v1,
  76097. NID_X9_62_prime192v2,
  76098. NID_X9_62_prime192v3,
  76099. NID_X9_62_prime239v1,
  76100. NID_X9_62_prime239v2,
  76101. NID_X9_62_prime239v3,
  76102. NID_X9_62_prime256v1,
  76103. NID_secp112r1,
  76104. NID_secp112r2,
  76105. NID_secp128r1,
  76106. NID_secp128r2,
  76107. NID_secp160r1,
  76108. NID_secp160r2,
  76109. NID_secp224r1,
  76110. NID_secp384r1,
  76111. NID_secp521r1,
  76112. NID_secp160k1,
  76113. NID_secp192k1,
  76114. NID_secp224k1,
  76115. NID_secp256k1,
  76116. NID_brainpoolP160r1,
  76117. NID_brainpoolP192r1,
  76118. NID_brainpoolP224r1,
  76119. NID_brainpoolP256r1,
  76120. NID_brainpoolP320r1,
  76121. NID_brainpoolP384r1,
  76122. NID_brainpoolP512r1,
  76123. };
  76124. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  76125. static const int knownEccEnums[] = {
  76126. ECC_SECP192R1,
  76127. ECC_PRIME192V2,
  76128. ECC_PRIME192V3,
  76129. ECC_PRIME239V1,
  76130. ECC_PRIME239V2,
  76131. ECC_PRIME239V3,
  76132. ECC_SECP256R1,
  76133. ECC_SECP112R1,
  76134. ECC_SECP112R2,
  76135. ECC_SECP128R1,
  76136. ECC_SECP128R2,
  76137. ECC_SECP160R1,
  76138. ECC_SECP160R2,
  76139. ECC_SECP224R1,
  76140. ECC_SECP384R1,
  76141. ECC_SECP521R1,
  76142. ECC_SECP160K1,
  76143. ECC_SECP192K1,
  76144. ECC_SECP224K1,
  76145. ECC_SECP256K1,
  76146. ECC_BRAINPOOLP160R1,
  76147. ECC_BRAINPOOLP192R1,
  76148. ECC_BRAINPOOLP224R1,
  76149. ECC_BRAINPOOLP256R1,
  76150. ECC_BRAINPOOLP320R1,
  76151. ECC_BRAINPOOLP384R1,
  76152. ECC_BRAINPOOLP512R1,
  76153. };
  76154. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  76155. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76156. ExpectNotNull(group2 = EC_GROUP_dup(group));
  76157. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  76158. #ifndef HAVE_ECC_BRAINPOOL
  76159. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  76160. NID_brainpoolP256r1));
  76161. #endif
  76162. ExpectNull(EC_GROUP_dup(NULL));
  76163. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  76164. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  76165. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  76166. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  76167. #ifndef HAVE_ECC_BRAINPOOL
  76168. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  76169. #endif
  76170. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  76171. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  76172. ExpectNotNull(order = BN_new());
  76173. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  76174. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  76175. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  76176. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  76177. wolfSSL_BN_free(order);
  76178. ExpectNotNull(EC_GROUP_method_of(group));
  76179. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  76180. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  76181. NID_X9_62_prime_field);
  76182. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  76183. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  76184. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  76185. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  76186. #ifndef NO_WOLFSSL_STUB
  76187. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  76188. #endif
  76189. #ifndef HAVE_ECC_BRAINPOOL
  76190. EC_GROUP_free(group4);
  76191. #endif
  76192. EC_GROUP_free(group3);
  76193. EC_GROUP_free(group2);
  76194. EC_GROUP_free(group);
  76195. for (i = 0; i < knowEccNidsLen; i++) {
  76196. group = NULL;
  76197. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  76198. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  76199. EC_GROUP_free(group);
  76200. }
  76201. for (i = 0; i < knowEccEnumsLen; i++) {
  76202. group = NULL;
  76203. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  76204. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  76205. EC_GROUP_free(group);
  76206. }
  76207. #endif
  76208. return EXPECT_RESULT();
  76209. }
  76210. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  76211. {
  76212. EXPECT_DECLS;
  76213. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76214. EC_GROUP *group = NULL;
  76215. BIO* bio = NULL;
  76216. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  76217. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  76218. EC_GROUP *ret = NULL;
  76219. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  76220. "BgUrgQQAIg==\n"
  76221. "-----END EC PARAMETERS-----";
  76222. #endif
  76223. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  76224. "MAA=\n"
  76225. "-----END EC PARAMETERS-----";
  76226. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  76227. "BgA=\n"
  76228. "-----END EC PARAMETERS-----";
  76229. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  76230. "BgE=\n"
  76231. "-----END EC PARAMETERS-----";
  76232. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  76233. "BgE*\n"
  76234. "-----END EC PARAMETERS-----";
  76235. /* Test that first parameter, bio, being NULL fails. */
  76236. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  76237. /* Test that reading named parameters works. */
  76238. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  76239. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  76240. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76241. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  76242. BIO_free(bio);
  76243. bio = NULL;
  76244. EC_GROUP_free(group);
  76245. group = NULL;
  76246. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  76247. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  76248. /* Test that reusing group works. */
  76249. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  76250. sizeof(ec_nc_p384)));
  76251. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  76252. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  76253. BIO_free(bio);
  76254. bio = NULL;
  76255. EC_GROUP_free(group);
  76256. group = NULL;
  76257. /* Test that returning through group works. */
  76258. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  76259. sizeof(ec_nc_p384)));
  76260. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  76261. ExpectIntEQ(group == ret, 1);
  76262. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  76263. BIO_free(bio);
  76264. bio = NULL;
  76265. EC_GROUP_free(group);
  76266. group = NULL;
  76267. #endif
  76268. /* Test 0x30, 0x00 (not and object id) fails. */
  76269. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  76270. sizeof(ec_nc_bad_1)));
  76271. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76272. BIO_free(bio);
  76273. bio = NULL;
  76274. /* Test 0x06, 0x00 (empty object id) fails. */
  76275. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  76276. sizeof(ec_nc_bad_2)));
  76277. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76278. BIO_free(bio);
  76279. bio = NULL;
  76280. /* Test 0x06, 0x01 (badly formed object id) fails. */
  76281. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  76282. sizeof(ec_nc_bad_3)));
  76283. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76284. BIO_free(bio);
  76285. bio = NULL;
  76286. /* Test invalid PEM encoding - invalid character. */
  76287. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  76288. sizeof(ec_nc_bad_4)));
  76289. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76290. BIO_free(bio);
  76291. #endif
  76292. return EXPECT_RESULT();
  76293. }
  76294. static int test_wolfSSL_EC_POINT(void)
  76295. {
  76296. EXPECT_DECLS;
  76297. #if !defined(WOLFSSL_SP_MATH) && \
  76298. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  76299. #ifdef OPENSSL_EXTRA
  76300. BN_CTX* ctx = NULL;
  76301. EC_GROUP* group = NULL;
  76302. #ifndef HAVE_ECC_BRAINPOOL
  76303. EC_GROUP* group2 = NULL;
  76304. #endif
  76305. EC_POINT* Gxy = NULL;
  76306. EC_POINT* new_point = NULL;
  76307. EC_POINT* set_point = NULL;
  76308. EC_POINT* get_point = NULL;
  76309. EC_POINT* infinity = NULL;
  76310. BIGNUM* k = NULL;
  76311. BIGNUM* Gx = NULL;
  76312. BIGNUM* Gy = NULL;
  76313. BIGNUM* Gz = NULL;
  76314. BIGNUM* X = NULL;
  76315. BIGNUM* Y = NULL;
  76316. BIGNUM* set_point_bn = NULL;
  76317. char* hexStr = NULL;
  76318. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  76319. "17AF381913FF7A96314EA47055EA0FD0";
  76320. /* NISTP256R1 Gx/Gy */
  76321. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  76322. "77037D812DEB33A0F4A13945D898C296";
  76323. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76324. "2BCE33576B315ECECBB6406837BF51F5";
  76325. const char* uncompG
  76326. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  76327. "77037D812DEB33A0F4A13945D898C296"
  76328. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76329. "2BCE33576B315ECECBB6406837BF51F5";
  76330. const char* compG
  76331. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  76332. "77037D812DEB33A0F4A13945D898C296";
  76333. #ifndef HAVE_SELFTEST
  76334. EC_POINT *tmp = NULL;
  76335. size_t bin_len;
  76336. unsigned int blen = 0;
  76337. unsigned char* buf = NULL;
  76338. unsigned char bufInf[1] = { 0x00 };
  76339. const unsigned char binUncompG[] = {
  76340. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76341. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76342. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76343. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76344. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76345. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76346. };
  76347. const unsigned char binUncompGBad[] = {
  76348. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76349. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76350. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76351. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76352. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76353. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76354. };
  76355. #ifdef HAVE_COMP_KEY
  76356. const unsigned char binCompG[] = {
  76357. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76358. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76359. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76360. };
  76361. #endif
  76362. #endif
  76363. ExpectNotNull(ctx = BN_CTX_new());
  76364. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76365. #ifndef HAVE_ECC_BRAINPOOL
  76366. /* Used to make groups curve_idx == -1. */
  76367. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  76368. #endif
  76369. ExpectNull(EC_POINT_new(NULL));
  76370. ExpectNotNull(Gxy = EC_POINT_new(group));
  76371. ExpectNotNull(new_point = EC_POINT_new(group));
  76372. ExpectNotNull(set_point = EC_POINT_new(group));
  76373. ExpectNotNull(X = BN_new());
  76374. ExpectNotNull(Y = BN_new());
  76375. ExpectNotNull(set_point_bn = BN_new());
  76376. ExpectNotNull(infinity = EC_POINT_new(group));
  76377. /* load test values */
  76378. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  76379. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  76380. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  76381. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  76382. /* populate coordinates for input point */
  76383. if (Gxy != NULL) {
  76384. Gxy->X = Gx;
  76385. Gxy->Y = Gy;
  76386. Gxy->Z = Gz;
  76387. }
  76388. /* Test handling of NULL point. */
  76389. EC_POINT_clear_free(NULL);
  76390. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76391. NULL, NULL, ctx), 0);
  76392. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76393. NULL, NULL, ctx), 0);
  76394. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76395. NULL, NULL, ctx), 0);
  76396. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76397. X, NULL, ctx), 0);
  76398. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76399. NULL, Y, ctx), 0);
  76400. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76401. X, Y, ctx), 0);
  76402. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76403. X, Y, ctx), 0);
  76404. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76405. NULL, Y, ctx), 0);
  76406. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76407. X, NULL, ctx), 0);
  76408. /* Getting point at infinity returns an error. */
  76409. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  76410. X, Y, ctx), 0);
  76411. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76412. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76413. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76414. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  76415. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  76416. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  76417. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  76418. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  76419. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  76420. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  76421. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  76422. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  76423. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  76424. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  76425. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  76426. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  76427. /* perform point multiplication */
  76428. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  76429. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76430. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76431. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76432. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), 1);
  76433. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76434. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76435. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76436. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), 1);
  76437. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76438. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76439. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76440. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, NULL, NULL, ctx), 1);
  76441. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  76442. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  76443. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76444. /* Set point to something. */
  76445. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  76446. #else
  76447. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  76448. ctx), 1);
  76449. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76450. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76451. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76452. #endif
  76453. /* check if point X coordinate is zero */
  76454. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76455. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  76456. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  76457. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  76458. #endif
  76459. /* extract the coordinates from point */
  76460. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76461. ctx), WOLFSSL_SUCCESS);
  76462. /* check if point X coordinate is zero */
  76463. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76464. /* set the same X and Y points in another object */
  76465. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  76466. ctx), WOLFSSL_SUCCESS);
  76467. /* compare points as they should be the same */
  76468. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  76469. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  76470. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  76471. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  76472. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  76473. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  76474. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  76475. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  76476. /* Test copying */
  76477. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  76478. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  76479. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  76480. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  76481. /* Test inverting */
  76482. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  76483. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  76484. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  76485. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  76486. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76487. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76488. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76489. {
  76490. EC_POINT* orig_point = NULL;
  76491. ExpectNotNull(orig_point = EC_POINT_new(group));
  76492. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  76493. 1);
  76494. /* new_point should be set_point inverted so adding it will revert
  76495. * the point back to set_point */
  76496. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  76497. NULL), 1);
  76498. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  76499. EC_POINT_free(orig_point);
  76500. }
  76501. #endif
  76502. /* Test getting affine converts from projective. */
  76503. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  76504. /* Force non-affine coordinates */
  76505. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76506. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  76507. if (new_point != NULL) {
  76508. new_point->inSet = 0;
  76509. }
  76510. /* extract the coordinates from point */
  76511. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76512. ctx), WOLFSSL_SUCCESS);
  76513. /* check if point ordinates have changed. */
  76514. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  76515. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  76516. /* Test check for infinity */
  76517. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  76518. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  76519. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  76520. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  76521. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  76522. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  76523. #else
  76524. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  76525. #endif
  76526. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  76527. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  76528. /* check bn2hex */
  76529. hexStr = BN_bn2hex(k);
  76530. ExpectStrEQ(hexStr, kTest);
  76531. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76532. defined(XFPRINTF)
  76533. BN_print_fp(stderr, k);
  76534. fprintf(stderr, "\n");
  76535. #endif
  76536. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76537. hexStr = BN_bn2hex(Gx);
  76538. ExpectStrEQ(hexStr, kGx);
  76539. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76540. defined(XFPRINTF)
  76541. BN_print_fp(stderr, Gx);
  76542. fprintf(stderr, "\n");
  76543. #endif
  76544. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76545. hexStr = BN_bn2hex(Gy);
  76546. ExpectStrEQ(hexStr, kGy);
  76547. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76548. defined(XFPRINTF)
  76549. BN_print_fp(stderr, Gy);
  76550. fprintf(stderr, "\n");
  76551. #endif
  76552. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76553. /* Test point to hex */
  76554. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76555. ctx));
  76556. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76557. ctx));
  76558. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76559. ctx));
  76560. #ifndef HAVE_ECC_BRAINPOOL
  76561. /* Group not supported in wolfCrypt. */
  76562. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76563. ctx));
  76564. #endif
  76565. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  76566. ExpectNotNull(hexStr);
  76567. ExpectStrEQ(hexStr, uncompG);
  76568. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  76569. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76570. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76571. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  76572. ExpectNotNull(hexStr);
  76573. ExpectStrEQ(hexStr, compG);
  76574. #ifdef HAVE_COMP_KEY
  76575. ExpectNotNull(get_point = EC_POINT_hex2point
  76576. (group, hexStr, get_point, ctx));
  76577. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76578. #endif
  76579. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76580. EC_POINT_free(get_point);
  76581. #ifndef HAVE_SELFTEST
  76582. /* Test point to oct */
  76583. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76584. NULL, 0, ctx), 0);
  76585. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76586. NULL, 0, ctx), 0);
  76587. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76588. NULL, 0, ctx), 0);
  76589. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76590. NULL, 0, ctx);
  76591. ExpectIntEQ(bin_len, sizeof(binUncompG));
  76592. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76593. DYNAMIC_TYPE_ECC));
  76594. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76595. buf, bin_len, ctx), bin_len);
  76596. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76597. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76598. /* Infinity (x=0, y=0) encodes as '0x00'. */
  76599. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76600. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  76601. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76602. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  76603. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76604. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  76605. ExpectIntEQ(bufInf[0], 0);
  76606. wolfSSL_EC_POINT_dump(NULL, NULL);
  76607. /* Test point i2d */
  76608. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  76609. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  76610. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  76611. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  76612. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  76613. ExpectIntEQ(blen, sizeof(binUncompG));
  76614. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  76615. blen -= 1;
  76616. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  76617. blen += 1;
  76618. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  76619. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76620. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76621. #ifdef HAVE_COMP_KEY
  76622. /* Test point to oct compressed */
  76623. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  76624. 0, ctx);
  76625. ExpectIntEQ(bin_len, sizeof(binCompG));
  76626. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76627. DYNAMIC_TYPE_ECC));
  76628. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  76629. bin_len, ctx), bin_len);
  76630. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  76631. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76632. #endif
  76633. /* Test point BN */
  76634. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  76635. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76636. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  76637. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76638. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  76639. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76640. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  76641. /* Test oct to point */
  76642. ExpectNotNull(tmp = EC_POINT_new(group));
  76643. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  76644. ctx), 0);
  76645. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  76646. ctx), 0);
  76647. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  76648. ctx), 0);
  76649. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  76650. sizeof(binUncompGBad), ctx), 0);
  76651. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  76652. ctx), 1);
  76653. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76654. EC_POINT_free(tmp);
  76655. tmp = NULL;
  76656. /* Test setting BN ordinates. */
  76657. ExpectNotNull(tmp = EC_POINT_new(group));
  76658. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76659. NULL, ctx), 0);
  76660. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  76661. NULL, ctx), 0);
  76662. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  76663. NULL, ctx), 0);
  76664. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  76665. NULL, ctx), 0);
  76666. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76667. Gy, ctx), 0);
  76668. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  76669. ctx), 0);
  76670. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  76671. ctx), 0);
  76672. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  76673. Gy, ctx), 0);
  76674. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  76675. NULL, ctx), 0);
  76676. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  76677. ctx), 1);
  76678. EC_POINT_free(tmp);
  76679. tmp = NULL;
  76680. /* Test point d2i */
  76681. ExpectNotNull(tmp = EC_POINT_new(group));
  76682. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  76683. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  76684. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  76685. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  76686. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  76687. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  76688. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  76689. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  76690. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  76691. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76692. EC_POINT_free(tmp);
  76693. tmp = NULL;
  76694. #ifdef HAVE_COMP_KEY
  76695. /* Test oct compressed to point */
  76696. ExpectNotNull(tmp = EC_POINT_new(group));
  76697. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  76698. 1);
  76699. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76700. EC_POINT_free(tmp);
  76701. tmp = NULL;
  76702. /* Test point d2i - compressed */
  76703. ExpectNotNull(tmp = EC_POINT_new(group));
  76704. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  76705. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76706. EC_POINT_free(tmp);
  76707. tmp = NULL;
  76708. #endif
  76709. #endif
  76710. /* test BN_mod_add */
  76711. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76712. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  76713. 1);
  76714. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76715. /* cleanup */
  76716. BN_free(X);
  76717. BN_free(Y);
  76718. BN_free(k);
  76719. BN_free(set_point_bn);
  76720. EC_POINT_free(infinity);
  76721. EC_POINT_free(new_point);
  76722. EC_POINT_free(set_point);
  76723. EC_POINT_clear_free(Gxy);
  76724. #ifndef HAVE_ECC_BRAINPOOL
  76725. EC_GROUP_free(group2);
  76726. #endif
  76727. EC_GROUP_free(group);
  76728. BN_CTX_free(ctx);
  76729. #endif
  76730. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  76731. return EXPECT_RESULT();
  76732. }
  76733. static int test_wolfSSL_SPAKE(void)
  76734. {
  76735. EXPECT_DECLS;
  76736. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  76737. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  76738. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76739. BIGNUM* x = NULL; /* kdc priv */
  76740. BIGNUM* y = NULL; /* client priv */
  76741. BIGNUM* w = NULL; /* shared value */
  76742. byte M_bytes[] = {
  76743. /* uncompressed */
  76744. 0x04,
  76745. /* x */
  76746. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  76747. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  76748. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  76749. /* y */
  76750. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  76751. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  76752. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  76753. };
  76754. EC_POINT* M = NULL; /* shared value */
  76755. byte N_bytes[] = {
  76756. /* uncompressed */
  76757. 0x04,
  76758. /* x */
  76759. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  76760. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  76761. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  76762. /* y */
  76763. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  76764. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  76765. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  76766. };
  76767. EC_POINT* N = NULL; /* shared value */
  76768. EC_POINT* T = NULL; /* kdc pub */
  76769. EC_POINT* tmp1 = NULL; /* kdc pub */
  76770. EC_POINT* tmp2 = NULL; /* kdc pub */
  76771. EC_POINT* S = NULL; /* client pub */
  76772. EC_POINT* client_secret = NULL;
  76773. EC_POINT* kdc_secret = NULL;
  76774. EC_GROUP* group = NULL;
  76775. BN_CTX* bn_ctx = NULL;
  76776. /* Values taken from a test run of Kerberos 5 */
  76777. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76778. ExpectNotNull(bn_ctx = BN_CTX_new());
  76779. ExpectNotNull(M = EC_POINT_new(group));
  76780. ExpectNotNull(N = EC_POINT_new(group));
  76781. ExpectNotNull(T = EC_POINT_new(group));
  76782. ExpectNotNull(tmp1 = EC_POINT_new(group));
  76783. ExpectNotNull(tmp2 = EC_POINT_new(group));
  76784. ExpectNotNull(S = EC_POINT_new(group));
  76785. ExpectNotNull(client_secret = EC_POINT_new(group));
  76786. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  76787. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  76788. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  76789. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  76790. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  76791. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  76792. "506AB395478F0AAB647752CF117B36250"), 1);
  76793. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  76794. 1);
  76795. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  76796. 1);
  76797. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  76798. /* kdc */
  76799. /* T=x*P+w*M */
  76800. /* All in one function call */
  76801. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  76802. /* Spread into separate calls */
  76803. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  76804. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  76805. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76806. 1);
  76807. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  76808. /* client */
  76809. /* S=y*P+w*N */
  76810. /* All in one function call */
  76811. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  76812. /* Spread into separate calls */
  76813. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  76814. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  76815. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76816. 1);
  76817. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  76818. /* K=y*(T-w*M) */
  76819. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  76820. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  76821. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  76822. 1);
  76823. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  76824. bn_ctx), 1);
  76825. /* kdc */
  76826. /* K=x*(S-w*N) */
  76827. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  76828. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  76829. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  76830. 1);
  76831. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  76832. 1);
  76833. /* kdc_secret == client_secret */
  76834. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  76835. BN_free(x);
  76836. BN_free(y);
  76837. BN_free(w);
  76838. EC_POINT_free(M);
  76839. EC_POINT_free(N);
  76840. EC_POINT_free(T);
  76841. EC_POINT_free(tmp1);
  76842. EC_POINT_free(tmp2);
  76843. EC_POINT_free(S);
  76844. EC_POINT_free(client_secret);
  76845. EC_POINT_free(kdc_secret);
  76846. EC_GROUP_free(group);
  76847. BN_CTX_free(bn_ctx);
  76848. #endif
  76849. return EXPECT_RESULT();
  76850. }
  76851. static int test_wolfSSL_EC_KEY_generate(void)
  76852. {
  76853. EXPECT_DECLS;
  76854. #ifdef OPENSSL_EXTRA
  76855. WOLFSSL_EC_KEY* key = NULL;
  76856. #ifndef HAVE_ECC_BRAINPOOL
  76857. WOLFSSL_EC_GROUP* group = NULL;
  76858. #endif
  76859. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76860. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  76861. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76862. wolfSSL_EC_KEY_free(key);
  76863. key = NULL;
  76864. #ifndef HAVE_ECC_BRAINPOOL
  76865. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  76866. NID_brainpoolP256r1));
  76867. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  76868. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  76869. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  76870. wolfSSL_EC_KEY_free(key);
  76871. wolfSSL_EC_GROUP_free(group);
  76872. #endif
  76873. #endif
  76874. return EXPECT_RESULT();
  76875. }
  76876. static int test_EC_i2d(void)
  76877. {
  76878. EXPECT_DECLS;
  76879. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  76880. EC_KEY *key = NULL;
  76881. EC_KEY *copy = NULL;
  76882. int len = 0;
  76883. unsigned char *buf = NULL;
  76884. unsigned char *p = NULL;
  76885. const unsigned char *tmp = NULL;
  76886. const unsigned char octBad[] = {
  76887. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76888. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76889. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76890. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76891. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76892. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76893. };
  76894. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76895. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  76896. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  76897. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76898. DYNAMIC_TYPE_TMP_BUFFER));
  76899. p = buf;
  76900. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  76901. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  76902. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  76903. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  76904. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76905. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  76906. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  76907. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  76908. tmp = buf;
  76909. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  76910. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  76911. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76912. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  76913. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  76914. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  76915. tmp = buf;
  76916. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  76917. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  76918. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  76919. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  76920. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  76921. {
  76922. EC_KEY *pubkey = NULL;
  76923. BIO* bio = NULL;
  76924. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76925. ExpectIntGT(BIO_write(bio, buf, len), 0);
  76926. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  76927. BIO_free(bio);
  76928. EC_KEY_free(pubkey);
  76929. }
  76930. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  76931. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  76932. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  76933. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  76934. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  76935. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  76936. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  76937. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  76938. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76939. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  76940. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76941. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  76942. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76943. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  76944. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76945. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  76946. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  76947. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76948. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76949. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76950. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76951. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76952. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76953. buf = NULL;
  76954. buf = NULL;
  76955. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  76956. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76957. DYNAMIC_TYPE_TMP_BUFFER));
  76958. p = buf;
  76959. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76960. p = NULL;
  76961. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76962. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76963. p = NULL;
  76964. /* Bad point is also an invalid private key. */
  76965. tmp = octBad;
  76966. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  76967. tmp = buf;
  76968. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  76969. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76970. buf = NULL;
  76971. buf = NULL;
  76972. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  76973. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76974. DYNAMIC_TYPE_TMP_BUFFER));
  76975. p = buf;
  76976. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76977. p = NULL;
  76978. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76979. tmp = buf;
  76980. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  76981. tmp = octBad;
  76982. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  76983. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  76984. ExpectIntEQ(EC_KEY_check_key(key), 1);
  76985. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  76986. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  76987. EC_KEY_free(key);
  76988. EC_KEY_free(copy);
  76989. #endif
  76990. return EXPECT_RESULT();
  76991. }
  76992. static int test_wolfSSL_EC_curve(void)
  76993. {
  76994. EXPECT_DECLS;
  76995. #if defined(OPENSSL_EXTRA)
  76996. int nid = NID_secp160k1;
  76997. const char* nid_name = NULL;
  76998. ExpectNull(EC_curve_nid2nist(NID_sha256));
  76999. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  77000. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  77001. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  77002. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  77003. #endif
  77004. return EXPECT_RESULT();
  77005. }
  77006. static int test_wolfSSL_EC_KEY_dup(void)
  77007. {
  77008. EXPECT_DECLS;
  77009. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  77010. WOLFSSL_EC_KEY* ecKey = NULL;
  77011. WOLFSSL_EC_KEY* dupKey = NULL;
  77012. ecc_key* srcKey = NULL;
  77013. ecc_key* destKey = NULL;
  77014. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77015. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77016. /* Valid cases */
  77017. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77018. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  77019. /* Compare pubkey */
  77020. if (ecKey != NULL) {
  77021. srcKey = (ecc_key*)ecKey->internal;
  77022. }
  77023. if (dupKey != NULL) {
  77024. destKey = (ecc_key*)dupKey->internal;
  77025. }
  77026. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  77027. /* compare EC_GROUP */
  77028. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  77029. /* compare EC_POINT */
  77030. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  77031. dupKey->pub_key, NULL), MP_EQ);
  77032. /* compare BIGNUM */
  77033. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  77034. wolfSSL_EC_KEY_free(dupKey);
  77035. dupKey = NULL;
  77036. /* Invalid cases */
  77037. /* NULL key */
  77038. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  77039. /* NULL ecc_key */
  77040. if (ecKey != NULL) {
  77041. wc_ecc_free((ecc_key*)ecKey->internal);
  77042. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  77043. ecKey->internal = NULL; /* Set ecc_key to NULL */
  77044. }
  77045. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77046. wolfSSL_EC_KEY_free(ecKey);
  77047. ecKey = NULL;
  77048. wolfSSL_EC_KEY_free(dupKey);
  77049. dupKey = NULL;
  77050. /* NULL Group */
  77051. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77052. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77053. if (ecKey != NULL) {
  77054. wolfSSL_EC_GROUP_free(ecKey->group);
  77055. ecKey->group = NULL; /* Set group to NULL */
  77056. }
  77057. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77058. wolfSSL_EC_KEY_free(ecKey);
  77059. ecKey = NULL;
  77060. wolfSSL_EC_KEY_free(dupKey);
  77061. dupKey = NULL;
  77062. /* NULL public key */
  77063. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77064. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77065. if (ecKey != NULL) {
  77066. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  77067. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  77068. }
  77069. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77070. if (ecKey != NULL) {
  77071. wolfSSL_EC_POINT_free(ecKey->pub_key);
  77072. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  77073. }
  77074. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77075. wolfSSL_EC_KEY_free(ecKey);
  77076. ecKey = NULL;
  77077. wolfSSL_EC_KEY_free(dupKey);
  77078. dupKey = NULL;
  77079. /* NULL private key */
  77080. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77081. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77082. if (ecKey != NULL) {
  77083. wolfSSL_BN_free(ecKey->priv_key);
  77084. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  77085. }
  77086. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77087. wolfSSL_EC_KEY_free(ecKey);
  77088. ecKey = NULL;
  77089. wolfSSL_EC_KEY_free(dupKey);
  77090. dupKey = NULL;
  77091. /* Test EC_KEY_up_ref */
  77092. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77093. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  77094. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77095. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  77096. /* reference count doesn't follow duplicate */
  77097. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77098. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  77099. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  77100. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  77101. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  77102. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  77103. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  77104. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  77105. #endif
  77106. return EXPECT_RESULT();
  77107. }
  77108. static int test_wolfSSL_EC_KEY_set_group(void)
  77109. {
  77110. EXPECT_DECLS;
  77111. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77112. defined(OPENSSL_EXTRA)
  77113. EC_KEY *key = NULL;
  77114. EC_GROUP *group = NULL;
  77115. const EC_GROUP *group2 = NULL;
  77116. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77117. ExpectNotNull(key = EC_KEY_new());
  77118. ExpectNull(EC_KEY_get0_group(NULL));
  77119. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  77120. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  77121. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  77122. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  77123. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  77124. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  77125. EC_GROUP_free(group);
  77126. EC_KEY_free(key);
  77127. #endif
  77128. return EXPECT_RESULT();
  77129. }
  77130. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  77131. {
  77132. EXPECT_DECLS;
  77133. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77134. BIO* bio = NULL;
  77135. EC_KEY* key = NULL;
  77136. /* Error condition: NULL key. */
  77137. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  77138. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  77139. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  77140. /* Conversion form defaults to uncompressed. */
  77141. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77142. #ifdef HAVE_COMP_KEY
  77143. /* Explicitly set to compressed. */
  77144. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77145. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  77146. #else
  77147. /* Will still work just won't change anything. */
  77148. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77149. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77150. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  77151. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77152. #endif
  77153. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  77154. BIO_free(bio);
  77155. EC_KEY_free(key);
  77156. #endif
  77157. return EXPECT_RESULT();
  77158. }
  77159. static int test_wolfSSL_EC_KEY_private_key(void)
  77160. {
  77161. EXPECT_DECLS;
  77162. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77163. WOLFSSL_EC_KEY* key = NULL;
  77164. WOLFSSL_BIGNUM* priv = NULL;
  77165. WOLFSSL_BIGNUM* priv2 = NULL;
  77166. WOLFSSL_BIGNUM* bn;
  77167. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77168. ExpectNotNull(priv = wolfSSL_BN_new());
  77169. ExpectNotNull(priv2 = wolfSSL_BN_new());
  77170. ExpectIntNE(BN_set_word(priv, 2), 0);
  77171. ExpectIntNE(BN_set_word(priv2, 2), 0);
  77172. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  77173. /* No private key set. */
  77174. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  77175. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  77176. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  77177. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  77178. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  77179. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77180. ExpectPtrNE(bn, priv);
  77181. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  77182. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77183. ExpectPtrNE(bn, priv2);
  77184. wolfSSL_BN_free(priv2);
  77185. wolfSSL_BN_free(priv);
  77186. wolfSSL_EC_KEY_free(key);
  77187. #endif
  77188. return EXPECT_RESULT();
  77189. }
  77190. static int test_wolfSSL_EC_KEY_public_key(void)
  77191. {
  77192. EXPECT_DECLS;
  77193. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77194. WOLFSSL_EC_KEY* key = NULL;
  77195. WOLFSSL_EC_POINT* pub = NULL;
  77196. WOLFSSL_EC_POINT* point = NULL;
  77197. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77198. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  77199. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  77200. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  77201. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  77202. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  77203. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  77204. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  77205. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  77206. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  77207. ExpectPtrEq(point, pub);
  77208. wolfSSL_EC_KEY_free(key);
  77209. #endif
  77210. return EXPECT_RESULT();
  77211. }
  77212. static int test_wolfSSL_EC_KEY_print_fp(void)
  77213. {
  77214. EXPECT_DECLS;
  77215. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  77216. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  77217. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  77218. !defined(NO_STDIO_FILESYSTEM)
  77219. EC_KEY* key = NULL;
  77220. /* Bad file pointer. */
  77221. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77222. /* NULL key. */
  77223. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77224. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  77225. /* Negative indent. */
  77226. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77227. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77228. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  77229. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77230. wolfSSL_EC_KEY_free(key);
  77231. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  77232. NID_X9_62_prime256v1)));
  77233. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  77234. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77235. wolfSSL_EC_KEY_free(key);
  77236. #endif
  77237. return EXPECT_RESULT();
  77238. }
  77239. static int test_wolfSSL_EC_get_builtin_curves(void)
  77240. {
  77241. EXPECT_DECLS;
  77242. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  77243. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  77244. EC_builtin_curve* curves = NULL;
  77245. size_t crv_len = 0;
  77246. size_t i = 0;
  77247. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  77248. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  77249. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  77250. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  77251. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  77252. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  77253. if (curves[i].comment != NULL) {
  77254. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  77255. }
  77256. }
  77257. if (crv_len > 1) {
  77258. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  77259. }
  77260. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77261. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  77262. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  77263. return EXPECT_RESULT();
  77264. }
  77265. static int test_wolfSSL_ECDSA_SIG(void)
  77266. {
  77267. EXPECT_DECLS;
  77268. #ifdef OPENSSL_EXTRA
  77269. WOLFSSL_ECDSA_SIG* sig = NULL;
  77270. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  77271. WOLFSSL_BIGNUM* r = NULL;
  77272. WOLFSSL_BIGNUM* s = NULL;
  77273. const WOLFSSL_BIGNUM* r2 = NULL;
  77274. const WOLFSSL_BIGNUM* s2 = NULL;
  77275. const unsigned char* cp = NULL;
  77276. unsigned char* p = NULL;
  77277. unsigned char outSig[8];
  77278. unsigned char sigData[8] =
  77279. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77280. unsigned char sigDataBad[8] =
  77281. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77282. wolfSSL_ECDSA_SIG_free(NULL);
  77283. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  77284. ExpectNotNull(r = wolfSSL_BN_new());
  77285. ExpectNotNull(s = wolfSSL_BN_new());
  77286. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  77287. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  77288. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  77289. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  77290. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  77291. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77292. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  77293. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  77294. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  77295. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  77296. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  77297. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  77298. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  77299. r2 = NULL;
  77300. s2 = NULL;
  77301. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77302. ExpectNull(r2);
  77303. ExpectNull(s2);
  77304. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  77305. if (EXPECT_FAIL()) {
  77306. wolfSSL_BN_free(r);
  77307. wolfSSL_BN_free(s);
  77308. }
  77309. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  77310. ExpectPtrEq(r2, r);
  77311. ExpectPtrEq(s2, s);
  77312. r2 = NULL;
  77313. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  77314. ExpectPtrEq(r2, r);
  77315. s2 = NULL;
  77316. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  77317. ExpectPtrEq(s2, s);
  77318. /* r and s are freed when sig is freed. */
  77319. wolfSSL_ECDSA_SIG_free(sig);
  77320. sig = NULL;
  77321. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  77322. cp = sigDataBad;
  77323. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  77324. cp = sigData;
  77325. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  77326. ExpectIntEQ((cp == sigData + 8), 1);
  77327. cp = sigData;
  77328. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  77329. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  77330. ExpectIntEQ((sig == sig2), 1);
  77331. cp = outSig;
  77332. p = outSig;
  77333. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  77334. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  77335. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  77336. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  77337. ExpectIntEQ((p == outSig + 8), 1);
  77338. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  77339. p = NULL;
  77340. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  77341. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  77342. ExpectNull(p);
  77343. #else
  77344. ExpectNotNull(p);
  77345. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  77346. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  77347. #endif
  77348. wolfSSL_ECDSA_SIG_free(sig);
  77349. #endif
  77350. return EXPECT_RESULT();
  77351. }
  77352. static int test_ECDSA_size_sign(void)
  77353. {
  77354. EXPECT_DECLS;
  77355. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  77356. EC_KEY* key = NULL;
  77357. ECDSA_SIG* ecdsaSig = NULL;
  77358. int id;
  77359. byte hash[WC_MAX_DIGEST_SIZE];
  77360. byte hash2[WC_MAX_DIGEST_SIZE];
  77361. byte sig[ECC_MAX_SIG_SIZE];
  77362. unsigned int sigSz = sizeof(sig);
  77363. XMEMSET(hash, 123, sizeof(hash));
  77364. XMEMSET(hash2, 234, sizeof(hash2));
  77365. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  77366. ExpectIntEQ(id, ECC_SECP256R1);
  77367. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77368. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  77369. ExpectIntGE(ECDSA_size(NULL), 0);
  77370. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  77371. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  77372. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  77373. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  77374. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  77375. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  77376. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  77377. ExpectIntGE(ECDSA_size(key), sigSz);
  77378. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  77379. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  77380. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  77381. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  77382. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  77383. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  77384. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  77385. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  77386. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  77387. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  77388. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  77389. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  77390. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  77391. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  77392. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  77393. ECDSA_SIG_free(ecdsaSig);
  77394. EC_KEY_free(key);
  77395. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  77396. return EXPECT_RESULT();
  77397. }
  77398. static int test_ECDH_compute_key(void)
  77399. {
  77400. EXPECT_DECLS;
  77401. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77402. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77403. EC_KEY* key1 = NULL;
  77404. EC_KEY* key2 = NULL;
  77405. EC_POINT* pub1 = NULL;
  77406. EC_POINT* pub2 = NULL;
  77407. byte secret1[32];
  77408. byte secret2[32];
  77409. int i;
  77410. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77411. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  77412. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  77413. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77414. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  77415. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  77416. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  77417. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  77418. 0);
  77419. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  77420. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  77421. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  77422. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  77423. 0);
  77424. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  77425. 0);
  77426. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  77427. NULL), 0);
  77428. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  77429. sizeof(secret1));
  77430. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  77431. sizeof(secret2));
  77432. for (i = 0; i < (int)sizeof(secret1); i++) {
  77433. ExpectIntEQ(secret1[i], secret2[i]);
  77434. }
  77435. EC_KEY_free(key2);
  77436. EC_KEY_free(key1);
  77437. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  77438. * !WOLF_CRYPTO_CB_ONLY_ECC */
  77439. return EXPECT_RESULT();
  77440. }
  77441. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  77442. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  77443. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  77444. !defined(NO_ASN_TIME)
  77445. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  77446. int expectedDerSz)
  77447. {
  77448. EXPECT_DECLS;
  77449. X509* x509 = NULL;
  77450. BIGNUM* serial_number = NULL;
  77451. X509_NAME* name = NULL;
  77452. time_t epoch_off = 0;
  77453. ASN1_INTEGER* asn1_serial_number = NULL;
  77454. long not_before, not_after;
  77455. int derSz;
  77456. ExpectNotNull(x509 = X509_new());
  77457. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  77458. ExpectNotNull(serial_number = BN_new());
  77459. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  77460. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  77461. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  77462. /* version 3 */
  77463. ExpectIntNE(X509_set_version(x509, 2L), 0);
  77464. ExpectNotNull(name = X509_NAME_new());
  77465. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  77466. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  77467. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  77468. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  77469. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  77470. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  77471. not_before = (long)wc_Time(NULL);
  77472. not_after = not_before + (365 * 24 * 60 * 60);
  77473. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  77474. &epoch_off));
  77475. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  77476. &epoch_off));
  77477. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  77478. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  77479. ExpectIntGE(derSz, expectedDerSz);
  77480. BN_free(serial_number);
  77481. X509_NAME_free(name);
  77482. X509_free(x509);
  77483. return EXPECT_RESULT();
  77484. }
  77485. #endif
  77486. static int test_openssl_generate_key_and_cert(void)
  77487. {
  77488. EXPECT_DECLS;
  77489. #if defined(OPENSSL_EXTRA)
  77490. int expectedDerSz;
  77491. EVP_PKEY* pkey = NULL;
  77492. #ifdef HAVE_ECC
  77493. EC_KEY* ec_key = NULL;
  77494. #endif
  77495. #if !defined(NO_RSA)
  77496. int key_length = 2048;
  77497. BIGNUM* exponent = NULL;
  77498. RSA* rsa = NULL;
  77499. ExpectNotNull(pkey = EVP_PKEY_new());
  77500. ExpectNotNull(exponent = BN_new());
  77501. ExpectNotNull(rsa = RSA_new());
  77502. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  77503. #ifndef WOLFSSL_KEY_GEN
  77504. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77505. #if defined(USE_CERT_BUFFERS_1024)
  77506. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  77507. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77508. key_length = 1024;
  77509. #elif defined(USE_CERT_BUFFERS_2048)
  77510. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  77511. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77512. #else
  77513. RSA_free(rsa);
  77514. rsa = NULL;
  77515. #endif
  77516. #else
  77517. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  77518. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  77519. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  77520. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77521. #endif
  77522. if (rsa) {
  77523. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  77524. if (EXPECT_FAIL()) {
  77525. RSA_free(rsa);
  77526. }
  77527. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77528. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77529. expectedDerSz = 743;
  77530. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  77531. expectedDerSz), TEST_SUCCESS);
  77532. #endif
  77533. }
  77534. EVP_PKEY_free(pkey);
  77535. pkey = NULL;
  77536. BN_free(exponent);
  77537. #endif /* !NO_RSA */
  77538. #ifdef HAVE_ECC
  77539. ExpectNotNull(pkey = EVP_PKEY_new());
  77540. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77541. #ifndef NO_WOLFSSL_STUB
  77542. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  77543. #endif
  77544. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  77545. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  77546. if (EXPECT_FAIL()) {
  77547. EC_KEY_free(ec_key);
  77548. }
  77549. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77550. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77551. expectedDerSz = 344;
  77552. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  77553. TEST_SUCCESS);
  77554. #endif
  77555. EVP_PKEY_free(pkey);
  77556. #endif /* HAVE_ECC */
  77557. (void)pkey;
  77558. (void)expectedDerSz;
  77559. #endif /* OPENSSL_EXTRA */
  77560. return EXPECT_RESULT();
  77561. }
  77562. static int test_stubs_are_stubs(void)
  77563. {
  77564. EXPECT_DECLS;
  77565. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  77566. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77567. WOLFSSL_CTX* ctx = NULL;
  77568. WOLFSSL_CTX* ctxN = NULL;
  77569. #ifndef NO_WOLFSSL_CLIENT
  77570. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77571. #elif !defined(NO_WOLFSSL_SERVER)
  77572. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  77573. #endif
  77574. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  77575. ExpectIntEQ((int) x(z), 0)
  77576. /* test logic, all stubs return same result regardless of ctx being NULL
  77577. * as there are no sanity checks, it's just a stub! If at some
  77578. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  77579. * if invalid inputs are supplied. Test calling both
  77580. * with and without valid inputs, if a stub functionality remains unchanged.
  77581. */
  77582. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  77583. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  77584. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  77585. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  77586. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  77587. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  77588. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  77589. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  77590. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  77591. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  77592. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  77593. /* when implemented this should take WOLFSSL object instead, right now
  77594. * always returns 0 */
  77595. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77596. wolfSSL_CTX_free(ctx);
  77597. ctx = NULL;
  77598. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  77599. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77600. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  77601. * !NO_WOLFSSL_SERVER) */
  77602. return EXPECT_RESULT();
  77603. }
  77604. static int test_CONF_modules_xxx(void)
  77605. {
  77606. int res = TEST_SKIPPED;
  77607. #if defined(OPENSSL_EXTRA)
  77608. CONF_modules_free();
  77609. CONF_modules_unload(0);
  77610. CONF_modules_unload(1);
  77611. CONF_modules_unload(-1);
  77612. res = TEST_SUCCESS;
  77613. #endif /* OPENSSL_EXTRA */
  77614. return res;
  77615. }
  77616. static int test_CRYPTO_set_dynlock_xxx(void)
  77617. {
  77618. int res = TEST_SKIPPED;
  77619. #if defined(OPENSSL_EXTRA)
  77620. CRYPTO_set_dynlock_create_callback(
  77621. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  77622. CRYPTO_set_dynlock_create_callback(
  77623. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  77624. CRYPTO_set_dynlock_destroy_callback(
  77625. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  77626. CRYPTO_set_dynlock_destroy_callback(
  77627. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  77628. CRYPTO_set_dynlock_lock_callback(
  77629. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  77630. CRYPTO_set_dynlock_lock_callback(
  77631. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  77632. res = TEST_SUCCESS;
  77633. #endif /* OPENSSL_EXTRA */
  77634. return res;
  77635. }
  77636. static int test_CRYPTO_THREADID_xxx(void)
  77637. {
  77638. EXPECT_DECLS;
  77639. #if defined(OPENSSL_EXTRA)
  77640. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  77641. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  77642. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  77643. #endif /* OPENSSL_EXTRA */
  77644. return EXPECT_RESULT();
  77645. }
  77646. static int test_ENGINE_cleanup(void)
  77647. {
  77648. int res = TEST_SKIPPED;
  77649. #if defined(OPENSSL_EXTRA)
  77650. ENGINE_cleanup();
  77651. res = TEST_SUCCESS;
  77652. #endif /* OPENSSL_EXTRA */
  77653. return res;
  77654. }
  77655. static int test_wolfSSL_CTX_LoadCRL(void)
  77656. {
  77657. EXPECT_DECLS;
  77658. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  77659. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77660. WOLFSSL_CTX* ctx = NULL;
  77661. WOLFSSL* ssl = NULL;
  77662. const char* badPath = "dummypath";
  77663. const char* validPath = "./certs/crl";
  77664. const char* validFilePath = "./certs/crl/cliCrl.pem";
  77665. const char* issuerCert = "./certs/client-cert.pem";
  77666. int derType = WOLFSSL_FILETYPE_ASN1;
  77667. int pemType = WOLFSSL_FILETYPE_PEM;
  77668. #ifdef HAVE_CRL_MONITOR
  77669. int monitor = WOLFSSL_CRL_MONITOR;
  77670. #else
  77671. int monitor = 0;
  77672. #endif
  77673. WOLFSSL_CERT_MANAGER* cm = NULL;
  77674. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77675. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  77676. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77677. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  77678. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77679. WOLFSSL_SUCCESS)
  77680. #ifndef NO_WOLFSSL_CLIENT
  77681. #define NEW_CTX(ctx) ExpectNotNull( \
  77682. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  77683. #elif !defined(NO_WOLFSSL_SERVER)
  77684. #define NEW_CTX(ctx) ExpectNotNull( \
  77685. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  77686. #else
  77687. #define NEW_CTX(ctx) return
  77688. #endif
  77689. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77690. NEW_CTX(ctx);
  77691. #ifndef HAVE_CRL_MONITOR
  77692. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  77693. wolfSSL_CTX_free(ctx);
  77694. NEW_CTX(ctx);
  77695. #endif
  77696. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77697. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  77698. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  77699. wolfSSL_CTX_free(ctx);
  77700. ctx = NULL;
  77701. NEW_CTX(ctx);
  77702. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77703. WOLFSSL_SUCCESS);
  77704. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  77705. wolfSSL_CTX_free(ctx);
  77706. ctx = NULL;
  77707. NEW_CTX(ctx);
  77708. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77709. WOLFSSL_SUCCESS);
  77710. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77711. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  77712. wolfSSL_free(ssl);
  77713. ssl = NULL;
  77714. wolfSSL_CTX_free(ctx);
  77715. ctx = NULL;
  77716. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  77717. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  77718. WOLFSSL_SUCCESS);
  77719. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  77720. WOLFSSL_SUCCESS);
  77721. wolfSSL_CertManagerFree(cm);
  77722. #endif
  77723. return EXPECT_RESULT();
  77724. }
  77725. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77726. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77727. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  77728. {
  77729. EXPECT_DECLS;
  77730. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  77731. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  77732. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  77733. return EXPECT_RESULT();
  77734. }
  77735. #endif
  77736. static int test_multiple_crls_same_issuer(void)
  77737. {
  77738. EXPECT_DECLS;
  77739. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77740. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77741. test_ssl_cbf client_cbs, server_cbs;
  77742. struct {
  77743. const char* server_cert;
  77744. const char* server_key;
  77745. } test_params[] = {
  77746. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  77747. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  77748. };
  77749. size_t i;
  77750. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  77751. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77752. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77753. server_cbs.certPemFile = test_params[i].server_cert;
  77754. server_cbs.keyPemFile = test_params[i].server_key;
  77755. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  77756. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  77757. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  77758. &server_cbs, NULL), -1001);
  77759. }
  77760. #endif
  77761. return EXPECT_RESULT();
  77762. }
  77763. static int test_SetTmpEC_DHE_Sz(void)
  77764. {
  77765. EXPECT_DECLS;
  77766. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  77767. WOLFSSL_CTX *ctx = NULL;
  77768. WOLFSSL *ssl = NULL;
  77769. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77770. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  77771. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77772. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  77773. wolfSSL_free(ssl);
  77774. wolfSSL_CTX_free(ctx);
  77775. #endif
  77776. return EXPECT_RESULT();
  77777. }
  77778. static int test_wolfSSL_CTX_get0_privatekey(void)
  77779. {
  77780. EXPECT_DECLS;
  77781. #ifdef OPENSSL_ALL
  77782. WOLFSSL_CTX* ctx = NULL;
  77783. (void)ctx;
  77784. #ifndef NO_RSA
  77785. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77786. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77787. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  77788. WOLFSSL_FILETYPE_PEM));
  77789. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77790. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  77791. WOLFSSL_FILETYPE_PEM));
  77792. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77793. wolfSSL_CTX_free(ctx);
  77794. ctx = NULL;
  77795. #endif
  77796. #ifdef HAVE_ECC
  77797. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77798. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77799. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  77800. WOLFSSL_FILETYPE_PEM));
  77801. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77802. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  77803. WOLFSSL_FILETYPE_PEM));
  77804. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77805. wolfSSL_CTX_free(ctx);
  77806. #endif
  77807. #endif
  77808. return EXPECT_RESULT();
  77809. }
  77810. static int test_wolfSSL_dtls_set_mtu(void)
  77811. {
  77812. EXPECT_DECLS;
  77813. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  77814. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  77815. !defined(WOLFSSL_NO_TLS12)
  77816. WOLFSSL_CTX* ctx = NULL;
  77817. WOLFSSL* ssl = NULL;
  77818. const char* testCertFile;
  77819. const char* testKeyFile;
  77820. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  77821. #ifndef NO_RSA
  77822. testCertFile = svrCertFile;
  77823. testKeyFile = svrKeyFile;
  77824. #elif defined(HAVE_ECC)
  77825. testCertFile = eccCertFile;
  77826. testKeyFile = eccKeyFile;
  77827. #endif
  77828. if (testCertFile != NULL && testKeyFile != NULL) {
  77829. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  77830. WOLFSSL_FILETYPE_PEM));
  77831. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  77832. WOLFSSL_FILETYPE_PEM));
  77833. }
  77834. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77835. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77836. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77837. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77838. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77839. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77840. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  77841. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  77842. wolfSSL_free(ssl);
  77843. wolfSSL_CTX_free(ctx);
  77844. #endif
  77845. return EXPECT_RESULT();
  77846. }
  77847. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77848. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77849. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  77850. enum HandShakeType hsType, word16 length)
  77851. {
  77852. size_t idx = 0;
  77853. byte* l;
  77854. /* record layer */
  77855. /* handshake type */
  77856. out[idx++] = handshake;
  77857. /* protocol version */
  77858. out[idx++] = 0xfe;
  77859. out[idx++] = 0xfd; /* DTLS 1.2 */
  77860. /* epoch 0 */
  77861. XMEMSET(out + idx, 0, 2);
  77862. idx += 2;
  77863. /* sequence number */
  77864. XMEMSET(out + idx, 0, 6);
  77865. c32toa(seq, out + idx + 2);
  77866. idx += 6;
  77867. /* length in BE */
  77868. if (length)
  77869. c16toa(length, out + idx);
  77870. else
  77871. c16toa(outSz - idx - 2, out + idx);
  77872. idx += 2;
  77873. /* handshake layer */
  77874. /* handshake type */
  77875. out[idx++] = (byte)hsType;
  77876. /* length */
  77877. l = out + idx;
  77878. idx += 3;
  77879. /* message seq */
  77880. c16toa(0, out + idx);
  77881. idx += 2;
  77882. /* frag offset */
  77883. c32to24(0, out + idx);
  77884. idx += 3;
  77885. /* frag length */
  77886. c32to24((word32)outSz - (word32)idx - 3, l);
  77887. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  77888. idx += 3;
  77889. XMEMSET(out + idx, 0, outSz - idx);
  77890. }
  77891. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  77892. {
  77893. byte msg[] = "This is a msg for the client";
  77894. byte reply[40];
  77895. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77896. reply[sizeof(reply) - 1] = '\0';
  77897. fprintf(stderr, "Client message: %s\n", reply);
  77898. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77899. }
  77900. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  77901. {
  77902. byte ch[50];
  77903. int fd = wolfSSL_get_fd(ssl);
  77904. byte msg[] = "This is a msg for the server";
  77905. byte reply[40];
  77906. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  77907. /* Server should ignore this datagram */
  77908. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77909. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  77910. /* Server should ignore this datagram */
  77911. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77912. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77913. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77914. reply[sizeof(reply) - 1] = '\0';
  77915. fprintf(stderr, "Server response: %s\n", reply);
  77916. }
  77917. static int test_wolfSSL_dtls_plaintext(void)
  77918. {
  77919. callback_functions func_cb_client;
  77920. callback_functions func_cb_server;
  77921. size_t i;
  77922. struct test_params {
  77923. method_provider client_meth;
  77924. method_provider server_meth;
  77925. ssl_callback on_result_server;
  77926. ssl_callback on_result_client;
  77927. } params[] = {
  77928. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77929. test_wolfSSL_dtls_plaintext_server,
  77930. test_wolfSSL_dtls_plaintext_client},
  77931. };
  77932. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77933. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77934. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77935. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77936. func_cb_server.method = params[i].server_meth;
  77937. func_cb_client.method = params[i].client_meth;
  77938. func_cb_client.on_result = params[i].on_result_client;
  77939. func_cb_server.on_result = params[i].on_result_server;
  77940. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77941. if (!func_cb_client.return_code)
  77942. return TEST_FAIL;
  77943. if (!func_cb_server.return_code)
  77944. return TEST_FAIL;
  77945. }
  77946. return TEST_RES_CHECK(1);
  77947. }
  77948. #else
  77949. static int test_wolfSSL_dtls_plaintext(void) {
  77950. return TEST_SKIPPED;
  77951. }
  77952. #endif
  77953. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77954. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77955. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  77956. {
  77957. byte b[1100]; /* buffer for the messages to send */
  77958. size_t idx = 0;
  77959. size_t seq_offset = 0;
  77960. size_t msg_offset = 0;
  77961. int i;
  77962. int fd = wolfSSL_get_fd(ssl);
  77963. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77964. word32 seq_number = 100; /* start high so server definitely reads this */
  77965. word16 msg_number = 50; /* start high so server has to buffer this */
  77966. AssertIntEQ(ret, 1);
  77967. /* Now let's start spamming the peer with fragments it needs to store */
  77968. XMEMSET(b, -1, sizeof(b));
  77969. /* record layer */
  77970. /* handshake type */
  77971. b[idx++] = 22;
  77972. /* protocol version */
  77973. b[idx++] = 0xfe;
  77974. b[idx++] = 0xfd; /* DTLS 1.2 */
  77975. /* epoch 0 */
  77976. XMEMSET(b + idx, 0, 2);
  77977. idx += 2;
  77978. /* sequence number */
  77979. XMEMSET(b + idx, 0, 6);
  77980. seq_offset = idx + 2; /* increment only the low 32 bits */
  77981. idx += 6;
  77982. /* static length in BE */
  77983. c16toa(42, b + idx);
  77984. idx += 2;
  77985. /* handshake layer */
  77986. /* cert type */
  77987. b[idx++] = 11;
  77988. /* length */
  77989. c32to24(1000, b + idx);
  77990. idx += 3;
  77991. /* message seq */
  77992. c16toa(0, b + idx);
  77993. msg_offset = idx;
  77994. idx += 2;
  77995. /* frag offset */
  77996. c32to24(500, b + idx);
  77997. idx += 3;
  77998. /* frag length */
  77999. c32to24(30, b + idx);
  78000. idx += 3;
  78001. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  78002. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  78003. seq_number++, msg_number++, i++) {
  78004. struct timespec delay;
  78005. XMEMSET(&delay, 0, sizeof(delay));
  78006. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78007. c32toa(seq_number, b + seq_offset);
  78008. c16toa(msg_number, b + msg_offset);
  78009. ret = (int)send(fd, b, 55, 0);
  78010. nanosleep(&delay, NULL);
  78011. }
  78012. }
  78013. #ifdef WOLFSSL_DTLS13
  78014. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  78015. {
  78016. const word16 sendCountMax = 100;
  78017. byte b[150]; /* buffer for the messages to send */
  78018. size_t idx = 0;
  78019. size_t msg_offset = 0;
  78020. int fd = wolfSSL_get_fd(ssl);
  78021. word16 msg_number = 10; /* start high so server has to buffer this */
  78022. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  78023. AssertIntEQ(ret, 1);
  78024. /* Now let's start spamming the peer with fragments it needs to store */
  78025. XMEMSET(b, -1, sizeof(b));
  78026. /* handshake type */
  78027. b[idx++] = 11;
  78028. /* length */
  78029. c32to24(10000, b + idx);
  78030. idx += 3;
  78031. /* message_seq */
  78032. msg_offset = idx;
  78033. idx += 2;
  78034. /* fragment_offset */
  78035. c32to24(5000, b + idx);
  78036. idx += 3;
  78037. /* fragment_length */
  78038. c32to24(100, b + idx);
  78039. idx += 3;
  78040. /* fragment contents */
  78041. idx += 100;
  78042. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  78043. byte sendBuf[150];
  78044. int sendSz = sizeof(sendBuf);
  78045. struct timespec delay;
  78046. XMEMSET(&delay, 0, sizeof(delay));
  78047. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78048. c16toa(msg_number, b + msg_offset);
  78049. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  78050. (int)idx, handshake, 0, 0, 0);
  78051. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  78052. nanosleep(&delay, NULL);
  78053. }
  78054. }
  78055. #endif
  78056. static int test_wolfSSL_dtls_fragments(void)
  78057. {
  78058. EXPECT_DECLS;
  78059. callback_functions func_cb_client;
  78060. callback_functions func_cb_server;
  78061. size_t i;
  78062. struct test_params {
  78063. method_provider client_meth;
  78064. method_provider server_meth;
  78065. ssl_callback spammer;
  78066. } params[] = {
  78067. #if !defined(WOLFSSL_NO_TLS12)
  78068. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78069. test_wolfSSL_dtls12_fragments_spammer},
  78070. #endif
  78071. #ifdef WOLFSSL_DTLS13
  78072. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78073. test_wolfSSL_dtls13_fragments_spammer},
  78074. #endif
  78075. };
  78076. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  78077. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78078. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78079. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78080. func_cb_server.method = params[i].server_meth;
  78081. func_cb_client.method = params[i].client_meth;
  78082. func_cb_client.ssl_ready = params[i].spammer;
  78083. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78084. ExpectFalse(func_cb_client.return_code);
  78085. ExpectFalse(func_cb_server.return_code);
  78086. /* The socket should be closed by the server resulting in a
  78087. * socket error, fatal error or reading a close notify alert */
  78088. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  78089. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  78090. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  78091. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  78092. }
  78093. /* Check the server returned an error indicating the msg buffer
  78094. * was full */
  78095. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  78096. if (EXPECT_FAIL())
  78097. break;
  78098. }
  78099. return EXPECT_RESULT();
  78100. }
  78101. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  78102. {
  78103. int fd, ret;
  78104. byte alert_msg[] = {
  78105. 0x15, /* alert type */
  78106. 0xfe, 0xfd, /* version */
  78107. 0x00, 0x00, /* epoch */
  78108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  78109. 0x00, 0x02, /* length */
  78110. 0x02, /* level: fatal */
  78111. 0x46 /* protocol version */
  78112. };
  78113. fd = wolfSSL_get_fd(ssl);
  78114. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  78115. AssertIntGT(ret, 0);
  78116. }
  78117. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  78118. {
  78119. callback_functions client_cbs, server_cbs;
  78120. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78121. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78122. client_cbs.doUdp = server_cbs.doUdp = 1;
  78123. if (version12) {
  78124. #if !defined(WOLFSSL_NO_TLS12)
  78125. client_cbs.method = wolfDTLSv1_2_client_method;
  78126. server_cbs.method = wolfDTLSv1_2_server_method;
  78127. #else
  78128. return TEST_SKIPPED;
  78129. #endif
  78130. }
  78131. else
  78132. {
  78133. #ifdef WOLFSSL_DTLS13
  78134. client_cbs.method = wolfDTLSv1_3_client_method;
  78135. server_cbs.method = wolfDTLSv1_3_server_method;
  78136. #else
  78137. return TEST_SKIPPED;
  78138. #endif /* WOLFSSL_DTLS13 */
  78139. }
  78140. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  78141. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78142. if (!client_cbs.return_code)
  78143. return TEST_FAIL;
  78144. if (!server_cbs.return_code)
  78145. return TEST_FAIL;
  78146. return TEST_SUCCESS;
  78147. }
  78148. static int test_wolfSSL_ignore_alert_before_cookie(void)
  78149. {
  78150. int ret;
  78151. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  78152. if (ret != 0)
  78153. return ret;
  78154. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  78155. if (ret != 0)
  78156. return ret;
  78157. return 0;
  78158. }
  78159. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  78160. {
  78161. int ret;
  78162. int fd;
  78163. byte bad_msg[] = {
  78164. 0x17, /* app data */
  78165. 0xaa, 0xfd, /* bad version */
  78166. 0x00, 0x01, /* epoch 1 */
  78167. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  78168. 0x00, 0x26, /* length: 38 bytes */
  78169. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  78170. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  78171. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  78172. 0x03, 0x18, 0x72
  78173. };
  78174. fd = wolfSSL_get_fd(ssl);
  78175. AssertIntGE(fd, 0);
  78176. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  78177. AssertIntEQ(ret, sizeof(bad_msg));
  78178. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  78179. AssertIntEQ(ret, sizeof("badrecordtest"));
  78180. }
  78181. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  78182. {
  78183. byte buf[100];
  78184. int ret;
  78185. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  78186. AssertIntGT(ret, 0);
  78187. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  78188. }
  78189. static int _test_wolfSSL_dtls_bad_record(
  78190. method_provider client_method, method_provider server_method)
  78191. {
  78192. callback_functions client_cbs, server_cbs;
  78193. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78194. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78195. client_cbs.doUdp = server_cbs.doUdp = 1;
  78196. client_cbs.method = client_method;
  78197. server_cbs.method = server_method;
  78198. client_cbs.on_result = test_wolfSSL_send_bad_record;
  78199. server_cbs.on_result = test_wolfSSL_read_string;
  78200. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78201. if (!client_cbs.return_code)
  78202. return TEST_FAIL;
  78203. if (!server_cbs.return_code)
  78204. return TEST_FAIL;
  78205. return TEST_SUCCESS;
  78206. }
  78207. static int test_wolfSSL_dtls_bad_record(void)
  78208. {
  78209. int ret = TEST_SUCCESS;
  78210. #if !defined(WOLFSSL_NO_TLS12)
  78211. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  78212. wolfDTLSv1_2_server_method);
  78213. #endif
  78214. #ifdef WOLFSSL_DTLS13
  78215. if (ret == TEST_SUCCESS) {
  78216. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  78217. wolfDTLSv1_3_server_method);
  78218. }
  78219. #endif /* WOLFSSL_DTLS13 */
  78220. return ret;
  78221. }
  78222. #else
  78223. static int test_wolfSSL_dtls_fragments(void) {
  78224. return TEST_SKIPPED;
  78225. }
  78226. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  78227. return TEST_SKIPPED;
  78228. }
  78229. static int test_wolfSSL_dtls_bad_record(void) {
  78230. return TEST_SKIPPED;
  78231. }
  78232. #endif
  78233. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  78234. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  78235. defined(HAVE_IO_TESTS_DEPENDENCIES)
  78236. static byte test_AEAD_fail_decryption = 0;
  78237. static byte test_AEAD_seq_num = 0;
  78238. static byte test_AEAD_done = 0;
  78239. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  78240. {
  78241. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  78242. if (ret > 0) {
  78243. if (test_AEAD_fail_decryption) {
  78244. /* Modify the packet to trigger a decryption failure */
  78245. buf[ret/2] ^= 0xFF;
  78246. if (test_AEAD_fail_decryption == 1)
  78247. test_AEAD_fail_decryption = 0;
  78248. }
  78249. }
  78250. (void)ctx;
  78251. return ret;
  78252. }
  78253. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  78254. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  78255. {
  78256. if (sendLimit)
  78257. w64Zero(sendLimit);
  78258. switch (ssl->specs.bulk_cipher_algorithm) {
  78259. case wolfssl_aes_gcm:
  78260. if (sendLimit)
  78261. *sendLimit = AEAD_AES_LIMIT;
  78262. FALL_THROUGH;
  78263. case wolfssl_chacha:
  78264. if (hardLimit)
  78265. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  78266. if (keyUpdateLimit)
  78267. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  78268. break;
  78269. case wolfssl_aes_ccm:
  78270. if (sendLimit)
  78271. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  78272. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  78273. if (hardLimit)
  78274. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  78275. if (keyUpdateLimit)
  78276. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  78277. }
  78278. else {
  78279. if (hardLimit)
  78280. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  78281. if (keyUpdateLimit)
  78282. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  78283. }
  78284. break;
  78285. default:
  78286. fprintf(stderr, "Unrecognized bulk cipher");
  78287. AssertFalse(1);
  78288. break;
  78289. }
  78290. }
  78291. static void test_AEAD_limit_client(WOLFSSL* ssl)
  78292. {
  78293. int ret;
  78294. int i;
  78295. int didReKey = 0;
  78296. char msgBuf[20];
  78297. w64wrapper hardLimit;
  78298. w64wrapper keyUpdateLimit;
  78299. w64wrapper counter;
  78300. w64wrapper sendLimit;
  78301. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  78302. w64Zero(&counter);
  78303. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  78304. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  78305. for (i = 0; i < 10; i++) {
  78306. /* Test some failed decryptions */
  78307. test_AEAD_fail_decryption = 1;
  78308. w64Increment(&counter);
  78309. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78310. /* Should succeed since decryption failures are dropped */
  78311. AssertIntGT(ret, 0);
  78312. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  78313. }
  78314. test_AEAD_fail_decryption = 1;
  78315. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  78316. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78317. /* 100 read calls should be enough to complete the key update */
  78318. w64Zero(&counter);
  78319. for (i = 0; i < 100; i++) {
  78320. /* Key update should be sent and negotiated */
  78321. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78322. AssertIntGT(ret, 0);
  78323. /* Epoch after one key update is 4 */
  78324. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  78325. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  78326. didReKey = 1;
  78327. break;
  78328. }
  78329. }
  78330. AssertTrue(didReKey);
  78331. if (!w64IsZero(sendLimit)) {
  78332. /* Test the sending limit for AEAD ciphers */
  78333. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  78334. test_AEAD_seq_num = 1;
  78335. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78336. AssertIntGT(ret, 0);
  78337. didReKey = 0;
  78338. w64Zero(&counter);
  78339. /* 100 read calls should be enough to complete the key update */
  78340. for (i = 0; i < 100; i++) {
  78341. /* Key update should be sent and negotiated */
  78342. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78343. AssertIntGT(ret, 0);
  78344. /* Epoch after another key update is 5 */
  78345. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  78346. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  78347. didReKey = 1;
  78348. break;
  78349. }
  78350. }
  78351. AssertTrue(didReKey);
  78352. }
  78353. test_AEAD_fail_decryption = 2;
  78354. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  78355. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78356. /* Connection should fail with a DECRYPT_ERROR */
  78357. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78358. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78359. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  78360. test_AEAD_done = 1;
  78361. }
  78362. int counter = 0;
  78363. static void test_AEAD_limit_server(WOLFSSL* ssl)
  78364. {
  78365. char msgBuf[] = "Sending data";
  78366. int ret = WOLFSSL_SUCCESS;
  78367. w64wrapper sendLimit;
  78368. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78369. struct timespec delay;
  78370. XMEMSET(&delay, 0, sizeof(delay));
  78371. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  78372. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  78373. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78374. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  78375. while (!test_AEAD_done && ret > 0) {
  78376. counter++;
  78377. if (test_AEAD_seq_num) {
  78378. /* We need to update the seq number so that we can understand the
  78379. * peer. Otherwise we will incorrectly interpret the seq number. */
  78380. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  78381. AssertNotNull(e);
  78382. e->nextPeerSeqNumber = sendLimit;
  78383. test_AEAD_seq_num = 0;
  78384. }
  78385. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78386. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78387. nanosleep(&delay, NULL);
  78388. }
  78389. }
  78390. static int test_wolfSSL_dtls_AEAD_limit(void)
  78391. {
  78392. callback_functions func_cb_client;
  78393. callback_functions func_cb_server;
  78394. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78395. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78396. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78397. func_cb_server.method = wolfDTLSv1_3_server_method;
  78398. func_cb_client.method = wolfDTLSv1_3_client_method;
  78399. func_cb_server.on_result = test_AEAD_limit_server;
  78400. func_cb_client.on_result = test_AEAD_limit_client;
  78401. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78402. if (!func_cb_client.return_code)
  78403. return TEST_FAIL;
  78404. if (!func_cb_server.return_code)
  78405. return TEST_FAIL;
  78406. return TEST_SUCCESS;
  78407. }
  78408. #else
  78409. static int test_wolfSSL_dtls_AEAD_limit(void)
  78410. {
  78411. return TEST_SKIPPED;
  78412. }
  78413. #endif
  78414. #if defined(WOLFSSL_DTLS) && \
  78415. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78416. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  78417. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  78418. {
  78419. int fd, ret;
  78420. byte ch_msg[] = {
  78421. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78422. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78423. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  78424. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  78425. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  78426. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78427. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78428. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78429. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78430. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78431. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78432. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78433. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78434. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  78435. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  78436. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  78437. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  78438. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  78439. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  78440. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  78441. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  78442. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  78443. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  78444. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  78445. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  78446. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  78447. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  78448. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  78449. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  78450. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  78451. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  78452. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  78453. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  78454. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  78455. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  78456. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  78457. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  78458. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  78459. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  78460. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  78461. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  78462. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  78463. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  78464. 0x31, 0x68, 0x4c
  78465. };
  78466. fd = wolfSSL_get_fd(ssl);
  78467. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  78468. AssertIntGT(ret, 0);
  78469. /* consume the HRR otherwise handshake will fail */
  78470. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  78471. AssertIntGT(ret, 0);
  78472. }
  78473. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78474. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  78475. {
  78476. int fd, ret;
  78477. byte ch_msh_invalid_cookie[] = {
  78478. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  78479. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  78480. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  78481. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  78482. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  78483. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78484. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78485. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78486. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78487. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78488. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78489. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78490. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78491. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  78492. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78493. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78494. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78495. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78496. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78497. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  78498. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  78499. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  78500. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  78501. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  78502. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  78503. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  78504. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  78505. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  78506. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  78507. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  78508. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  78509. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  78510. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  78511. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  78512. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  78513. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  78514. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  78515. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  78516. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  78517. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  78518. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  78519. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  78520. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  78521. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  78522. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  78523. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  78524. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  78525. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  78526. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  78527. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  78528. 0x23, 0x00, 0x00
  78529. };
  78530. byte alert_reply[50];
  78531. byte expected_alert_reply[] = {
  78532. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  78533. 0x02, 0x02, 0x2f
  78534. };
  78535. fd = wolfSSL_get_fd(ssl);
  78536. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  78537. AssertIntGT(ret, 0);
  78538. /* should reply with an illegal_parameter reply */
  78539. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  78540. AssertIntEQ(ret, sizeof(expected_alert_reply));
  78541. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  78542. }
  78543. #endif
  78544. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  78545. {
  78546. #ifndef NO_MD5
  78547. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  78548. #elif !defined(NO_SHA)
  78549. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  78550. #elif !defined(NO_SHA256)
  78551. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  78552. #else
  78553. #error "We need a digest to hash the WOLFSSL object"
  78554. #endif
  78555. byte hashBuf[WC_MAX_DIGEST_SIZE];
  78556. wc_HashAlg hash;
  78557. const TLSX* exts = ssl->extensions;
  78558. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  78559. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  78560. * InitHandshakeHashes */
  78561. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  78562. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  78563. /* Following fields are not important to compare */
  78564. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78565. sslCopy.buffers.inputBuffer.buffer = NULL;
  78566. sslCopy.buffers.inputBuffer.bufferSize = 0;
  78567. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  78568. sslCopy.buffers.inputBuffer.offset = 0;
  78569. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78570. sslCopy.buffers.outputBuffer.buffer = NULL;
  78571. sslCopy.buffers.outputBuffer.bufferSize = 0;
  78572. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  78573. sslCopy.buffers.outputBuffer.offset = 0;
  78574. sslCopy.error = 0;
  78575. sslCopy.curSize = 0;
  78576. sslCopy.curStartIdx = 0;
  78577. sslCopy.keys.curSeq_lo = 0;
  78578. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  78579. #ifdef WOLFSSL_DTLS13
  78580. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  78581. sslCopy.dtls13FastTimeout = 0;
  78582. #endif
  78583. sslCopy.keys.dtls_peer_handshake_number = 0;
  78584. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  78585. sslCopy.hsHashes = NULL;
  78586. #ifdef WOLFSSL_ASYNC_IO
  78587. #ifdef WOLFSSL_ASYNC_CRYPT
  78588. sslCopy.asyncDev = NULL;
  78589. #endif
  78590. sslCopy.async = NULL;
  78591. #endif
  78592. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  78593. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  78594. /* hash extension list */
  78595. while (exts != NULL) {
  78596. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  78597. exts = exts->next;
  78598. }
  78599. /* Hash suites */
  78600. if (sslCopy.suites != NULL) {
  78601. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  78602. sizeof(struct Suites)), 0);
  78603. }
  78604. /* Hash hsHashes */
  78605. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  78606. sizeof(*hsHashes)), 0);
  78607. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  78608. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  78609. return MakeWordFromHash(hashBuf);
  78610. }
  78611. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  78612. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  78613. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  78614. char *buf, int sz, void *ctx)
  78615. {
  78616. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  78617. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  78618. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  78619. }
  78620. else {
  78621. return WOLFSSL_CBIO_ERR_WANT_READ;
  78622. }
  78623. }
  78624. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  78625. {
  78626. /* Compare the ssl object before and after one ClientHello msg */
  78627. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78628. int res;
  78629. int err;
  78630. word32 initHash;
  78631. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  78632. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  78633. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78634. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  78635. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  78636. (void)initHash;
  78637. res = tcp_select(fd, 5);
  78638. /* We are expecting a msg. A timeout indicates failure. */
  78639. AssertIntEQ(res, TEST_RECV_READY);
  78640. res = wolfSSL_accept(ssl);
  78641. err = wolfSSL_get_error(ssl, res);
  78642. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78643. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  78644. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  78645. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  78646. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  78647. }
  78648. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78649. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  78650. {
  78651. int ret;
  78652. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  78653. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  78654. test_wolfSSL_dtls_compare_stateless(ssl);
  78655. }
  78656. #endif
  78657. static int test_wolfSSL_dtls_stateless(void)
  78658. {
  78659. callback_functions client_cbs, server_cbs;
  78660. size_t i;
  78661. struct {
  78662. method_provider client_meth;
  78663. method_provider server_meth;
  78664. ssl_callback client_ssl_ready;
  78665. ssl_callback server_ssl_ready;
  78666. } test_params[] = {
  78667. #if !defined(WOLFSSL_NO_TLS12)
  78668. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78669. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  78670. #endif
  78671. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78672. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78673. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  78674. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78675. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  78676. #endif
  78677. };
  78678. if (0 == sizeof(test_params)){
  78679. return TEST_SKIPPED;
  78680. }
  78681. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  78682. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78683. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78684. client_cbs.doUdp = server_cbs.doUdp = 1;
  78685. client_cbs.method = test_params[i].client_meth;
  78686. server_cbs.method = test_params[i].server_meth;
  78687. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  78688. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  78689. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78690. if (!client_cbs.return_code)
  78691. return TEST_FAIL;
  78692. if (!server_cbs.return_code)
  78693. return TEST_FAIL;
  78694. }
  78695. return TEST_SUCCESS;
  78696. }
  78697. #else
  78698. static int test_wolfSSL_dtls_stateless(void)
  78699. {
  78700. return TEST_SKIPPED;
  78701. }
  78702. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  78703. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  78704. #ifdef HAVE_CERT_CHAIN_VALIDATION
  78705. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78706. {
  78707. int ret;
  78708. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  78709. fprintf(stderr, "loading cert %s failed\n", certA);
  78710. fprintf(stderr, "Error: (%d): %s\n", ret,
  78711. wolfSSL_ERR_reason_error_string(ret));
  78712. return -1;
  78713. }
  78714. return 0;
  78715. }
  78716. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78717. {
  78718. int ret;
  78719. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  78720. != WOLFSSL_SUCCESS) {
  78721. fprintf(stderr, "could not verify the cert: %s\n", certA);
  78722. fprintf(stderr, "Error: (%d): %s\n", ret,
  78723. wolfSSL_ERR_reason_error_string(ret));
  78724. return -1;
  78725. }
  78726. else {
  78727. fprintf(stderr, "successfully verified: %s\n", certA);
  78728. }
  78729. return 0;
  78730. }
  78731. #define LOAD_ONE_CA(a, b, c, d) \
  78732. do { \
  78733. (a) = load_ca_into_cm(c, d); \
  78734. if ((a) != 0) \
  78735. return (b); \
  78736. else \
  78737. (b)--; \
  78738. } while(0)
  78739. #define VERIFY_ONE_CERT(a, b, c, d) \
  78740. do { \
  78741. (a) = verify_cert_with_cm(c, d);\
  78742. if ((a) != 0) \
  78743. return (b); \
  78744. else \
  78745. (b)--; \
  78746. } while(0)
  78747. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  78748. {
  78749. int ret;
  78750. int i = -1;
  78751. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  78752. char chainGArr[9][50] = {"certs/ca-cert.pem",
  78753. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  78754. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  78755. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  78756. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  78757. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  78758. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  78759. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  78760. "certs/test-pathlen/chainG-entity.pem"};
  78761. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  78762. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  78763. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  78764. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  78765. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  78766. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  78767. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  78768. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  78769. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  78770. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  78771. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  78772. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  78773. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  78774. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  78775. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  78776. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  78777. /* test validating the entity twice, should have no effect on pathLen since
  78778. * entity/leaf cert */
  78779. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  78780. return ret;
  78781. }
  78782. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  78783. {
  78784. int ret;
  78785. int i = -1;
  78786. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  78787. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  78788. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  78789. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  78790. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  78791. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78792. */
  78793. char chainHArr[6][50] = {"certs/ca-cert.pem",
  78794. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  78795. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  78796. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  78797. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  78798. "certs/test-pathlen/chainH-entity.pem"};
  78799. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  78800. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  78801. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  78802. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  78803. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  78804. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  78805. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  78806. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  78807. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  78808. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  78809. return ret;
  78810. }
  78811. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  78812. {
  78813. int ret;
  78814. int i = -1;
  78815. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  78816. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  78817. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  78818. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  78819. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78820. */
  78821. char chainIArr[5][50] = {"certs/ca-cert.pem",
  78822. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  78823. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  78824. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  78825. "certs/test-pathlen/chainI-entity.pem"};
  78826. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  78827. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  78828. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  78829. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  78830. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  78831. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  78832. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  78833. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  78834. return ret;
  78835. }
  78836. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  78837. {
  78838. int ret;
  78839. int i = -1;
  78840. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  78841. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  78842. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  78843. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  78844. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  78845. */
  78846. char chainJArr[6][50] = {"certs/ca-cert.pem",
  78847. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  78848. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  78849. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  78850. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  78851. "certs/test-pathlen/chainJ-entity.pem"};
  78852. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  78853. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  78854. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  78855. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  78856. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  78857. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  78858. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  78859. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  78860. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  78861. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  78862. return ret;
  78863. }
  78864. static int test_various_pathlen_chains(void)
  78865. {
  78866. EXPECT_DECLS;
  78867. WOLFSSL_CERT_MANAGER* cm = NULL;
  78868. /* Test chain G (large chain with varying pathLens) */
  78869. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78870. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78871. ExpectIntEQ(test_chainG(cm), -1);
  78872. #else
  78873. ExpectIntEQ(test_chainG(cm), 0);
  78874. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78875. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78876. wolfSSL_CertManagerFree(cm);
  78877. /* end test chain G */
  78878. /* Test chain H (5 chain with same pathLens) */
  78879. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78880. ExpectIntLT(test_chainH(cm), 0);
  78881. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78882. wolfSSL_CertManagerFree(cm);
  78883. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78884. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78885. wolfSSL_CertManagerFree(cm);
  78886. /* end test chain H */
  78887. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  78888. * followed by 2 ICA's, should pass) */
  78889. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78890. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78891. ExpectIntEQ(test_chainI(cm), -1);
  78892. #else
  78893. ExpectIntEQ(test_chainI(cm), 0);
  78894. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78895. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78896. wolfSSL_CertManagerFree(cm);
  78897. cm = NULL;
  78898. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78899. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78900. wolfSSL_CertManagerFree(cm);
  78901. cm = NULL;
  78902. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  78903. * this time followed by 3 ICA's, should fail */
  78904. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78905. ExpectIntLT(test_chainJ(cm), 0);
  78906. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78907. wolfSSL_CertManagerFree(cm);
  78908. cm = NULL;
  78909. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78910. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78911. wolfSSL_CertManagerFree(cm);
  78912. return EXPECT_RESULT();
  78913. }
  78914. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  78915. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  78916. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  78917. {
  78918. EXPECT_DECLS;
  78919. byte ekm[100] = {0};
  78920. (void)ctx;
  78921. /* Success Cases */
  78922. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78923. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  78924. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78925. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  78926. /* Use some random context */
  78927. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78928. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  78929. /* Failure cases */
  78930. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78931. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  78932. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78933. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  78934. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78935. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  78936. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78937. "extended master secret", XSTR_SIZEOF("extended master secret"),
  78938. NULL, 0, 0), 0);
  78939. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78940. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  78941. return EXPECT_RESULT();
  78942. }
  78943. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  78944. {
  78945. wolfSSL_KeepArrays(ssl);
  78946. return TEST_SUCCESS;
  78947. }
  78948. static int test_export_keying_material(void)
  78949. {
  78950. EXPECT_DECLS;
  78951. test_ssl_cbf serverCb;
  78952. test_ssl_cbf clientCb;
  78953. XMEMSET(&serverCb, 0, sizeof(serverCb));
  78954. XMEMSET(&clientCb, 0, sizeof(clientCb));
  78955. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  78956. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  78957. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  78958. return EXPECT_RESULT();
  78959. }
  78960. #endif /* HAVE_KEYING_MATERIAL */
  78961. static int test_wolfSSL_THREADID_hash(void)
  78962. {
  78963. EXPECT_DECLS;
  78964. #if defined(OPENSSL_EXTRA)
  78965. CRYPTO_THREADID id;
  78966. CRYPTO_THREADID_current(NULL);
  78967. /* Hash result is unsigned long. */
  78968. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  78969. XMEMSET(&id, 0, sizeof(id));
  78970. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  78971. #endif /* OPENSSL_EXTRA */
  78972. return EXPECT_RESULT();
  78973. }
  78974. static int test_wolfSSL_set_ecdh_auto(void)
  78975. {
  78976. EXPECT_DECLS;
  78977. #if defined(OPENSSL_EXTRA)
  78978. WOLFSSL* ssl = NULL;
  78979. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  78980. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  78981. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  78982. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  78983. #endif /* OPENSSL_EXTRA */
  78984. return EXPECT_RESULT();
  78985. }
  78986. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  78987. {
  78988. EXPECT_DECLS;
  78989. #if defined(OPENSSL_EXTRA)
  78990. WOLFSSL_CTX* ctx = NULL;
  78991. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  78992. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  78993. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  78994. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  78995. #endif /* OPENSSL_EXTRA */
  78996. return EXPECT_RESULT();
  78997. }
  78998. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78999. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  79000. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  79001. {
  79002. EXPECT_DECLS;
  79003. callback_functions* callbacks = NULL;
  79004. WOLFSSL_CTX* ctx = NULL;
  79005. WOLFSSL* ssl = NULL;
  79006. SOCKET_T sfd = 0;
  79007. SOCKET_T cfd = 0;
  79008. word16 port;
  79009. char msg[] = "I hear you fa shizzle!";
  79010. int len = (int) XSTRLEN(msg);
  79011. char input[1024];
  79012. int ret = 0;
  79013. int err = 0;
  79014. if (!args)
  79015. WOLFSSL_RETURN_FROM_THREAD(0);
  79016. ((func_args*)args)->return_code = TEST_FAIL;
  79017. callbacks = ((func_args*)args)->callbacks;
  79018. ctx = wolfSSL_CTX_new(callbacks->method());
  79019. #if defined(USE_WINDOWS_API)
  79020. port = ((func_args*)args)->signal->port;
  79021. #else
  79022. /* Let tcp_listen assign port */
  79023. port = 0;
  79024. #endif
  79025. #ifdef WOLFSSL_TIRTOS
  79026. fdOpenSession(Task_self());
  79027. #endif
  79028. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79029. caCertFile, 0));
  79030. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79031. svrCertFile, WOLFSSL_FILETYPE_PEM));
  79032. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79033. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  79034. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  79035. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  79036. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  79037. #elif !defined(NO_DH)
  79038. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  79039. #endif
  79040. if (callbacks->ctx_ready)
  79041. callbacks->ctx_ready(ctx);
  79042. ssl = wolfSSL_new(ctx);
  79043. ExpectNotNull(ssl);
  79044. /* listen and accept */
  79045. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  79046. CloseSocket(sfd);
  79047. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  79048. if (callbacks->ssl_ready)
  79049. callbacks->ssl_ready(ssl);
  79050. if (EXPECT_SUCCESS()) {
  79051. do {
  79052. err = 0; /* Reset error */
  79053. ret = wolfSSL_accept(ssl);
  79054. if (ret != WOLFSSL_SUCCESS) {
  79055. err = wolfSSL_get_error(ssl, 0);
  79056. }
  79057. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79058. }
  79059. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79060. /* read and write data */
  79061. XMEMSET(input, 0, sizeof(input));
  79062. while (EXPECT_SUCCESS()) {
  79063. ret = wolfSSL_read(ssl, input, sizeof(input));
  79064. if (ret > 0) {
  79065. break;
  79066. }
  79067. else {
  79068. err = wolfSSL_get_error(ssl,ret);
  79069. if (err == WOLFSSL_ERROR_WANT_READ) {
  79070. continue;
  79071. }
  79072. break;
  79073. }
  79074. }
  79075. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  79076. do {
  79077. ret = wolfSSL_write(ssl, msg, len);
  79078. if (ret > 0) {
  79079. break;
  79080. }
  79081. } while (ret < 0);
  79082. }
  79083. /* bidirectional shutdown */
  79084. while (EXPECT_SUCCESS()) {
  79085. ret = wolfSSL_shutdown(ssl);
  79086. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79087. if (ret == WOLFSSL_SUCCESS) {
  79088. break;
  79089. }
  79090. }
  79091. if (EXPECT_SUCCESS()) {
  79092. /* wait for the peer to disconnect the tcp connection */
  79093. do {
  79094. ret = wolfSSL_read(ssl, input, sizeof(input));
  79095. err = wolfSSL_get_error(ssl, ret);
  79096. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  79097. }
  79098. /* detect TCP disconnect */
  79099. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79100. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  79101. ((func_args*)args)->return_code = EXPECT_RESULT();
  79102. wolfSSL_free(ssl);
  79103. wolfSSL_CTX_free(ctx);
  79104. CloseSocket(cfd);
  79105. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79106. wc_ecc_fp_free(); /* free per thread cache */
  79107. #endif
  79108. WOLFSSL_RETURN_FROM_THREAD(0);
  79109. }
  79110. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  79111. {
  79112. EXPECT_DECLS;
  79113. callback_functions* callbacks = NULL;
  79114. WOLFSSL_CTX* ctx = NULL;
  79115. WOLFSSL* ssl = NULL;
  79116. SOCKET_T sfd = 0;
  79117. char msg[] = "hello wolfssl server!";
  79118. int len = (int) XSTRLEN(msg);
  79119. char input[1024];
  79120. int idx;
  79121. int ret, err;
  79122. if (!args)
  79123. WOLFSSL_RETURN_FROM_THREAD(0);
  79124. ((func_args*)args)->return_code = TEST_FAIL;
  79125. callbacks = ((func_args*)args)->callbacks;
  79126. ctx = wolfSSL_CTX_new(callbacks->method());
  79127. #ifdef WOLFSSL_TIRTOS
  79128. fdOpenSession(Task_self());
  79129. #endif
  79130. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79131. caCertFile, 0));
  79132. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79133. cliCertFile, WOLFSSL_FILETYPE_PEM));
  79134. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79135. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  79136. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  79137. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  79138. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  79139. if (EXPECT_SUCCESS()) {
  79140. do {
  79141. err = 0; /* Reset error */
  79142. ret = wolfSSL_connect(ssl);
  79143. if (ret != WOLFSSL_SUCCESS) {
  79144. err = wolfSSL_get_error(ssl, 0);
  79145. }
  79146. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79147. }
  79148. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  79149. if (EXPECT_SUCCESS()) {
  79150. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  79151. input[idx] = 0;
  79152. }
  79153. }
  79154. if (EXPECT_SUCCESS()) {
  79155. ret = wolfSSL_shutdown(ssl);
  79156. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  79157. ret = wolfSSL_shutdown(ssl);
  79158. }
  79159. }
  79160. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79161. ((func_args*)args)->return_code = EXPECT_RESULT();
  79162. wolfSSL_free(ssl);
  79163. wolfSSL_CTX_free(ctx);
  79164. CloseSocket(sfd);
  79165. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79166. wc_ecc_fp_free(); /* free per thread cache */
  79167. #endif
  79168. WOLFSSL_RETURN_FROM_THREAD(0);
  79169. }
  79170. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  79171. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  79172. /* This test is to check wolfSSL_read behaves as same as
  79173. * openSSL when it is called after SSL_shutdown completes.
  79174. */
  79175. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  79176. {
  79177. EXPECT_DECLS;
  79178. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  79179. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  79180. tcp_ready ready;
  79181. func_args client_args;
  79182. func_args server_args;
  79183. THREAD_TYPE serverThread;
  79184. THREAD_TYPE clientThread;
  79185. callback_functions server_cbf;
  79186. callback_functions client_cbf;
  79187. #ifdef WOLFSSL_TIRTOS
  79188. fdOpenSession(Task_self());
  79189. #endif
  79190. StartTCP();
  79191. InitTcpReady(&ready);
  79192. #if defined(USE_WINDOWS_API)
  79193. /* use RNG to get random port if using windows */
  79194. ready.port = GetRandomPort();
  79195. #endif
  79196. XMEMSET(&client_args, 0, sizeof(func_args));
  79197. XMEMSET(&server_args, 0, sizeof(func_args));
  79198. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  79199. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  79200. server_cbf.method = wolfTLSv1_2_server_method;
  79201. client_cbf.method = wolfTLSv1_2_client_method;
  79202. server_args.callbacks = &server_cbf;
  79203. client_args.callbacks = &client_cbf;
  79204. server_args.signal = &ready;
  79205. client_args.signal = &ready;
  79206. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  79207. wait_tcp_ready(&server_args);
  79208. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  79209. join_thread(clientThread);
  79210. join_thread(serverThread);
  79211. ExpectTrue(client_args.return_code);
  79212. ExpectTrue(server_args.return_code);
  79213. FreeTcpReady(&ready);
  79214. #endif
  79215. return EXPECT_RESULT();
  79216. }
  79217. static int test_wolfSSL_CTX_get_min_proto_version(void)
  79218. {
  79219. EXPECT_DECLS;
  79220. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  79221. WOLFSSL_CTX *ctx = NULL;
  79222. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79223. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  79224. WOLFSSL_SUCCESS);
  79225. #ifdef WOLFSSL_ALLOW_SSLV3
  79226. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  79227. #else
  79228. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  79229. #endif
  79230. wolfSSL_CTX_free(ctx);
  79231. ctx = NULL;
  79232. #ifndef NO_OLD_TLS
  79233. #ifdef WOLFSSL_ALLOW_TLSV10
  79234. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  79235. #else
  79236. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79237. #endif
  79238. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  79239. WOLFSSL_SUCCESS);
  79240. #ifdef WOLFSSL_ALLOW_TLSV10
  79241. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  79242. #else
  79243. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  79244. #endif
  79245. wolfSSL_CTX_free(ctx);
  79246. ctx = NULL;
  79247. #endif
  79248. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79249. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  79250. WOLFSSL_SUCCESS);
  79251. #ifndef NO_OLD_TLS
  79252. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  79253. #else
  79254. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  79255. #endif
  79256. wolfSSL_CTX_free(ctx);
  79257. ctx = NULL;
  79258. #ifndef WOLFSSL_NO_TLS12
  79259. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  79260. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  79261. WOLFSSL_SUCCESS);
  79262. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  79263. wolfSSL_CTX_free(ctx);
  79264. ctx = NULL;
  79265. #endif
  79266. #ifdef WOLFSSL_TLS13
  79267. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  79268. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  79269. WOLFSSL_SUCCESS);
  79270. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  79271. wolfSSL_CTX_free(ctx);
  79272. ctx = NULL;
  79273. #endif
  79274. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79275. return EXPECT_RESULT();
  79276. }
  79277. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79278. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79279. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79280. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  79281. static int test_wolfSSL_set_SSL_CTX(void)
  79282. {
  79283. EXPECT_DECLS;
  79284. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  79285. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  79286. !defined(NO_RSA)
  79287. WOLFSSL_CTX *ctx1 = NULL;
  79288. WOLFSSL_CTX *ctx2 = NULL;
  79289. WOLFSSL *ssl = NULL;
  79290. const byte *session_id1 = (const byte *)"CTX1";
  79291. const byte *session_id2 = (const byte *)"CTX2";
  79292. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79293. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  79294. WOLFSSL_FILETYPE_PEM));
  79295. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  79296. WOLFSSL_FILETYPE_PEM));
  79297. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  79298. WOLFSSL_SUCCESS);
  79299. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  79300. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  79301. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  79302. WOLFSSL_SUCCESS);
  79303. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79304. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  79305. WOLFSSL_FILETYPE_PEM));
  79306. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  79307. WOLFSSL_FILETYPE_PEM));
  79308. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  79309. WOLFSSL_SUCCESS);
  79310. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  79311. WOLFSSL_SUCCESS);
  79312. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  79313. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  79314. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  79315. WOLFSSL_SUCCESS);
  79316. #ifdef HAVE_SESSION_TICKET
  79317. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  79318. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  79319. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  79320. #endif
  79321. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  79322. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79323. #ifdef WOLFSSL_INT_H
  79324. #ifdef WOLFSSL_SESSION_ID_CTX
  79325. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  79326. #endif
  79327. #ifdef WOLFSSL_COPY_CERT
  79328. if (ctx2 != NULL && ctx2->certificate != NULL) {
  79329. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  79330. }
  79331. if (ctx2 != NULL && ctx2->certChain != NULL) {
  79332. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  79333. }
  79334. #else
  79335. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  79336. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  79337. #endif
  79338. #endif
  79339. #ifdef HAVE_SESSION_TICKET
  79340. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79341. #endif
  79342. /* Set the ctx1 that has TLSv1.3 as max proto version */
  79343. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  79344. /* MUST not change proto versions of ssl */
  79345. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79346. #ifdef HAVE_SESSION_TICKET
  79347. /* MUST not change */
  79348. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79349. #endif
  79350. /* MUST change */
  79351. #ifdef WOLFSSL_INT_H
  79352. #ifdef WOLFSSL_COPY_CERT
  79353. if (ctx1 != NULL && ctx1->certificate != NULL) {
  79354. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  79355. }
  79356. if (ctx1 != NULL && ctx1->certChain != NULL) {
  79357. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  79358. }
  79359. #else
  79360. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  79361. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  79362. #endif
  79363. #ifdef WOLFSSL_SESSION_ID_CTX
  79364. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  79365. #endif
  79366. #endif
  79367. wolfSSL_free(ssl);
  79368. wolfSSL_CTX_free(ctx1);
  79369. wolfSSL_CTX_free(ctx2);
  79370. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79371. return EXPECT_RESULT();
  79372. }
  79373. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79374. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79375. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79376. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  79377. static int test_wolfSSL_security_level(void)
  79378. {
  79379. EXPECT_DECLS;
  79380. #if defined(OPENSSL_EXTRA)
  79381. SSL_CTX *ctx = NULL;
  79382. #ifdef WOLFSSL_TLS13
  79383. #ifdef NO_WOLFSSL_SERVER
  79384. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79385. #else
  79386. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79387. #endif
  79388. SSL_CTX_set_security_level(NULL, 1);
  79389. SSL_CTX_set_security_level(ctx, 1);
  79390. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  79391. /* Stub so nothing happens. */
  79392. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  79393. SSL_CTX_free(ctx);
  79394. #else
  79395. (void)ctx;
  79396. #endif
  79397. #endif
  79398. return EXPECT_RESULT();
  79399. }
  79400. static int test_wolfSSL_SSL_in_init(void)
  79401. {
  79402. EXPECT_DECLS;
  79403. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  79404. SSL_CTX* ctx = NULL;
  79405. SSL* ssl = NULL;
  79406. const char* testCertFile;
  79407. const char* testKeyFile;
  79408. #ifdef WOLFSSL_TLS13
  79409. #ifdef NO_WOLFSSL_SERVER
  79410. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79411. #else
  79412. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79413. #endif
  79414. #else
  79415. #ifdef NO_WOLFSSL_SERVER
  79416. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79417. #else
  79418. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79419. #endif
  79420. #endif
  79421. #ifndef NO_RSA
  79422. testCertFile = svrCertFile;
  79423. testKeyFile = svrKeyFile;
  79424. #elif defined(HAVE_ECC)
  79425. testCertFile = eccCertFile;
  79426. testKeyFile = eccKeyFile;
  79427. #else
  79428. testCertFile = NULL;
  79429. testKeyFile = NULL;
  79430. #endif
  79431. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79432. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79433. SSL_FILETYPE_PEM));
  79434. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79435. SSL_FILETYPE_PEM));
  79436. }
  79437. ExpectNotNull(ssl = SSL_new(ctx));
  79438. ExpectIntEQ(SSL_in_init(ssl), 1);
  79439. SSL_CTX_free(ctx);
  79440. SSL_free(ssl);
  79441. #endif
  79442. return EXPECT_RESULT();
  79443. }
  79444. static int test_wolfSSL_CTX_set_timeout(void)
  79445. {
  79446. EXPECT_DECLS;
  79447. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  79448. int timeout;
  79449. WOLFSSL_CTX* ctx = NULL;
  79450. (void)timeout;
  79451. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79452. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  79453. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  79454. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  79455. */
  79456. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79457. /* giving 0 as timeout value sets default timeout */
  79458. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  79459. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  79460. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  79461. #else
  79462. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79463. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  79464. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  79465. #endif
  79466. wolfSSL_CTX_free(ctx);
  79467. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  79468. return EXPECT_RESULT();
  79469. }
  79470. static int test_wolfSSL_OpenSSL_version(void)
  79471. {
  79472. EXPECT_DECLS;
  79473. #if defined(OPENSSL_EXTRA)
  79474. const char* ver;
  79475. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  79476. ExpectNotNull(ver = OpenSSL_version(0));
  79477. #else
  79478. ExpectNotNull(ver = OpenSSL_version());
  79479. #endif
  79480. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  79481. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  79482. #endif
  79483. return EXPECT_RESULT();
  79484. }
  79485. static int test_CONF_CTX_CMDLINE(void)
  79486. {
  79487. EXPECT_DECLS;
  79488. #if defined(OPENSSL_ALL)
  79489. SSL_CTX* ctx = NULL;
  79490. SSL_CONF_CTX* cctx = NULL;
  79491. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79492. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79493. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79494. /* set flags */
  79495. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  79496. WOLFSSL_CONF_FLAG_CMDLINE);
  79497. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79498. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79499. /* cmd invalid command */
  79500. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79501. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79502. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79503. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79504. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79505. /* cmd Certificate and Private Key*/
  79506. {
  79507. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79508. const char* ourCert = svrCertFile;
  79509. const char* ourKey = svrKeyFile;
  79510. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  79511. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  79512. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  79513. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  79514. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79515. #endif
  79516. }
  79517. /* cmd curves */
  79518. {
  79519. #if defined(HAVE_ECC)
  79520. const char* curve = "secp256r1";
  79521. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  79522. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  79523. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79524. #endif
  79525. }
  79526. /* cmd CipherString */
  79527. {
  79528. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79529. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  79530. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  79531. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79532. }
  79533. /* cmd DH parameter */
  79534. {
  79535. #if !defined(NO_DH) && !defined(NO_BIO)
  79536. const char* ourdhcert = "./certs/dh2048.pem";
  79537. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  79538. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  79539. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79540. #endif
  79541. }
  79542. SSL_CTX_free(ctx);
  79543. SSL_CONF_CTX_free(cctx);
  79544. #endif /* OPENSSL_EXTRA */
  79545. return EXPECT_RESULT();
  79546. }
  79547. static int test_CONF_CTX_FILE(void)
  79548. {
  79549. EXPECT_DECLS;
  79550. #if defined(OPENSSL_ALL)
  79551. SSL_CTX* ctx = NULL;
  79552. SSL_CONF_CTX* cctx = NULL;
  79553. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79554. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79555. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79556. /* set flags */
  79557. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  79558. WOLFSSL_CONF_FLAG_FILE);
  79559. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79560. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79561. /* sanity check */
  79562. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79563. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79564. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79565. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79566. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79567. /* cmd Certificate and Private Key*/
  79568. {
  79569. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79570. const char* ourCert = svrCertFile;
  79571. const char* ourKey = svrKeyFile;
  79572. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  79573. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  79574. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  79575. WOLFSSL_SUCCESS);
  79576. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  79577. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79578. #endif
  79579. }
  79580. /* cmd curves */
  79581. {
  79582. #if defined(HAVE_ECC)
  79583. const char* curve = "secp256r1";
  79584. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  79585. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  79586. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79587. #endif
  79588. }
  79589. /* cmd CipherString */
  79590. {
  79591. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79592. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  79593. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  79594. WOLFSSL_SUCCESS);
  79595. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79596. }
  79597. /* cmd DH parameter */
  79598. {
  79599. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  79600. const char* ourdhcert = "./certs/dh3072.pem";
  79601. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  79602. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  79603. WOLFSSL_SUCCESS);
  79604. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79605. #endif
  79606. }
  79607. SSL_CTX_free(ctx);
  79608. SSL_CONF_CTX_free(cctx);
  79609. #endif /* OPENSSL_EXTRA */
  79610. return EXPECT_RESULT();
  79611. }
  79612. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  79613. {
  79614. EXPECT_DECLS;
  79615. #ifdef HAVE_EX_DATA
  79616. int idx1, idx2;
  79617. /* test for unsupported class index */
  79618. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  79619. 0,NULL, NULL, NULL, NULL ), -1);
  79620. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  79621. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  79622. 0,NULL, NULL, NULL, NULL ), -1);
  79623. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  79624. 0,NULL, NULL, NULL, NULL ), -1);
  79625. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  79626. 0,NULL, NULL, NULL, NULL ), -1);
  79627. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  79628. 0,NULL, NULL, NULL, NULL ), -1);
  79629. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  79630. 0,NULL, NULL, NULL, NULL ), -1);
  79631. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  79632. 0,NULL, NULL, NULL, NULL ), -1);
  79633. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  79634. 0,NULL, NULL, NULL, NULL ), -1);
  79635. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  79636. 0,NULL, NULL, NULL, NULL ), -1);
  79637. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  79638. 0,NULL, NULL, NULL, NULL ), -1);
  79639. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  79640. 0,NULL, NULL, NULL, NULL ), -1);
  79641. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  79642. 0,NULL, NULL, NULL, NULL ), -1);
  79643. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  79644. 0,NULL, NULL, NULL, NULL ), -1);
  79645. /* test for supported class index */
  79646. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79647. 0,NULL, NULL, NULL, NULL );
  79648. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79649. 0,NULL, NULL, NULL, NULL );
  79650. ExpectIntNE(idx1, -1);
  79651. ExpectIntNE(idx2, -1);
  79652. ExpectIntNE(idx1, idx2);
  79653. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79654. 0,NULL, NULL, NULL, NULL );
  79655. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79656. 0,NULL, NULL, NULL, NULL );
  79657. ExpectIntNE(idx1, -1);
  79658. ExpectIntNE(idx2, -1);
  79659. ExpectIntNE(idx1, idx2);
  79660. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79661. 0,NULL, NULL, NULL, NULL );
  79662. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79663. 0,NULL, NULL, NULL, NULL );
  79664. ExpectIntNE(idx1, -1);
  79665. ExpectIntNE(idx2, -1);
  79666. ExpectIntNE(idx1, idx2);
  79667. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79668. 0,NULL, NULL, NULL, NULL );
  79669. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79670. 0,NULL, NULL, NULL, NULL );
  79671. ExpectIntNE(idx1, -1);
  79672. ExpectIntNE(idx2, -1);
  79673. ExpectIntNE(idx1, idx2);
  79674. #endif /* HAVE_EX_DATA */
  79675. return EXPECT_RESULT();
  79676. }
  79677. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  79678. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79679. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79680. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79681. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  79682. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  79683. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  79684. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  79685. #define SESSION_NEW_IDX_PTR "Testing"
  79686. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  79687. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79688. {
  79689. AssertNotNull(p);
  79690. AssertNull(ptr);
  79691. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  79692. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79693. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  79694. }
  79695. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  79696. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  79697. void* arg)
  79698. {
  79699. EXPECT_DECLS;
  79700. ExpectNotNull(out);
  79701. ExpectNotNull(in);
  79702. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  79703. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  79704. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  79705. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  79706. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79707. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  79708. if (EXPECT_SUCCESS()) {
  79709. return SSL_SUCCESS;
  79710. }
  79711. else {
  79712. return SSL_FAILURE;
  79713. }
  79714. }
  79715. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  79716. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  79717. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79718. {
  79719. EXPECT_DECLS;
  79720. ExpectNotNull(p);
  79721. ExpectNull(ptr);
  79722. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  79723. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79724. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79725. if (EXPECT_SUCCESS()) {
  79726. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  79727. }
  79728. }
  79729. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79730. {
  79731. EXPECT_DECLS;
  79732. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  79733. (void*)SESSION_NEW_IDX_PTR,
  79734. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  79735. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  79736. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  79737. SSL_SESSION* s = SSL_SESSION_new();
  79738. SSL_SESSION* d = NULL;
  79739. ExpectNotNull(s);
  79740. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  79741. ExpectNotNull(d = SSL_SESSION_dup(s));
  79742. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  79743. SSL_SESSION_free(s);
  79744. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  79745. SSL_SESSION_free(d);
  79746. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  79747. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  79748. crypto_ex_cb_ctx_session = NULL;
  79749. return EXPECT_RESULT();
  79750. }
  79751. #else
  79752. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79753. {
  79754. return TEST_SKIPPED;
  79755. }
  79756. #endif
  79757. static int test_wolfSSL_set_psk_use_session_callback(void)
  79758. {
  79759. EXPECT_DECLS;
  79760. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  79761. SSL_CTX* ctx = NULL;
  79762. SSL* ssl = NULL;
  79763. const char* testCertFile;
  79764. const char* testKeyFile;
  79765. #ifdef WOLFSSL_TLS13
  79766. #ifdef NO_WOLFSSL_SERVER
  79767. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79768. #else
  79769. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79770. #endif
  79771. #else
  79772. #ifdef NO_WOLFSSL_SERVER
  79773. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79774. #else
  79775. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79776. #endif
  79777. #endif
  79778. #ifndef NO_RSA
  79779. testCertFile = svrCertFile;
  79780. testKeyFile = svrKeyFile;
  79781. #elif defined(HAVE_ECC)
  79782. testCertFile = eccCertFile;
  79783. testKeyFile = eccKeyFile;
  79784. #else
  79785. testCertFile = NULL;
  79786. testKeyFile = NULL;
  79787. #endif
  79788. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79789. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79790. SSL_FILETYPE_PEM));
  79791. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79792. SSL_FILETYPE_PEM));
  79793. }
  79794. ExpectNotNull(ssl = SSL_new(ctx));
  79795. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  79796. SSL_CTX_free(ctx);
  79797. SSL_free(ssl);
  79798. #endif
  79799. return EXPECT_RESULT();
  79800. }
  79801. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  79802. * TLS layer.
  79803. */
  79804. static int error_test(void)
  79805. {
  79806. EXPECT_DECLS;
  79807. const char* errStr;
  79808. const char* unknownStr = wc_GetErrorString(0);
  79809. #ifdef NO_ERROR_STRINGS
  79810. /* Ensure a valid error code's string matches an invalid code's.
  79811. * The string is that error strings are not available.
  79812. */
  79813. errStr = wc_GetErrorString(OPEN_RAN_E);
  79814. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79815. if (EXPECT_FAIL())
  79816. return OPEN_RAN_E;
  79817. #else
  79818. int i;
  79819. int j = 0;
  79820. /* Values that are not or no longer error codes. */
  79821. static const struct {
  79822. int first;
  79823. int last;
  79824. } missing[] = {
  79825. #ifndef OPENSSL_EXTRA
  79826. { 0, 0 },
  79827. #endif
  79828. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  79829. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  79830. { -11, -12 },
  79831. { -15, -17 },
  79832. { -19, -19 },
  79833. { -26, -27 },
  79834. { -30, WC_FIRST_E+1 },
  79835. #else
  79836. { -9, WC_FIRST_E+1 },
  79837. #endif
  79838. { -124, -124 },
  79839. { -166, -169 },
  79840. { -300, -300 },
  79841. { -334, -336 },
  79842. { -346, -349 },
  79843. { -356, -356 },
  79844. { -358, -358 },
  79845. { -372, -372 },
  79846. { -384, -384 },
  79847. { -466, -499 },
  79848. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  79849. };
  79850. /* Check that all errors have a string and it's the same through the two
  79851. * APIs. Check that the values that are not errors map to the unknown
  79852. * string.
  79853. */
  79854. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  79855. int this_missing = 0;
  79856. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  79857. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  79858. this_missing = 1;
  79859. break;
  79860. }
  79861. }
  79862. errStr = wolfSSL_ERR_reason_error_string(i);
  79863. if (! this_missing) {
  79864. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  79865. if (EXPECT_FAIL()) {
  79866. return i;
  79867. }
  79868. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  79869. if (EXPECT_FAIL()) {
  79870. return i;
  79871. }
  79872. }
  79873. else {
  79874. j++;
  79875. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79876. if (EXPECT_FAIL()) {
  79877. return i;
  79878. }
  79879. }
  79880. }
  79881. #endif
  79882. return 1;
  79883. }
  79884. static int test_wolfSSL_ERR_strings(void)
  79885. {
  79886. EXPECT_DECLS;
  79887. #if !defined(NO_ERROR_STRINGS)
  79888. const char* err1 = "unsupported cipher suite";
  79889. const char* err2 = "wolfSSL PEM routines";
  79890. const char* err = NULL;
  79891. (void)err;
  79892. (void)err1;
  79893. (void)err2;
  79894. #if defined(OPENSSL_EXTRA)
  79895. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79896. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79897. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79898. ExpectIntEQ((*err == '\0'), 1);
  79899. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  79900. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  79901. #else
  79902. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79903. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79904. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79905. ExpectIntEQ((*err == '\0'), 1);
  79906. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  79907. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  79908. ExpectIntEQ((*err == '\0'), 1);
  79909. #endif
  79910. #endif
  79911. ExpectIntEQ(error_test(), 1);
  79912. return EXPECT_RESULT();
  79913. }
  79914. static int test_wolfSSL_EVP_shake128(void)
  79915. {
  79916. EXPECT_DECLS;
  79917. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79918. defined(WOLFSSL_SHAKE128)
  79919. const EVP_MD* md = NULL;
  79920. ExpectNotNull(md = EVP_shake128());
  79921. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  79922. #endif
  79923. return EXPECT_RESULT();
  79924. }
  79925. static int test_wolfSSL_EVP_shake256(void)
  79926. {
  79927. EXPECT_DECLS;
  79928. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79929. defined(WOLFSSL_SHAKE256)
  79930. const EVP_MD* md = NULL;
  79931. ExpectNotNull(md = EVP_shake256());
  79932. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  79933. #endif
  79934. return EXPECT_RESULT();
  79935. }
  79936. /*
  79937. * Testing EVP digest API with SM3
  79938. */
  79939. static int test_wolfSSL_EVP_sm3(void)
  79940. {
  79941. int res = TEST_SKIPPED;
  79942. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  79943. EXPECT_DECLS;
  79944. const EVP_MD* md = NULL;
  79945. EVP_MD_CTX* mdCtx = NULL;
  79946. byte data[WC_SM3_BLOCK_SIZE * 4];
  79947. byte hash[WC_SM3_DIGEST_SIZE];
  79948. byte calcHash[WC_SM3_DIGEST_SIZE];
  79949. byte expHash[WC_SM3_DIGEST_SIZE] = {
  79950. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  79951. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  79952. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  79953. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  79954. };
  79955. word32 chunk;
  79956. word32 i;
  79957. unsigned int sz;
  79958. int ret;
  79959. XMEMSET(data, 0, sizeof(data));
  79960. md = EVP_sm3();
  79961. ExpectTrue(md != NULL);
  79962. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  79963. mdCtx = EVP_MD_CTX_new();
  79964. ExpectTrue(mdCtx != NULL);
  79965. /* Invalid Parameters */
  79966. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79967. /* Valid Parameters */
  79968. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  79969. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79970. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79971. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79972. /* Valid Parameters */
  79973. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  79974. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79975. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79976. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  79977. WOLFSSL_SUCCESS);
  79978. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  79979. WOLFSSL_SUCCESS);
  79980. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  79981. WOLFSSL_SUCCESS);
  79982. /* Ensure too many bytes for lengths. */
  79983. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  79984. WOLFSSL_SUCCESS);
  79985. /* Invalid Parameters */
  79986. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79987. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79988. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79989. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79990. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79991. /* Valid Parameters */
  79992. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79993. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  79994. /* Chunk tests. */
  79995. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  79996. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  79997. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  79998. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  79999. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  80000. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  80001. WOLFSSL_SUCCESS);
  80002. }
  80003. if (i < (word32)sizeof(data)) {
  80004. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  80005. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  80006. }
  80007. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  80008. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  80009. }
  80010. /* Not testing when the low 32-bit length overflows. */
  80011. ret = EVP_MD_CTX_cleanup(mdCtx);
  80012. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  80013. wolfSSL_EVP_MD_CTX_free(mdCtx);
  80014. res = EXPECT_RESULT();
  80015. #endif
  80016. return res;
  80017. } /* END test_EVP_sm3 */
  80018. static int test_EVP_blake2(void)
  80019. {
  80020. EXPECT_DECLS;
  80021. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  80022. const EVP_MD* md = NULL;
  80023. (void)md;
  80024. #if defined(HAVE_BLAKE2)
  80025. ExpectNotNull(md = EVP_blake2b512());
  80026. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  80027. #endif
  80028. #if defined(HAVE_BLAKE2S)
  80029. ExpectNotNull(md = EVP_blake2s256());
  80030. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  80031. #endif
  80032. #endif
  80033. return EXPECT_RESULT();
  80034. }
  80035. #if defined(OPENSSL_EXTRA)
  80036. static void list_md_fn(const EVP_MD* m, const char* from,
  80037. const char* to, void* arg)
  80038. {
  80039. const char* mn;
  80040. BIO *bio;
  80041. (void) from;
  80042. (void) to;
  80043. (void) arg;
  80044. (void) mn;
  80045. (void) bio;
  80046. if (!m) {
  80047. /* alias */
  80048. AssertNull(m);
  80049. AssertNotNull(to);
  80050. }
  80051. else {
  80052. AssertNotNull(m);
  80053. AssertNull(to);
  80054. }
  80055. AssertNotNull(from);
  80056. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80057. mn = EVP_get_digestbyname(from);
  80058. /* print to stderr */
  80059. AssertNotNull(arg);
  80060. bio = BIO_new(BIO_s_file());
  80061. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80062. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  80063. BIO_free(bio);
  80064. #endif
  80065. }
  80066. #endif
  80067. static int test_EVP_MD_do_all(void)
  80068. {
  80069. int res = TEST_SKIPPED;
  80070. #if defined(OPENSSL_EXTRA)
  80071. EVP_MD_do_all(NULL, stderr);
  80072. EVP_MD_do_all(list_md_fn, stderr);
  80073. res = TEST_SUCCESS;
  80074. #endif
  80075. return res;
  80076. }
  80077. #if defined(OPENSSL_EXTRA)
  80078. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  80079. {
  80080. (void)arg;
  80081. (void)nm;
  80082. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  80083. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80084. /* print to stderr */
  80085. AssertNotNull(arg);
  80086. BIO *bio = BIO_new(BIO_s_file());
  80087. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80088. BIO_printf(bio, "%s\n", nm);
  80089. BIO_free(bio);
  80090. #endif
  80091. }
  80092. #endif
  80093. static int test_OBJ_NAME_do_all(void)
  80094. {
  80095. int res = TEST_SKIPPED;
  80096. #if defined(OPENSSL_EXTRA)
  80097. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  80098. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  80099. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  80100. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  80101. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  80102. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  80103. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  80104. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  80105. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  80106. res = TEST_SUCCESS;
  80107. #endif
  80108. return res;
  80109. }
  80110. static int test_SSL_CIPHER_get_xxx(void)
  80111. {
  80112. EXPECT_DECLS;
  80113. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  80114. !defined(NO_FILESYSTEM)
  80115. const SSL_CIPHER* cipher = NULL;
  80116. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  80117. int i, numCiphers = 0;
  80118. SSL_CTX* ctx = NULL;
  80119. SSL* ssl = NULL;
  80120. const char* testCertFile;
  80121. const char* testKeyFile;
  80122. char buf[256] = {0};
  80123. const char* cipher_id = NULL;
  80124. int expect_nid1 = NID_undef;
  80125. int expect_nid2 = NID_undef;
  80126. int expect_nid3 = NID_undef;
  80127. int expect_nid4 = NID_undef;
  80128. int expect_nid5 = 0;
  80129. const char* cipher_id2 = NULL;
  80130. int expect_nid21 = NID_undef;
  80131. int expect_nid22 = NID_undef;
  80132. int expect_nid23 = NID_undef;
  80133. int expect_nid24 = NID_undef;
  80134. int expect_nid25 = 0;
  80135. (void)cipher;
  80136. (void)supportedCiphers;
  80137. (void)i;
  80138. (void)numCiphers;
  80139. (void)ctx;
  80140. (void)ssl;
  80141. (void)testCertFile;
  80142. (void)testKeyFile;
  80143. #if defined(WOLFSSL_TLS13)
  80144. cipher_id = "TLS13-AES128-GCM-SHA256";
  80145. expect_nid1 = NID_auth_rsa;
  80146. expect_nid2 = NID_aes_128_gcm;
  80147. expect_nid3 = NID_sha256;
  80148. expect_nid4 = NID_kx_any;
  80149. expect_nid5 = 1;
  80150. #if !defined(WOLFSSL_NO_TLS12)
  80151. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  80152. expect_nid21 = NID_auth_rsa;
  80153. expect_nid22 = NID_aes_256_gcm;
  80154. expect_nid23 = NID_sha384;
  80155. expect_nid24 = NID_kx_ecdhe;
  80156. expect_nid25 = 1;
  80157. #endif
  80158. #endif
  80159. #ifdef NO_WOLFSSL_SERVER
  80160. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80161. #else
  80162. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80163. #endif
  80164. if (cipher_id) {
  80165. #ifndef NO_RSA
  80166. testCertFile = svrCertFile;
  80167. testKeyFile = svrKeyFile;
  80168. #elif defined(HAVE_ECC)
  80169. testCertFile = eccCertFile;
  80170. testKeyFile = eccKeyFile;
  80171. #else
  80172. testCertFile = NULL;
  80173. testKeyFile = NULL;
  80174. #endif
  80175. if (testCertFile != NULL && testKeyFile != NULL) {
  80176. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80177. SSL_FILETYPE_PEM));
  80178. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80179. SSL_FILETYPE_PEM));
  80180. }
  80181. ExpectNotNull(ssl = SSL_new(ctx));
  80182. ExpectIntEQ(SSL_in_init(ssl), 1);
  80183. supportedCiphers = SSL_get_ciphers(ssl);
  80184. numCiphers = sk_num(supportedCiphers);
  80185. for (i = 0; i < numCiphers; ++i) {
  80186. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  80187. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  80188. }
  80189. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  80190. break;
  80191. }
  80192. }
  80193. /* test case for */
  80194. if (i != numCiphers) {
  80195. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  80196. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  80197. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  80198. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  80199. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  80200. }
  80201. if (cipher_id2) {
  80202. for (i = 0; i < numCiphers; ++i) {
  80203. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  80204. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  80205. }
  80206. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  80207. break;
  80208. }
  80209. }
  80210. /* test case for */
  80211. if (i != numCiphers) {
  80212. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  80213. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  80214. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  80215. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  80216. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  80217. }
  80218. }
  80219. }
  80220. SSL_CTX_free(ctx);
  80221. SSL_free(ssl);
  80222. #endif
  80223. return EXPECT_RESULT();
  80224. }
  80225. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80226. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  80227. int* keyFormat)
  80228. {
  80229. int ret;
  80230. byte* key_buf = NULL;
  80231. size_t key_sz = 0;
  80232. EncryptedInfo encInfo;
  80233. XMEMSET(&encInfo, 0, sizeof(encInfo));
  80234. ret = load_file(privKeyFile, &key_buf, &key_sz);
  80235. if (ret == 0) {
  80236. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  80237. NULL, &encInfo, keyFormat);
  80238. }
  80239. if (key_buf != NULL) {
  80240. free(key_buf); key_buf = NULL;
  80241. }
  80242. (void)encInfo; /* not used in this test */
  80243. #ifdef DEBUG_WOLFSSL
  80244. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  80245. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  80246. (*pDer)->length);
  80247. #endif
  80248. return ret;
  80249. }
  80250. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  80251. {
  80252. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  80253. const char* privKeyFile = (const char*)ctx;
  80254. DerBuffer* pDer = NULL;
  80255. int keyFormat = 0;
  80256. if (info->algo_type == WC_ALGO_TYPE_PK) {
  80257. #ifdef DEBUG_WOLFSSL
  80258. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  80259. #endif
  80260. #ifndef NO_RSA
  80261. if (info->pk.type == WC_PK_TYPE_RSA) {
  80262. switch (info->pk.rsa.type) {
  80263. case RSA_PUBLIC_ENCRYPT:
  80264. case RSA_PUBLIC_DECRYPT:
  80265. /* perform software based RSA public op */
  80266. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  80267. break;
  80268. case RSA_PRIVATE_ENCRYPT:
  80269. case RSA_PRIVATE_DECRYPT:
  80270. {
  80271. RsaKey key;
  80272. /* perform software based RSA private op */
  80273. #ifdef DEBUG_WOLFSSL
  80274. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  80275. #endif
  80276. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80277. &keyFormat);
  80278. if (ret != 0) {
  80279. return ret;
  80280. }
  80281. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80282. if (ret == 0) {
  80283. word32 keyIdx = 0;
  80284. /* load RSA private key and perform private transform */
  80285. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80286. &key, pDer->length);
  80287. if (ret == 0) {
  80288. ret = wc_RsaFunction(
  80289. info->pk.rsa.in, info->pk.rsa.inLen,
  80290. info->pk.rsa.out, info->pk.rsa.outLen,
  80291. info->pk.rsa.type, &key, info->pk.rsa.rng);
  80292. }
  80293. else {
  80294. /* if decode fails, then fall-back to software based crypto */
  80295. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  80296. "key decode failed %d, falling back to "
  80297. "software\n", ret);
  80298. ret = CRYPTOCB_UNAVAILABLE;
  80299. }
  80300. wc_FreeRsaKey(&key);
  80301. }
  80302. wc_FreeDer(&pDer); pDer = NULL;
  80303. break;
  80304. }
  80305. }
  80306. #ifdef DEBUG_WOLFSSL
  80307. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  80308. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  80309. #endif
  80310. }
  80311. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  80312. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  80313. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  80314. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  80315. RsaKey key;
  80316. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  80317. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  80318. /* Have all public key ops fall back to SW */
  80319. return CRYPTOCB_UNAVAILABLE;
  80320. }
  80321. if (info->pk.rsa.padding == NULL) {
  80322. return BAD_FUNC_ARG;
  80323. }
  80324. /* Initialize key */
  80325. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80326. &keyFormat);
  80327. if (ret != 0) {
  80328. return ret;
  80329. }
  80330. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80331. if (ret == 0) {
  80332. word32 keyIdx = 0;
  80333. /* load RSA private key and perform private transform */
  80334. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80335. &key, pDer->length);
  80336. }
  80337. /* Perform RSA operation */
  80338. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  80339. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  80340. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  80341. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  80342. info->pk.rsa.rng);
  80343. #else
  80344. ret = CRYPTOCB_UNAVAILABLE;
  80345. #endif
  80346. }
  80347. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  80348. #ifdef WC_RSA_PSS
  80349. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  80350. info->pk.rsa.out, *info->pk.rsa.outLen,
  80351. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  80352. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  80353. #else
  80354. ret = CRYPTOCB_UNAVAILABLE;
  80355. #endif
  80356. }
  80357. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  80358. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  80359. ret = wc_RsaPrivateDecrypt_ex(
  80360. info->pk.rsa.in, info->pk.rsa.inLen,
  80361. info->pk.rsa.out, *info->pk.rsa.outLen,
  80362. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  80363. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  80364. info->pk.rsa.padding->labelSz);
  80365. #else
  80366. ret = CRYPTOCB_UNAVAILABLE;
  80367. #endif
  80368. }
  80369. if (ret > 0) {
  80370. *info->pk.rsa.outLen = ret;
  80371. }
  80372. wc_FreeRsaKey(&key);
  80373. wc_FreeDer(&pDer); pDer = NULL;
  80374. }
  80375. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  80376. #endif /* !NO_RSA */
  80377. #ifdef HAVE_ECC
  80378. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  80379. /* mark this key as ephemeral */
  80380. if (info->pk.eckg.key != NULL) {
  80381. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  80382. sizeof(info->pk.eckg.key->label));
  80383. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  80384. }
  80385. }
  80386. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  80387. ecc_key key;
  80388. /* perform software based ECC sign */
  80389. #ifdef DEBUG_WOLFSSL
  80390. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  80391. #endif
  80392. if (info->pk.eccsign.key != NULL &&
  80393. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  80394. /* this is an empheral key */
  80395. #ifdef DEBUG_WOLFSSL
  80396. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  80397. "ephemeral key\n");
  80398. #endif
  80399. return CRYPTOCB_UNAVAILABLE;
  80400. }
  80401. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80402. if (ret != 0) {
  80403. return ret;
  80404. }
  80405. ret = wc_ecc_init(&key);
  80406. if (ret == 0) {
  80407. word32 keyIdx = 0;
  80408. /* load ECC private key and perform private transform */
  80409. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  80410. &key, pDer->length);
  80411. if (ret == 0) {
  80412. ret = wc_ecc_sign_hash(
  80413. info->pk.eccsign.in, info->pk.eccsign.inlen,
  80414. info->pk.eccsign.out, info->pk.eccsign.outlen,
  80415. info->pk.eccsign.rng, &key);
  80416. }
  80417. else {
  80418. /* if decode fails, then fall-back to software based crypto */
  80419. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  80420. "decode failed %d, falling back to software\n", ret);
  80421. ret = CRYPTOCB_UNAVAILABLE;
  80422. }
  80423. wc_ecc_free(&key);
  80424. }
  80425. wc_FreeDer(&pDer); pDer = NULL;
  80426. #ifdef DEBUG_WOLFSSL
  80427. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  80428. ret, *info->pk.eccsign.outlen);
  80429. #endif
  80430. }
  80431. #endif /* HAVE_ECC */
  80432. #ifdef HAVE_ED25519
  80433. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  80434. ed25519_key key;
  80435. /* perform software based ED25519 sign */
  80436. #ifdef DEBUG_WOLFSSL
  80437. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  80438. #endif
  80439. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80440. if (ret != 0) {
  80441. return ret;
  80442. }
  80443. ret = wc_ed25519_init(&key);
  80444. if (ret == 0) {
  80445. word32 keyIdx = 0;
  80446. /* load ED25519 private key and perform private transform */
  80447. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  80448. &key, pDer->length);
  80449. if (ret == 0) {
  80450. /* calculate public key */
  80451. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  80452. if (ret == 0) {
  80453. key.pubKeySet = 1;
  80454. ret = wc_ed25519_sign_msg_ex(
  80455. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  80456. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  80457. &key, info->pk.ed25519sign.type,
  80458. info->pk.ed25519sign.context,
  80459. info->pk.ed25519sign.contextLen);
  80460. }
  80461. }
  80462. else {
  80463. /* if decode fails, then fall-back to software based crypto */
  80464. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  80465. "decode failed %d, falling back to software\n", ret);
  80466. ret = CRYPTOCB_UNAVAILABLE;
  80467. }
  80468. wc_ed25519_free(&key);
  80469. }
  80470. wc_FreeDer(&pDer); pDer = NULL;
  80471. #ifdef DEBUG_WOLFSSL
  80472. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  80473. ret, *info->pk.ed25519sign.outLen);
  80474. #endif
  80475. }
  80476. #endif /* HAVE_ED25519 */
  80477. }
  80478. (void)thisDevId;
  80479. (void)keyFormat;
  80480. return ret;
  80481. }
  80482. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80483. static int test_wc_CryptoCb_TLS(int tlsVer,
  80484. const char* cliCaPemFile, const char* cliCertPemFile,
  80485. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  80486. const char* svrCaPemFile, const char* svrCertPemFile,
  80487. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  80488. {
  80489. EXPECT_DECLS;
  80490. callback_functions client_cbf;
  80491. callback_functions server_cbf;
  80492. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80493. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80494. if (tlsVer == WOLFSSL_TLSV1_3) {
  80495. #ifdef WOLFSSL_TLS13
  80496. server_cbf.method = wolfTLSv1_3_server_method;
  80497. client_cbf.method = wolfTLSv1_3_client_method;
  80498. #endif
  80499. }
  80500. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80501. #ifndef WOLFSSL_NO_TLS12
  80502. server_cbf.method = wolfTLSv1_2_server_method;
  80503. client_cbf.method = wolfTLSv1_2_client_method;
  80504. #endif
  80505. }
  80506. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80507. #ifndef NO_OLD_TLS
  80508. server_cbf.method = wolfTLSv1_1_server_method;
  80509. client_cbf.method = wolfTLSv1_1_client_method;
  80510. #endif
  80511. }
  80512. else if (tlsVer == WOLFSSL_TLSV1) {
  80513. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80514. server_cbf.method = wolfTLSv1_server_method;
  80515. client_cbf.method = wolfTLSv1_client_method;
  80516. #endif
  80517. }
  80518. else if (tlsVer == WOLFSSL_SSLV3) {
  80519. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80520. defined(WOLFSSL_STATIC_RSA)
  80521. server_cbf.method = wolfSSLv3_server_method;
  80522. client_cbf.method = wolfSSLv3_client_method;
  80523. #endif
  80524. }
  80525. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80526. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80527. server_cbf.method = wolfDTLSv1_2_server_method;
  80528. client_cbf.method = wolfDTLSv1_2_client_method;
  80529. #endif
  80530. }
  80531. else if (tlsVer == WOLFSSL_DTLSV1) {
  80532. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80533. server_cbf.method = wolfDTLSv1_server_method;
  80534. client_cbf.method = wolfDTLSv1_client_method;
  80535. #endif
  80536. }
  80537. if (server_cbf.method == NULL) {
  80538. /* not enabled */
  80539. return TEST_SUCCESS;
  80540. }
  80541. /* Setup the keys for the TLS test */
  80542. client_cbf.certPemFile = cliCertPemFile;
  80543. client_cbf.keyPemFile = cliPubKeyPemFile;
  80544. client_cbf.caPemFile = cliCaPemFile;
  80545. server_cbf.certPemFile = svrCertPemFile;
  80546. server_cbf.keyPemFile = svrPubKeyPemFile;
  80547. server_cbf.caPemFile = svrCaPemFile;
  80548. /* Setup a crypto callback with pointer to private key file for testing */
  80549. client_cbf.devId = 1;
  80550. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  80551. (void*)cliPrivKeyPemFile);
  80552. server_cbf.devId = 2;
  80553. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  80554. (void*)svrPrivKeyPemFile);
  80555. /* Perform TLS server and client test */
  80556. /* First test is at WOLFSSL_CTX level */
  80557. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80558. /* Check for success */
  80559. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80560. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80561. if (EXPECT_SUCCESS()) {
  80562. /* Second test is a WOLFSSL object level */
  80563. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80564. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80565. }
  80566. /* Check for success */
  80567. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80568. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80569. /* Un register the devId's */
  80570. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  80571. client_cbf.devId = INVALID_DEVID;
  80572. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  80573. server_cbf.devId = INVALID_DEVID;
  80574. return EXPECT_RESULT();
  80575. }
  80576. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  80577. static int test_wc_CryptoCb(void)
  80578. {
  80579. EXPECT_DECLS;
  80580. #ifdef WOLF_CRYPTO_CB
  80581. /* TODO: Add crypto callback API tests */
  80582. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80583. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80584. int tlsVer;
  80585. #endif
  80586. #ifndef NO_RSA
  80587. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80588. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80589. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  80590. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  80591. TEST_SUCCESS);
  80592. }
  80593. #endif
  80594. #ifdef HAVE_ECC
  80595. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80596. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80597. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  80598. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  80599. TEST_SUCCESS);
  80600. }
  80601. #endif
  80602. #ifdef HAVE_ED25519
  80603. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80604. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80605. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80606. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  80607. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  80608. TEST_SUCCESS);
  80609. }
  80610. #endif
  80611. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80612. #endif /* WOLF_CRYPTO_CB */
  80613. return EXPECT_RESULT();
  80614. }
  80615. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80616. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80617. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  80618. const char* cliCaPemFile, const char* cliCertPemFile,
  80619. const char* cliPrivKeyPemFile,
  80620. const char* svrCaPemFile, const char* svrCertPemFile,
  80621. const char* svrPrivKeyPemFile,
  80622. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  80623. {
  80624. EXPECT_DECLS;
  80625. callback_functions client_cbf;
  80626. callback_functions server_cbf;
  80627. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80628. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80629. if (tlsVer == WOLFSSL_TLSV1_3) {
  80630. #ifdef WOLFSSL_TLS13
  80631. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  80632. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  80633. #endif
  80634. }
  80635. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80636. #ifndef WOLFSSL_NO_TLS12
  80637. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  80638. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  80639. #endif
  80640. }
  80641. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80642. #ifndef NO_OLD_TLS
  80643. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  80644. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  80645. #endif
  80646. }
  80647. else if (tlsVer == WOLFSSL_TLSV1) {
  80648. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80649. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  80650. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  80651. #endif
  80652. }
  80653. else if (tlsVer == WOLFSSL_SSLV3) {
  80654. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80655. defined(WOLFSSL_STATIC_RSA)
  80656. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  80657. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  80658. #endif
  80659. }
  80660. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80661. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80662. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  80663. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  80664. #endif
  80665. }
  80666. else if (tlsVer == WOLFSSL_DTLSV1) {
  80667. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80668. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  80669. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  80670. #endif
  80671. }
  80672. if (server_cbf.method_ex == NULL) {
  80673. /* not enabled */
  80674. return TEST_SUCCESS;
  80675. }
  80676. /* Setup the keys for the TLS test */
  80677. client_cbf.certPemFile = cliCertPemFile;
  80678. client_cbf.keyPemFile = cliPrivKeyPemFile;
  80679. client_cbf.caPemFile = cliCaPemFile;
  80680. server_cbf.certPemFile = svrCertPemFile;
  80681. server_cbf.keyPemFile = svrPrivKeyPemFile;
  80682. server_cbf.caPemFile = svrCaPemFile;
  80683. client_cbf.mem = cliMem;
  80684. client_cbf.memSz = cliMemSz;
  80685. server_cbf.mem = svrMem;
  80686. server_cbf.memSz = svrMemSz;
  80687. client_cbf.devId = INVALID_DEVID;
  80688. server_cbf.devId = INVALID_DEVID;
  80689. /* Perform TLS server and client test */
  80690. /* First test is at WOLFSSL_CTX level */
  80691. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80692. /* Check for success */
  80693. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80694. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80695. if (EXPECT_SUCCESS()) {
  80696. /* Second test is a WOLFSSL object level */
  80697. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80698. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80699. }
  80700. /* Check for success */
  80701. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80702. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80703. return EXPECT_RESULT();
  80704. }
  80705. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  80706. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80707. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  80708. {
  80709. EXPECT_DECLS;
  80710. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  80711. WOLFSSL_MEM_STATS mem_stats;
  80712. WOLFSSL_MEM_CONN_STATS ssl_stats;
  80713. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  80714. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  80715. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80716. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  80717. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80718. #endif
  80719. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  80720. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  80721. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  80722. /* this should fail because kMaxCtxClients == 2 */
  80723. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  80724. #else
  80725. (void)ssl3;
  80726. #endif
  80727. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  80728. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80729. wolfSSL_PrintStatsConn(&ssl_stats);
  80730. #endif
  80731. (void)ssl_stats;
  80732. }
  80733. /* display collected statistics */
  80734. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  80735. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80736. wolfSSL_PrintStats(&mem_stats);
  80737. #endif
  80738. (void)mem_stats;
  80739. }
  80740. wolfSSL_free(ssl1);
  80741. wolfSSL_free(ssl2);
  80742. return EXPECT_RESULT();
  80743. }
  80744. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80745. static int test_wolfSSL_CTX_StaticMemory(void)
  80746. {
  80747. EXPECT_DECLS;
  80748. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80749. wolfSSL_method_func method_func;
  80750. WOLFSSL_CTX* ctx;
  80751. const int kMaxCtxClients = 2;
  80752. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80753. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80754. int tlsVer;
  80755. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  80756. #endif
  80757. #endif
  80758. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  80759. #ifndef NO_WOLFSSL_SERVER
  80760. #ifndef WOLFSSL_NO_TLS12
  80761. method_func = wolfTLSv1_2_server_method_ex;
  80762. #else
  80763. method_func = wolfTLSv1_3_server_method_ex;
  80764. #endif
  80765. #else
  80766. #ifndef WOLFSSL_NO_TLS12
  80767. method_func = wolfTLSv1_2_client_method_ex;
  80768. #else
  80769. method_func = wolfTLSv1_3_client_method_ex;
  80770. #endif
  80771. #endif
  80772. /* Test creating CTX directly from static memory pool */
  80773. ctx = NULL;
  80774. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  80775. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80776. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80777. wolfSSL_CTX_free(ctx);
  80778. ctx = NULL;
  80779. /* Test for heap allocated CTX, then assigning static pool to it */
  80780. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  80781. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  80782. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80783. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80784. wolfSSL_CTX_free(ctx);
  80785. /* TLS Level Tests using static memory */
  80786. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80787. #ifndef NO_RSA
  80788. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80789. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80790. svrCertFile, cliCertFile, cliKeyFile,
  80791. cliCertFile, svrCertFile, svrKeyFile,
  80792. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80793. TEST_SUCCESS);
  80794. }
  80795. #endif
  80796. #ifdef HAVE_ECC
  80797. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80798. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80799. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  80800. cliEccCertFile, eccCertFile, eccKeyFile,
  80801. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80802. TEST_SUCCESS);
  80803. }
  80804. #endif
  80805. #ifdef HAVE_ED25519
  80806. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80807. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80808. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80809. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  80810. cliEdCertFile, edCertFile, edKeyFile,
  80811. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80812. TEST_SUCCESS);
  80813. }
  80814. #endif
  80815. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80816. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80817. return EXPECT_RESULT();
  80818. }
  80819. static int test_openssl_FIPS_drbg(void)
  80820. {
  80821. EXPECT_DECLS;
  80822. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  80823. DRBG_CTX* dctx = NULL;
  80824. byte data1[32], data2[32], zeroData[32];
  80825. byte testSeed[16];
  80826. size_t dlen = sizeof(data1);
  80827. int i;
  80828. XMEMSET(data1, 0, dlen);
  80829. XMEMSET(data2, 0, dlen);
  80830. XMEMSET(zeroData, 0, sizeof(zeroData));
  80831. for (i = 0; i < (int)sizeof(testSeed); i++) {
  80832. testSeed[i] = (byte)i;
  80833. }
  80834. ExpectNotNull(dctx = FIPS_get_default_drbg());
  80835. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  80836. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  80837. WOLFSSL_SUCCESS);
  80838. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  80839. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  80840. WOLFSSL_SUCCESS);
  80841. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80842. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  80843. WOLFSSL_SUCCESS);
  80844. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  80845. WOLFSSL_SUCCESS);
  80846. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80847. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  80848. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  80849. #ifndef HAVE_GLOBAL_RNG
  80850. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  80851. wolfSSL_FIPS_drbg_free(dctx);
  80852. #endif
  80853. #endif
  80854. return EXPECT_RESULT();
  80855. }
  80856. static int test_wolfSSL_FIPS_mode(void)
  80857. {
  80858. EXPECT_DECLS;
  80859. #if defined(OPENSSL_ALL)
  80860. #ifdef HAVE_FIPS
  80861. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  80862. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80863. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  80864. #else
  80865. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  80866. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  80867. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80868. #endif
  80869. #endif
  80870. return EXPECT_RESULT();
  80871. }
  80872. #ifdef WOLFSSL_DTLS
  80873. /* Prints out the current window */
  80874. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  80875. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80876. int i;
  80877. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  80878. word32 b = w[i];
  80879. int j;
  80880. /* Prints out a 32 bit binary number in big endian order */
  80881. for (j = 0; j < 32; j++, b <<= 1) {
  80882. if (b & (((word32)1) << 31))
  80883. fprintf(stderr, "1");
  80884. else
  80885. fprintf(stderr, "0");
  80886. }
  80887. fprintf(stderr, " ");
  80888. }
  80889. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  80890. #else
  80891. (void)h;
  80892. (void)l;
  80893. (void)w;
  80894. #endif
  80895. }
  80896. /* a - cur_hi
  80897. * b - cur_lo
  80898. * c - next_hi
  80899. * d - next_lo
  80900. * e - window
  80901. * f - expected next_hi
  80902. * g - expected next_lo
  80903. * h - expected window[1]
  80904. * i - expected window[0]
  80905. */
  80906. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  80907. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  80908. DUW_TEST_print_window_binary((a), (b), (e)); \
  80909. ExpectIntEQ((c), (f)); \
  80910. ExpectIntEQ((d), (g)); \
  80911. ExpectIntEQ((e)[1], (h)); \
  80912. ExpectIntEQ((e)[0], (i)); \
  80913. } while (0)
  80914. static int test_wolfSSL_DtlsUpdateWindow(void)
  80915. {
  80916. EXPECT_DECLS;
  80917. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  80918. word32 next_lo = 0;
  80919. word16 next_hi = 0;
  80920. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80921. fprintf(stderr, "\n");
  80922. #endif
  80923. XMEMSET(window, 0, sizeof window);
  80924. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  80925. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  80926. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  80927. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  80928. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  80929. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  80930. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  80931. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  80932. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  80933. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  80934. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  80935. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  80936. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  80937. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  80938. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  80939. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  80940. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  80941. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  80942. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  80943. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  80944. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  80945. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80946. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80947. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  80948. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  80949. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80950. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80951. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80952. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80953. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80954. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  80955. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  80956. return EXPECT_RESULT();
  80957. }
  80958. #endif /* WOLFSSL_DTLS */
  80959. #ifdef WOLFSSL_DTLS
  80960. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  80961. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  80962. {
  80963. DtlsMsg* cur;
  80964. static byte msg[100];
  80965. static byte msgInit = 0;
  80966. if (!msgInit) {
  80967. int i;
  80968. for (i = 0; i < 100; i++)
  80969. msg[i] = i + 1;
  80970. msgInit = 1;
  80971. }
  80972. /* Sanitize test parameters */
  80973. if (len > sizeof(msg))
  80974. return -1;
  80975. if (f_offset + f_len > sizeof(msg))
  80976. return -1;
  80977. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  80978. if (ssl->dtls_rx_msg_list == NULL)
  80979. return -100;
  80980. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  80981. return -200;
  80982. if (cur->fragBucketListCount != f_count)
  80983. return -300;
  80984. if (cur->ready != ready)
  80985. return -400;
  80986. if (cur->bytesReceived != bytesReceived)
  80987. return -500;
  80988. if (ready) {
  80989. if (cur->fragBucketList != NULL)
  80990. return -600;
  80991. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  80992. return -700;
  80993. }
  80994. else {
  80995. DtlsFragBucket* fb;
  80996. if (cur->fragBucketList == NULL)
  80997. return -800;
  80998. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  80999. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  81000. return -900;
  81001. }
  81002. }
  81003. return 0;
  81004. }
  81005. static int test_wolfSSL_DTLS_fragment_buckets(void)
  81006. {
  81007. EXPECT_DECLS;
  81008. WOLFSSL ssl[1];
  81009. XMEMSET(ssl, 0, sizeof(*ssl));
  81010. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  81011. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81012. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  81013. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  81014. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  81015. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  81016. /* Test all permutations of 3 regions */
  81017. /* 1 2 3 */
  81018. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81019. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  81020. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81021. /* 1 3 2 */
  81022. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81023. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  81024. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81025. /* 2 1 3 */
  81026. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81027. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  81028. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81029. /* 2 3 1 */
  81030. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81031. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  81032. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81033. /* 3 1 2 */
  81034. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81035. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  81036. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81037. /* 3 2 1 */
  81038. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81039. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  81040. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81041. /* Test overlapping regions */
  81042. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81043. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  81044. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  81045. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  81046. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  81047. /* Test overlapping multiple regions */
  81048. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81049. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  81050. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  81051. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  81052. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  81053. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  81054. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  81055. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  81056. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  81057. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  81058. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81059. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  81060. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  81061. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  81062. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  81063. ssl->dtls_rx_msg_list = NULL;
  81064. ssl->dtls_rx_msg_list_sz = 0;
  81065. return EXPECT_RESULT();
  81066. }
  81067. #endif
  81068. #if !defined(NO_FILESYSTEM) && \
  81069. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81070. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81071. static int test_wolfSSL_dtls_stateless2(void)
  81072. {
  81073. EXPECT_DECLS;
  81074. WOLFSSL *ssl_c = NULL;
  81075. WOLFSSL *ssl_c2 = NULL;
  81076. WOLFSSL *ssl_s = NULL;
  81077. struct test_memio_ctx test_ctx;
  81078. WOLFSSL_CTX *ctx_c = NULL;
  81079. WOLFSSL_CTX *ctx_s = NULL;
  81080. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81081. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81082. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81083. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81084. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81085. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81086. /* send CH */
  81087. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81088. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81089. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81090. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81091. ExpectIntNE(test_ctx.c_len, 0);
  81092. /* consume HRR */
  81093. test_ctx.c_len = 0;
  81094. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81095. wolfSSL_free(ssl_c2);
  81096. wolfSSL_free(ssl_c);
  81097. wolfSSL_free(ssl_s);
  81098. wolfSSL_CTX_free(ctx_c);
  81099. wolfSSL_CTX_free(ctx_s);
  81100. return EXPECT_RESULT();
  81101. }
  81102. #ifdef HAVE_MAX_FRAGMENT
  81103. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  81104. {
  81105. EXPECT_DECLS;
  81106. WOLFSSL *ssl_c = NULL;
  81107. WOLFSSL *ssl_c2 = NULL;
  81108. WOLFSSL *ssl_s = NULL;
  81109. struct test_memio_ctx test_ctx;
  81110. WOLFSSL_CTX *ctx_c = NULL;
  81111. WOLFSSL_CTX *ctx_s = NULL;
  81112. word16 max_fragment = 0;
  81113. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81114. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81115. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81116. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81117. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  81118. WOLFSSL_SUCCESS);
  81119. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81120. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81121. if (ssl_s != NULL) {
  81122. max_fragment = ssl_s->max_fragment;
  81123. }
  81124. /* send CH */
  81125. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81126. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81127. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81128. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81129. /* CH without cookie shouldn't change state */
  81130. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  81131. ExpectIntNE(test_ctx.c_len, 0);
  81132. /* consume HRR from buffer */
  81133. test_ctx.c_len = 0;
  81134. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81135. wolfSSL_free(ssl_c2);
  81136. wolfSSL_free(ssl_c);
  81137. wolfSSL_free(ssl_s);
  81138. wolfSSL_CTX_free(ctx_c);
  81139. wolfSSL_CTX_free(ctx_s);
  81140. return EXPECT_RESULT();
  81141. }
  81142. #endif /* HAVE_MAX_FRAGMENT */
  81143. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  81144. #define ROUNDS_WITH_HVR 4
  81145. #define ROUNDS_WITHOUT_HVR 2
  81146. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  81147. static int buf_is_hvr(const byte *data, int len)
  81148. {
  81149. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  81150. return 0;
  81151. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  81152. }
  81153. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  81154. {
  81155. EXPECT_DECLS;
  81156. struct test_memio_ctx test_ctx;
  81157. WOLFSSL_CTX *ctx_c = NULL;
  81158. WOLFSSL_CTX *ctx_s = NULL;
  81159. WOLFSSL *ssl_c = NULL;
  81160. WOLFSSL *ssl_s = NULL;
  81161. WOLFSSL_SESSION *sess = NULL;
  81162. int round_trips;
  81163. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81164. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  81165. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81166. #ifdef HAVE_SESSION_TICKET
  81167. if (useticket) {
  81168. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  81169. }
  81170. #endif
  81171. round_trips = ROUNDS_WITH_HVR;
  81172. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  81173. &round_trips), 0);
  81174. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  81175. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81176. wolfSSL_shutdown(ssl_c);
  81177. wolfSSL_shutdown(ssl_s);
  81178. wolfSSL_free(ssl_c);
  81179. ssl_c = NULL;
  81180. wolfSSL_free(ssl_s);
  81181. ssl_s = NULL;
  81182. test_ctx.c_len = test_ctx.s_len = 0;
  81183. /* make resumption invalid */
  81184. if (bad && (sess != NULL)) {
  81185. if (useticket) {
  81186. #ifdef HAVE_SESSION_TICKET
  81187. if (sess->ticket != NULL) {
  81188. sess->ticket[0] = !sess->ticket[0];
  81189. }
  81190. #endif /* HAVE_SESSION_TICKET */
  81191. }
  81192. else {
  81193. sess->sessionID[0] = !sess->sessionID[0];
  81194. }
  81195. }
  81196. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81197. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81198. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81199. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81200. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81201. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81202. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81203. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81204. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81205. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81206. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81207. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  81208. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  81209. if (!useticket) {
  81210. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  81211. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  81212. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  81213. }
  81214. wolfSSL_SESSION_free(sess);
  81215. wolfSSL_free(ssl_c);
  81216. wolfSSL_free(ssl_s);
  81217. wolfSSL_CTX_free(ctx_c);
  81218. wolfSSL_CTX_free(ctx_s);
  81219. return EXPECT_RESULT();
  81220. }
  81221. static int test_wolfSSL_dtls_stateless_resume(void)
  81222. {
  81223. EXPECT_DECLS;
  81224. #ifdef HAVE_SESSION_TICKET
  81225. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  81226. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  81227. #endif /* HAVE_SESION_TICKET */
  81228. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  81229. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  81230. return EXPECT_RESULT();
  81231. }
  81232. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  81233. #if !defined(NO_OLD_TLS)
  81234. static int test_wolfSSL_dtls_stateless_downgrade(void)
  81235. {
  81236. EXPECT_DECLS;
  81237. WOLFSSL_CTX *ctx_c = NULL;
  81238. WOLFSSL_CTX *ctx_c2 = NULL;
  81239. WOLFSSL_CTX *ctx_s = NULL;
  81240. WOLFSSL *ssl_c = NULL;
  81241. WOLFSSL *ssl_c2 = NULL;
  81242. WOLFSSL *ssl_s = NULL;
  81243. struct test_memio_ctx test_ctx;
  81244. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81245. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81246. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81247. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  81248. WOLFSSL_SUCCESS);
  81249. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  81250. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  81251. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  81252. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  81253. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81254. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81255. /* send CH */
  81256. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81257. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81258. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81259. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81260. ExpectIntNE(test_ctx.c_len, 0);
  81261. /* consume HRR */
  81262. test_ctx.c_len = 0;
  81263. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81264. wolfSSL_free(ssl_c2);
  81265. wolfSSL_free(ssl_c);
  81266. wolfSSL_free(ssl_s);
  81267. wolfSSL_CTX_free(ctx_c);
  81268. wolfSSL_CTX_free(ctx_c2);
  81269. wolfSSL_CTX_free(ctx_s);
  81270. return EXPECT_RESULT();
  81271. }
  81272. #endif /* !defined(NO_OLD_TLS) */
  81273. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81274. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  81275. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81276. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81277. static int test_WOLFSSL_dtls_version_alert(void)
  81278. {
  81279. EXPECT_DECLS;
  81280. struct test_memio_ctx test_ctx;
  81281. WOLFSSL_CTX *ctx_c = NULL;
  81282. WOLFSSL_CTX *ctx_s = NULL;
  81283. WOLFSSL *ssl_c = NULL;
  81284. WOLFSSL *ssl_s = NULL;
  81285. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81286. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81287. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  81288. /* client hello */
  81289. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81290. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81291. /* hrr */
  81292. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81293. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81294. /* client hello 1 */
  81295. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81296. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81297. /* server hello */
  81298. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81299. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81300. /* should fail */
  81301. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81302. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  81303. /* shuould fail */
  81304. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81305. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  81306. wolfSSL_free(ssl_c);
  81307. wolfSSL_free(ssl_s);
  81308. wolfSSL_CTX_free(ctx_c);
  81309. wolfSSL_CTX_free(ctx_s);
  81310. return EXPECT_RESULT();
  81311. }
  81312. #else
  81313. static int test_WOLFSSL_dtls_version_alert(void)
  81314. {
  81315. return TEST_SKIPPED;
  81316. }
  81317. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  81318. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  81319. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  81320. */
  81321. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  81322. && defined(WOLFSSL_TLS13) && \
  81323. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  81324. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81325. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  81326. {
  81327. struct test_memio_ctx *test_ctx;
  81328. byte buf[2048];
  81329. int idx, sz;
  81330. word32 tmp;
  81331. int ret;
  81332. idx = 5; /* space for record header */
  81333. buf[idx] = session_ticket; /* type */
  81334. idx++;
  81335. tmp = OPAQUE32_LEN +
  81336. OPAQUE32_LEN +
  81337. OPAQUE8_LEN + nonceLength +
  81338. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  81339. c32to24(tmp, buf + idx);
  81340. idx += OPAQUE24_LEN;
  81341. c32toa((word32)12345, buf+idx); /* lifetime */
  81342. idx += OPAQUE32_LEN;
  81343. c32toa((word32)12345, buf+idx); /* add */
  81344. idx += OPAQUE32_LEN;
  81345. buf[idx] = nonceLength; /* nonce length */
  81346. idx++;
  81347. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  81348. idx += nonceLength;
  81349. tmp = 1; /* ticket len */
  81350. c16toa((word16)tmp, buf+idx);
  81351. idx += 2;
  81352. buf[idx] = 0xFF; /* ticket */
  81353. idx++;
  81354. tmp = 0; /* ext len */
  81355. c16toa((word16)tmp, buf+idx);
  81356. idx += 2;
  81357. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  81358. handshake, 0, 0, 0);
  81359. AssertIntGT(sz, 0);
  81360. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  81361. AssertNotNull(test_ctx);
  81362. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  81363. return !(ret == sz);
  81364. }
  81365. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  81366. {
  81367. int ret = 0;
  81368. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  81369. ret = -1;
  81370. }
  81371. else {
  81372. int i;
  81373. for (i = 0; i < len; i++) {
  81374. if (sess->ticketNonce.data[i] != len) {
  81375. ret = -1;
  81376. break;
  81377. }
  81378. }
  81379. }
  81380. return ret;
  81381. }
  81382. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81383. {
  81384. EXPECT_DECLS;
  81385. char *buf[1024];
  81386. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  81387. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81388. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81389. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  81390. return EXPECT_RESULT();
  81391. }
  81392. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81393. {
  81394. EXPECT_DECLS;
  81395. WOLFSSL_SESSION *sess = NULL;
  81396. WOLFSSL_SESSION *cached = NULL;
  81397. WOLFSSL_CTX *ctx = ssl_c->ctx;
  81398. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  81399. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81400. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  81401. NULL, ssl_c->options.side, 1,NULL), 0);
  81402. ExpectNotNull(cached = wolfSSL_SESSION_new());
  81403. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  81404. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  81405. wolfSSL_SESSION_free(cached);
  81406. wolfSSL_SESSION_free(sess);
  81407. return EXPECT_RESULT();
  81408. }
  81409. static int test_ticket_nonce_malloc(void)
  81410. {
  81411. EXPECT_DECLS;
  81412. struct test_memio_ctx test_ctx;
  81413. WOLFSSL_CTX *ctx_c = NULL;
  81414. WOLFSSL_CTX *ctx_s = NULL;
  81415. WOLFSSL *ssl_c = NULL;
  81416. WOLFSSL *ssl_s = NULL;
  81417. byte small;
  81418. byte medium;
  81419. byte big;
  81420. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81421. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81422. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81423. /* will send ticket manually */
  81424. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  81425. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81426. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81427. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  81428. (ssl_s->options.handShakeDone == 0)) {
  81429. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  81430. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81431. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  81432. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81433. }
  81434. small = TLS13_TICKET_NONCE_STATIC_SZ;
  81435. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  81436. medium = small + 20;
  81437. #else
  81438. medium = 255;
  81439. #endif
  81440. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  81441. big = small + 20;
  81442. #else
  81443. big = 255;
  81444. #endif
  81445. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81446. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  81447. ssl_c->session->ticketNonce.dataStatic);
  81448. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81449. TEST_SUCCESS);
  81450. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  81451. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81452. TEST_SUCCESS);
  81453. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81454. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81455. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81456. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  81457. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81458. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81459. wolfSSL_free(ssl_c);
  81460. wolfSSL_free(ssl_s);
  81461. wolfSSL_CTX_free(ctx_c);
  81462. wolfSSL_CTX_free(ctx_s);
  81463. return EXPECT_RESULT();
  81464. }
  81465. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  81466. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  81467. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  81468. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  81469. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  81470. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81471. static int test_ticket_ret_create(void)
  81472. {
  81473. EXPECT_DECLS;
  81474. WOLFSSL_CTX *ctx_c = NULL;
  81475. WOLFSSL_CTX *ctx_s = NULL;
  81476. WOLFSSL *ssl_c = NULL;
  81477. WOLFSSL *ssl_s = NULL;
  81478. byte ticket[SESSION_TICKET_LEN];
  81479. struct test_memio_ctx test_ctx;
  81480. WOLFSSL_SESSION *sess = NULL;
  81481. word16 ticketLen = 0;
  81482. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81483. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81484. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81485. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81486. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81487. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  81488. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81489. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81490. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  81491. if (sess != NULL) {
  81492. ticketLen = sess->ticketLen;
  81493. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  81494. }
  81495. wolfSSL_free(ssl_c);
  81496. ssl_c = NULL;
  81497. wolfSSL_free(ssl_s);
  81498. ssl_s = NULL;
  81499. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81500. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81501. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81502. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81503. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81504. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81505. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81506. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81507. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  81508. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  81509. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  81510. wolfSSL_SESSION_free(sess);
  81511. wolfSSL_free(ssl_c);
  81512. wolfSSL_free(ssl_s);
  81513. wolfSSL_CTX_free(ctx_c);
  81514. wolfSSL_CTX_free(ctx_s);
  81515. return EXPECT_RESULT();
  81516. }
  81517. #else
  81518. static int test_ticket_ret_create(void)
  81519. {
  81520. return TEST_SKIPPED;
  81521. }
  81522. #endif
  81523. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  81524. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  81525. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81526. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81527. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81528. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  81529. {
  81530. int ret;
  81531. WOLFSSL_SESSION* session = NULL;
  81532. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81533. if (!wolfSSL_is_server(ssl)) {
  81534. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81535. AssertNotNull(session);
  81536. }
  81537. do {
  81538. ret = wolfSSL_shutdown(ssl);
  81539. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81540. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81541. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81542. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81543. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81544. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81545. #endif
  81546. if (!wolfSSL_is_server(ssl)) {
  81547. /* client */
  81548. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81549. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81550. wolfSSL_set_session(ssl, session);
  81551. wolfSSL_SESSION_free(session);
  81552. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81553. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81554. }
  81555. else {
  81556. /* server */
  81557. /* Different ciphersuite so that the ticket will be invalidated based on
  81558. * the ciphersuite */
  81559. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  81560. WOLFSSL_SUCCESS);
  81561. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  81562. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81563. }
  81564. }
  81565. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  81566. {
  81567. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  81568. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81569. WOLFSSL_SUCCESS);
  81570. }
  81571. static int test_ticket_and_psk_mixing(void)
  81572. {
  81573. EXPECT_DECLS;
  81574. /* Test mixing tickets and regular PSK */
  81575. callback_functions client_cbs, server_cbs;
  81576. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81577. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81578. client_cbs.method = wolfTLSv1_3_client_method;
  81579. server_cbs.method = wolfTLSv1_3_server_method;
  81580. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  81581. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81582. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81583. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81584. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81585. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81586. return EXPECT_RESULT();
  81587. }
  81588. #else
  81589. static int test_ticket_and_psk_mixing(void)
  81590. {
  81591. return TEST_SKIPPED;
  81592. }
  81593. #endif
  81594. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  81595. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  81596. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81597. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81598. static int test_prioritize_psk_cb_called = FALSE;
  81599. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  81600. const char* identity, unsigned char* key, unsigned int key_max_len,
  81601. const char** ciphersuite)
  81602. {
  81603. test_prioritize_psk_cb_called = TRUE;
  81604. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  81605. }
  81606. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  81607. {
  81608. int ret;
  81609. WOLFSSL_SESSION* session = NULL;
  81610. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81611. if (!wolfSSL_is_server(ssl)) {
  81612. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81613. AssertNotNull(session);
  81614. }
  81615. do {
  81616. ret = wolfSSL_shutdown(ssl);
  81617. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81618. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81619. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81620. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  81621. * important. */
  81622. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81623. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81624. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81625. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81626. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81627. #endif
  81628. if (!wolfSSL_is_server(ssl)) {
  81629. /* client */
  81630. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81631. wolfSSL_set_session(ssl, session);
  81632. wolfSSL_SESSION_free(session);
  81633. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81634. }
  81635. else {
  81636. /* server */
  81637. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  81638. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81639. #ifdef WOLFSSL_PRIORITIZE_PSK
  81640. /* The ticket should be first tried with all ciphersuites and chosen */
  81641. AssertFalse(test_prioritize_psk_cb_called);
  81642. #else
  81643. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  81644. * callback that sets this var. */
  81645. AssertTrue(test_prioritize_psk_cb_called);
  81646. #endif
  81647. }
  81648. }
  81649. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  81650. {
  81651. if (!wolfSSL_is_server(ssl))
  81652. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81653. WOLFSSL_SUCCESS);
  81654. else
  81655. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81656. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81657. }
  81658. static int test_prioritize_psk(void)
  81659. {
  81660. EXPECT_DECLS;
  81661. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  81662. * of the PSK's will be followed instead of the ciphersuite. */
  81663. callback_functions client_cbs, server_cbs;
  81664. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81665. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81666. client_cbs.method = wolfTLSv1_3_client_method;
  81667. server_cbs.method = wolfTLSv1_3_server_method;
  81668. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81669. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81670. client_cbs.on_result = test_prioritize_psk_on_result;
  81671. server_cbs.on_result = test_prioritize_psk_on_result;
  81672. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81673. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81674. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81675. return EXPECT_RESULT();
  81676. }
  81677. #else
  81678. static int test_prioritize_psk(void)
  81679. {
  81680. return TEST_SKIPPED;
  81681. }
  81682. #endif
  81683. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  81684. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81685. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81686. !defined(WOLFSSL_NO_TLS12)
  81687. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  81688. {
  81689. EXPECT_DECLS;
  81690. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  81691. /* Set TLS 1.3 specific suite */
  81692. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  81693. return EXPECT_RESULT();
  81694. }
  81695. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81696. {
  81697. EXPECT_DECLS;
  81698. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  81699. * do a 1.2 connection. */
  81700. test_ssl_cbf client_cbs, server_cbs;
  81701. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81702. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81703. client_cbs.method = wolfTLSv1_2_client_method;
  81704. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  81705. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  81706. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81707. &server_cbs, NULL), TEST_SUCCESS);
  81708. return EXPECT_RESULT();
  81709. }
  81710. #else
  81711. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81712. {
  81713. return TEST_SKIPPED;
  81714. }
  81715. #endif
  81716. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  81717. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  81718. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  81719. {
  81720. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  81721. return TEST_SUCCESS;
  81722. }
  81723. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  81724. {
  81725. EXPECT_DECLS;
  81726. WOLFSSL_ALERT_HISTORY h;
  81727. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  81728. ExpectIntEQ(h.last_rx.level, alert_fatal);
  81729. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  81730. return EXPECT_RESULT();
  81731. }
  81732. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81733. {
  81734. EXPECT_DECLS;
  81735. test_ssl_cbf client_cbs, server_cbs;
  81736. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81737. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81738. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  81739. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  81740. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  81741. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  81742. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  81743. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81744. &server_cbs, NULL), -1001);
  81745. return EXPECT_RESULT();
  81746. }
  81747. #else
  81748. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81749. {
  81750. return TEST_SKIPPED;
  81751. }
  81752. #endif
  81753. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  81754. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81755. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81756. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  81757. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  81758. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81759. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  81760. static int test_TLS_13_ticket_different_ciphers_run = 0;
  81761. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  81762. {
  81763. EXPECT_DECLS;
  81764. switch (test_TLS_13_ticket_different_ciphers_run) {
  81765. case 0:
  81766. /* First run */
  81767. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81768. WOLFSSL_SUCCESS);
  81769. if (wolfSSL_is_server(ssl)) {
  81770. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  81771. wolfSSL_get_SSL_CTX(ssl));
  81772. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  81773. test_TLS_13_ticket_different_ciphers_ctx));
  81774. }
  81775. break;
  81776. case 1:
  81777. /* Second run */
  81778. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81779. "TLS13-AES128-GCM-SHA256"),
  81780. WOLFSSL_SUCCESS);
  81781. if (!wolfSSL_is_server(ssl)) {
  81782. ExpectIntEQ(wolfSSL_set_session(ssl,
  81783. test_TLS_13_ticket_different_ciphers_session),
  81784. WOLFSSL_SUCCESS);
  81785. }
  81786. break;
  81787. default:
  81788. /* Bad state? */
  81789. Fail(("Should not enter here"), ("Should not enter here"));
  81790. }
  81791. return EXPECT_RESULT();
  81792. }
  81793. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  81794. {
  81795. EXPECT_DECLS;
  81796. switch (test_TLS_13_ticket_different_ciphers_run) {
  81797. case 0:
  81798. /* First run */
  81799. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  81800. wolfSSL_get1_session(ssl));
  81801. break;
  81802. case 1:
  81803. /* Second run */
  81804. ExpectTrue(wolfSSL_session_reused(ssl));
  81805. break;
  81806. default:
  81807. /* Bad state? */
  81808. Fail(("Should not enter here"), ("Should not enter here"));
  81809. }
  81810. return EXPECT_RESULT();
  81811. }
  81812. static int test_TLS_13_ticket_different_ciphers(void)
  81813. {
  81814. EXPECT_DECLS;
  81815. /* Check that we handle the connection when the ticket doesn't match
  81816. * the first ciphersuite. */
  81817. test_ssl_cbf client_cbs, server_cbs;
  81818. struct test_params {
  81819. method_provider client_meth;
  81820. method_provider server_meth;
  81821. int doUdp;
  81822. } params[] = {
  81823. #ifdef WOLFSSL_DTLS13
  81824. /* Test that the stateless code handles sessions correctly */
  81825. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  81826. #endif
  81827. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  81828. };
  81829. size_t i;
  81830. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  81831. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81832. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81833. test_TLS_13_ticket_different_ciphers_run = 0;
  81834. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  81835. client_cbs.method = params[i].client_meth;
  81836. server_cbs.method = params[i].server_meth;
  81837. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81838. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81839. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  81840. server_cbs.ticNoInit = 1;
  81841. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81842. &server_cbs, NULL), TEST_SUCCESS);
  81843. test_TLS_13_ticket_different_ciphers_run++;
  81844. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  81845. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81846. &server_cbs, NULL), TEST_SUCCESS);
  81847. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  81848. test_TLS_13_ticket_different_ciphers_session = NULL;
  81849. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  81850. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81851. }
  81852. return EXPECT_RESULT();
  81853. }
  81854. #else
  81855. static int test_TLS_13_ticket_different_ciphers(void)
  81856. {
  81857. return TEST_SKIPPED;
  81858. }
  81859. #endif
  81860. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  81861. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81862. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  81863. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  81864. byte test_extra_alerts_wrong_cs_sh[] = {
  81865. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  81866. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  81867. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  81868. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  81869. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  81870. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  81871. 0xbb, 0x07, 0x54, 0x1c,
  81872. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  81873. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81874. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81875. };
  81876. static int test_extra_alerts_wrong_cs(void)
  81877. {
  81878. EXPECT_DECLS;
  81879. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  81880. struct test_memio_ctx test_ctx;
  81881. WOLFSSL_CTX *ctx_c = NULL;
  81882. WOLFSSL_ALERT_HISTORY h;
  81883. WOLFSSL *ssl_c = NULL;
  81884. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81885. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81886. wolfTLSv1_2_client_method, NULL), 0);
  81887. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  81888. WOLFSSL_SUCCESS);
  81889. /* CH */
  81890. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81891. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81892. WOLFSSL_ERROR_WANT_READ);
  81893. /* consume CH */
  81894. test_ctx.s_len = 0;
  81895. /* inject SH */
  81896. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  81897. sizeof(test_extra_alerts_wrong_cs_sh));
  81898. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  81899. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81900. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81901. WOLFSSL_ERROR_WANT_READ);
  81902. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81903. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81904. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81905. wolfSSL_free(ssl_c);
  81906. wolfSSL_CTX_free(ctx_c);
  81907. #endif
  81908. return EXPECT_RESULT();
  81909. }
  81910. #else
  81911. static int test_extra_alerts_wrong_cs(void)
  81912. {
  81913. return TEST_SKIPPED;
  81914. }
  81915. #endif
  81916. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  81917. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81918. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  81919. byte test_wrong_cs_downgrade_sh[] = {
  81920. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  81921. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  81922. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  81923. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  81924. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  81925. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  81926. 0x85, 0xe5, 0x2f, 0x54,
  81927. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  81928. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81929. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81930. };
  81931. static int test_wrong_cs_downgrade(void)
  81932. {
  81933. EXPECT_DECLS;
  81934. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  81935. struct test_memio_ctx test_ctx;
  81936. WOLFSSL_CTX *ctx_c = NULL;
  81937. WOLFSSL *ssl_c = NULL;
  81938. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81939. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81940. wolfSSLv23_client_method, NULL), 0);
  81941. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  81942. WOLFSSL_SUCCESS);
  81943. /* CH */
  81944. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81945. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81946. WOLFSSL_ERROR_WANT_READ);
  81947. /* consume CH */
  81948. test_ctx.s_len = 0;
  81949. /* inject SH */
  81950. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  81951. sizeof(test_wrong_cs_downgrade_sh));
  81952. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  81953. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81954. #ifdef OPENSSL_EXTRA
  81955. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81956. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  81957. #else
  81958. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81959. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  81960. #endif /* OPENSSL_EXTRA */
  81961. wolfSSL_free(ssl_c);
  81962. wolfSSL_CTX_free(ctx_c);
  81963. #endif
  81964. return EXPECT_RESULT();
  81965. }
  81966. #else
  81967. static int test_wrong_cs_downgrade(void)
  81968. {
  81969. return TEST_SKIPPED;
  81970. }
  81971. #endif
  81972. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  81973. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  81974. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  81975. {
  81976. tail_len -= msg_length;
  81977. XMEMMOVE(msg, msg + msg_length, tail_len);
  81978. *len = *len - msg_length;
  81979. }
  81980. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  81981. byte *found)
  81982. {
  81983. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  81984. const unsigned int _RECORD_HEADER_SZ = 5;
  81985. const int _change_cipher_hs = 55;
  81986. const int _change_cipher = 20;
  81987. const int _handshake = 22;
  81988. unsigned int tail_len;
  81989. byte *idx, *curr;
  81990. word8 currType;
  81991. word16 rLength;
  81992. word32 hLength;
  81993. idx = buf;
  81994. tail_len = (unsigned int)*len;
  81995. *found = 0;
  81996. while (tail_len > _RECORD_HEADER_SZ) {
  81997. curr = idx;
  81998. currType = *idx;
  81999. ato16(idx + 3, &rLength);
  82000. idx += _RECORD_HEADER_SZ;
  82001. tail_len -= _RECORD_HEADER_SZ;
  82002. if (tail_len < rLength)
  82003. return -1;
  82004. if (type == _change_cipher_hs && currType == _change_cipher) {
  82005. if (rLength != 1)
  82006. return -1;
  82007. /* match */
  82008. test_remove_msg(curr, *len - (int)(curr - buf),
  82009. len, _RECORD_HEADER_SZ + 1);
  82010. *found = 1;
  82011. return 0;
  82012. }
  82013. if (currType != _handshake) {
  82014. idx += rLength;
  82015. tail_len -= rLength;
  82016. continue;
  82017. }
  82018. if (rLength < _HANDSHAKE_HEADER_SZ)
  82019. return -1;
  82020. currType = *idx;
  82021. ato24(idx+1, &hLength);
  82022. hLength += _HANDSHAKE_HEADER_SZ;
  82023. if (tail_len < hLength)
  82024. return -1;
  82025. if (currType != type) {
  82026. idx += hLength;
  82027. tail_len -= hLength;
  82028. continue;
  82029. }
  82030. /* match */
  82031. test_remove_msg(curr, *len - (int)(curr - buf), len,
  82032. hLength + _RECORD_HEADER_SZ);
  82033. *found = 1;
  82034. return 0;
  82035. }
  82036. /* not found */
  82037. return 0;
  82038. }
  82039. static int test_remove_hs_message(byte hs_message_type,
  82040. int extra_round, byte alert_type)
  82041. {
  82042. EXPECT_DECLS;
  82043. WOLFSSL_CTX *ctx_c = NULL;
  82044. WOLFSSL_CTX *ctx_s = NULL;
  82045. WOLFSSL *ssl_c = NULL;
  82046. WOLFSSL *ssl_s = NULL;
  82047. struct test_memio_ctx test_ctx;
  82048. WOLFSSL_ALERT_HISTORY h;
  82049. byte found = 0;
  82050. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82051. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82052. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82053. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82054. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82055. WOLFSSL_ERROR_WANT_READ);
  82056. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82057. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82058. WOLFSSL_ERROR_WANT_READ);
  82059. if (extra_round) {
  82060. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82061. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82062. WOLFSSL_ERROR_WANT_READ);
  82063. /* this will complete handshake from server side */
  82064. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82065. }
  82066. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  82067. &test_ctx.c_len, hs_message_type, &found), 0);
  82068. if (!found) {
  82069. wolfSSL_free(ssl_c);
  82070. wolfSSL_CTX_free(ctx_c);
  82071. wolfSSL_free(ssl_s);
  82072. wolfSSL_CTX_free(ctx_s);
  82073. return TEST_SKIPPED;
  82074. }
  82075. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82076. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82077. WOLFSSL_ERROR_WANT_READ);
  82078. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82079. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  82080. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82081. wolfSSL_free(ssl_c);
  82082. wolfSSL_CTX_free(ctx_c);
  82083. wolfSSL_free(ssl_s);
  82084. wolfSSL_CTX_free(ctx_s);
  82085. return EXPECT_RESULT();
  82086. }
  82087. static int test_extra_alerts_skip_hs(void)
  82088. {
  82089. EXPECT_DECLS;
  82090. const byte _server_key_exchange = 12;
  82091. const byte _server_hello = 2;
  82092. const byte _certificate = 11;
  82093. /* server_hello */
  82094. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  82095. unexpected_message), TEST_FAIL);
  82096. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  82097. 0xff), TEST_FAIL);
  82098. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  82099. unexpected_message), TEST_FAIL);
  82100. return EXPECT_RESULT();
  82101. }
  82102. #else
  82103. static int test_extra_alerts_skip_hs(void)
  82104. {
  82105. return TEST_SKIPPED;
  82106. }
  82107. #endif
  82108. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82109. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  82110. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  82111. unsigned char* key, unsigned int key_max_len)
  82112. {
  82113. (void)ssl;
  82114. (void)id;
  82115. (void)key_max_len;
  82116. /* zero means error */
  82117. key[0] = 0x10;
  82118. return 1;
  82119. }
  82120. static int test_extra_alerts_bad_psk(void)
  82121. {
  82122. EXPECT_DECLS;
  82123. WOLFSSL_CTX *ctx_c = NULL;
  82124. WOLFSSL_CTX *ctx_s = NULL;
  82125. WOLFSSL *ssl_c = NULL;
  82126. WOLFSSL *ssl_s = NULL;
  82127. struct test_memio_ctx test_ctx;
  82128. WOLFSSL_ALERT_HISTORY h;
  82129. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82130. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82131. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82132. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  82133. WOLFSSL_SUCCESS);
  82134. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  82135. WOLFSSL_SUCCESS);
  82136. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  82137. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82138. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82139. WOLFSSL_ERROR_WANT_READ);
  82140. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82141. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82142. WOLFSSL_ERROR_WANT_READ);
  82143. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82144. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82145. WOLFSSL_ERROR_WANT_READ);
  82146. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82147. ExpectIntEQ(h.last_tx.code, handshake_failure);
  82148. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82149. wolfSSL_free(ssl_c);
  82150. wolfSSL_CTX_free(ctx_c);
  82151. wolfSSL_free(ssl_s);
  82152. wolfSSL_CTX_free(ctx_s);
  82153. return EXPECT_RESULT();
  82154. }
  82155. #else
  82156. static int test_extra_alerts_bad_psk(void)
  82157. {
  82158. return TEST_SKIPPED;
  82159. }
  82160. #endif
  82161. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  82162. /*
  82163. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  82164. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  82165. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  82166. int sz, void *ctx)
  82167. {
  82168. (void)ssl;
  82169. (void)buf;
  82170. (void)ctx;
  82171. (void)sz;
  82172. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  82173. }
  82174. static int test_multiple_alerts_EAGAIN(void)
  82175. {
  82176. EXPECT_DECLS;
  82177. size_t size_of_last_packet = 0;
  82178. /* declare wolfSSL objects */
  82179. struct test_memio_ctx test_ctx;
  82180. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82181. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82182. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82183. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  82184. #ifdef USE_TLSV13
  82185. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82186. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82187. #else
  82188. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82189. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82190. #endif
  82191. ExpectNotNull(ctx_c);
  82192. ExpectNotNull(ssl_c);
  82193. ExpectNotNull(ctx_s);
  82194. ExpectNotNull(ssl_s);
  82195. /* Load client certificates into WOLFSSL_CTX */
  82196. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  82197. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82198. /*
  82199. * We set the custom callback for the IO to emulate multiple EAGAINs
  82200. * on shutdown, so we can check that we don't send multiple packets.
  82201. * */
  82202. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  82203. /*
  82204. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  82205. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  82206. * on the output buffer.
  82207. * */
  82208. wolfSSL_shutdown(ssl_c);
  82209. wolfSSL_shutdown(ssl_c);
  82210. if (ssl_c != NULL) {
  82211. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  82212. }
  82213. wolfSSL_shutdown(ssl_c);
  82214. /*
  82215. * Finally we check the length of the output buffer.
  82216. * */
  82217. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  82218. /* Cleanup and return */
  82219. wolfSSL_CTX_free(ctx_c);
  82220. wolfSSL_free(ssl_c);
  82221. wolfSSL_CTX_free(ctx_s);
  82222. wolfSSL_free(ssl_s);
  82223. return EXPECT_RESULT();
  82224. }
  82225. #else
  82226. static int test_multiple_alerts_EAGAIN(void)
  82227. {
  82228. return TEST_SKIPPED;
  82229. }
  82230. #endif
  82231. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82232. && !defined(NO_PSK)
  82233. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  82234. const char* hint, char* identity, unsigned int id_max_len,
  82235. unsigned char* key, unsigned int key_max_len)
  82236. {
  82237. (void)ssl;
  82238. (void)hint;
  82239. (void)key_max_len;
  82240. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  82241. XSTRNCPY(identity, "Client_identity", id_max_len);
  82242. key[0] = 0x20;
  82243. return 1;
  82244. }
  82245. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  82246. const char* id, unsigned char* key, unsigned int key_max_len)
  82247. {
  82248. (void)ssl;
  82249. (void)id;
  82250. (void)key_max_len;
  82251. /* zero means error */
  82252. key[0] = 0x10;
  82253. return 1;
  82254. }
  82255. #endif
  82256. static int test_tls13_bad_psk_binder(void)
  82257. {
  82258. EXPECT_DECLS;
  82259. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82260. && !defined(NO_PSK)
  82261. WOLFSSL_CTX *ctx_c = NULL;
  82262. WOLFSSL_CTX *ctx_s = NULL;
  82263. WOLFSSL *ssl_c = NULL;
  82264. WOLFSSL *ssl_s = NULL;
  82265. struct test_memio_ctx test_ctx;
  82266. WOLFSSL_ALERT_HISTORY h;
  82267. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82268. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82269. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82270. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  82271. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  82272. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82273. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82274. WOLFSSL_ERROR_WANT_READ);
  82275. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82276. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82277. WC_NO_ERR_TRACE(BAD_BINDER));
  82278. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82279. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82280. WC_NO_ERR_TRACE(FATAL_ERROR));
  82281. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82282. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  82283. ExpectIntEQ(h.last_rx.level, alert_fatal);
  82284. wolfSSL_free(ssl_c);
  82285. wolfSSL_CTX_free(ctx_c);
  82286. wolfSSL_free(ssl_s);
  82287. wolfSSL_CTX_free(ctx_s);
  82288. #endif
  82289. return EXPECT_RESULT();
  82290. }
  82291. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  82292. defined(HAVE_IO_TESTS_DEPENDENCIES)
  82293. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  82294. int sz, void *ctx)
  82295. {
  82296. static int sentServerHello = FALSE;
  82297. if (!sentServerHello) {
  82298. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  82299. size_t i;
  82300. if (sz < (int)sizeof(renegExt))
  82301. return WOLFSSL_CBIO_ERR_GENERAL;
  82302. /* Remove SCR from ServerHello */
  82303. for (i = 0; i < sz - sizeof(renegExt); i++) {
  82304. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  82305. /* Found the extension. Change it to something unrecognized. */
  82306. buf[i+1] = 0x11;
  82307. break;
  82308. }
  82309. }
  82310. sentServerHello = TRUE;
  82311. }
  82312. return EmbedSend(ssl, buf, sz, ctx);
  82313. }
  82314. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  82315. {
  82316. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  82317. }
  82318. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  82319. {
  82320. WOLFSSL_ALERT_HISTORY h;
  82321. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  82322. AssertIntEQ(h.last_rx.code, handshake_failure);
  82323. AssertIntEQ(h.last_rx.level, alert_fatal);
  82324. }
  82325. static int test_harden_no_secure_renegotiation(void)
  82326. {
  82327. EXPECT_DECLS;
  82328. callback_functions client_cbs, server_cbs;
  82329. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82330. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82331. client_cbs.method = wolfTLSv1_2_client_method;
  82332. server_cbs.method = wolfTLSv1_2_server_method;
  82333. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  82334. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  82335. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82336. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  82337. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  82338. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  82339. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  82340. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  82341. return EXPECT_RESULT();
  82342. }
  82343. #else
  82344. static int test_harden_no_secure_renegotiation(void)
  82345. {
  82346. return TEST_SKIPPED;
  82347. }
  82348. #endif
  82349. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  82350. static int test_override_alt_cert_chain_cert_cb(int preverify,
  82351. WOLFSSL_X509_STORE_CTX* store)
  82352. {
  82353. fprintf(stderr, "preverify: %d\n", preverify);
  82354. fprintf(stderr, "store->error: %d\n", store->error);
  82355. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  82356. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  82357. fprintf(stderr, "Overriding OCSP error\n");
  82358. return 1;
  82359. }
  82360. #ifndef WOLFSSL_ALT_CERT_CHAINS
  82361. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  82362. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  82363. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  82364. defined(HAVE_WEBSERVER)
  82365. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  82366. #endif
  82367. ) && store->error_depth == store->totalCerts - 1) {
  82368. fprintf(stderr, "Overriding no signer error only for root cert\n");
  82369. return 1;
  82370. }
  82371. #endif
  82372. else
  82373. return preverify;
  82374. }
  82375. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  82376. int urlSz, unsigned char* request, int requestSz,
  82377. unsigned char** response)
  82378. {
  82379. (void)ioCtx;
  82380. (void)url;
  82381. (void)urlSz;
  82382. (void)request;
  82383. (void)requestSz;
  82384. (void)response;
  82385. return -1;
  82386. }
  82387. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  82388. {
  82389. EXPECT_DECLS;
  82390. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  82391. test_override_alt_cert_chain_cert_cb);
  82392. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82393. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82394. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82395. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82396. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82397. WOLFSSL_SUCCESS);
  82398. return EXPECT_RESULT();
  82399. }
  82400. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  82401. {
  82402. EXPECT_DECLS;
  82403. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  82404. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82405. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82406. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82407. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82408. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82409. WOLFSSL_SUCCESS);
  82410. return EXPECT_RESULT();
  82411. }
  82412. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  82413. {
  82414. EXPECT_DECLS;
  82415. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  82416. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  82417. return EXPECT_RESULT();
  82418. }
  82419. static int test_override_alt_cert_chain(void)
  82420. {
  82421. EXPECT_DECLS;
  82422. size_t i;
  82423. struct test_params {
  82424. ctx_cb client_ctx_cb;
  82425. ctx_cb server_ctx_cb;
  82426. int result;
  82427. } params[] = {
  82428. {test_override_alt_cert_chain_client_ctx_ready,
  82429. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  82430. {test_override_alt_cert_chain_client_ctx_ready2,
  82431. test_override_alt_cert_chain_server_ctx_ready, -1001},
  82432. };
  82433. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  82434. test_ssl_cbf client_cbs, server_cbs;
  82435. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82436. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82437. fprintf(stderr, "test config: %d\n", (int)i);
  82438. client_cbs.ctx_ready = params[i].client_ctx_cb;
  82439. server_cbs.ctx_ready = params[i].server_ctx_cb;
  82440. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82441. &server_cbs, NULL), params[i].result);
  82442. ExpectIntEQ(client_cbs.return_code,
  82443. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  82444. ExpectIntEQ(server_cbs.return_code,
  82445. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  82446. }
  82447. return EXPECT_RESULT();
  82448. }
  82449. #else
  82450. static int test_override_alt_cert_chain(void)
  82451. {
  82452. return TEST_SKIPPED;
  82453. }
  82454. #endif
  82455. #if defined(HAVE_RPK)
  82456. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  82457. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  82458. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82459. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  82460. {
  82461. int ret = WOLFSSL_SUCCESS;
  82462. (void)mode;
  82463. (void)strctx;
  82464. WOLFSSL_ENTER("MyRpkVerifyCb");
  82465. return ret;
  82466. }
  82467. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  82468. static WC_INLINE int test_rpk_memio_setup(
  82469. struct test_memio_ctx *ctx,
  82470. WOLFSSL_CTX **ctx_c,
  82471. WOLFSSL_CTX **ctx_s,
  82472. WOLFSSL **ssl_c,
  82473. WOLFSSL **ssl_s,
  82474. method_provider method_c,
  82475. method_provider method_s,
  82476. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  82477. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  82478. const char* pkey_c, int fmt_kc, /* client private key and format */
  82479. const char* pkey_s, int fmt_ks /* server private key and format */
  82480. )
  82481. {
  82482. int ret;
  82483. if (ctx_c != NULL && *ctx_c == NULL) {
  82484. *ctx_c = wolfSSL_CTX_new(method_c());
  82485. if (*ctx_c == NULL) {
  82486. return -1;
  82487. }
  82488. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  82489. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  82490. if (ret != WOLFSSL_SUCCESS) {
  82491. return -1;
  82492. }
  82493. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  82494. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  82495. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  82496. if (ret != WOLFSSL_SUCCESS) {
  82497. return -1;
  82498. }
  82499. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  82500. if (ret != WOLFSSL_SUCCESS) {
  82501. return -1;
  82502. }
  82503. }
  82504. if (ctx_s != NULL && *ctx_s == NULL) {
  82505. *ctx_s = wolfSSL_CTX_new(method_s());
  82506. if (*ctx_s == NULL) {
  82507. return -1;
  82508. }
  82509. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  82510. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  82511. if (ret != WOLFSSL_SUCCESS) {
  82512. return -1;
  82513. }
  82514. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  82515. if (ret != WOLFSSL_SUCCESS) {
  82516. return -1;
  82517. }
  82518. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  82519. if (ret != WOLFSSL_SUCCESS) {
  82520. return -1;
  82521. }
  82522. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  82523. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  82524. if (ctx->s_ciphers != NULL) {
  82525. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  82526. if (ret != WOLFSSL_SUCCESS) {
  82527. return -1;
  82528. }
  82529. }
  82530. }
  82531. if (ctx_c != NULL && ssl_c != NULL) {
  82532. *ssl_c = wolfSSL_new(*ctx_c);
  82533. if (*ssl_c == NULL) {
  82534. return -1;
  82535. }
  82536. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  82537. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  82538. }
  82539. if (ctx_s != NULL && ssl_s != NULL) {
  82540. *ssl_s = wolfSSL_new(*ctx_s);
  82541. if (*ssl_s == NULL) {
  82542. return -1;
  82543. }
  82544. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  82545. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  82546. #if !defined(NO_DH)
  82547. SetDH(*ssl_s);
  82548. #endif
  82549. }
  82550. return 0;
  82551. }
  82552. #endif /* HAVE_RPK */
  82553. static int test_rpk_set_xxx_cert_type(void)
  82554. {
  82555. EXPECT_DECLS;
  82556. #if defined(HAVE_RPK)
  82557. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  82558. WOLFSSL_CTX* ctx = NULL;
  82559. WOLFSSL* ssl = NULL;
  82560. int tp;
  82561. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  82562. ExpectNotNull(ctx);
  82563. ssl = wolfSSL_new(ctx);
  82564. ExpectNotNull(ssl);
  82565. /*--------------------------------------------*/
  82566. /* tests for wolfSSL_CTX_set_client_cert_type */
  82567. /*--------------------------------------------*/
  82568. /* illegal parameter test caces */
  82569. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  82570. MAX_CLIENT_CERT_TYPE_CNT),
  82571. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82572. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82573. sizeof(ctype)),
  82574. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82575. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82576. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82577. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82578. MAX_CLIENT_CERT_TYPE_CNT),
  82579. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82580. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82581. ctype[1] = 10; /* set unknown cert type */
  82582. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82583. MAX_CLIENT_CERT_TYPE_CNT),
  82584. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82585. /* pass larger type count */
  82586. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82587. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82588. ctype[2] = 1; /* pass unacceptable type count */
  82589. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82590. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82591. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82592. /* should accept NULL for type buffer */
  82593. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  82594. MAX_CLIENT_CERT_TYPE_CNT),
  82595. WOLFSSL_SUCCESS);
  82596. /* should accept zero for type count */
  82597. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82598. 0),
  82599. WOLFSSL_SUCCESS);
  82600. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82601. MAX_CLIENT_CERT_TYPE_CNT),
  82602. WOLFSSL_SUCCESS);
  82603. /*--------------------------------------------*/
  82604. /* tests for wolfSSL_CTX_set_server_cert_type */
  82605. /*--------------------------------------------*/
  82606. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  82607. MAX_SERVER_CERT_TYPE_CNT),
  82608. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82609. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82610. sizeof(ctype)),
  82611. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82612. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82613. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82614. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82615. MAX_SERVER_CERT_TYPE_CNT),
  82616. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82617. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82618. ctype[1] = 10; /* set unknown cert type */
  82619. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82620. MAX_SERVER_CERT_TYPE_CNT),
  82621. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82622. /* pass larger type count */
  82623. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82624. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82625. ctype[2] = 1; /* pass unacceptable type count */
  82626. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82627. MAX_SERVER_CERT_TYPE_CNT + 1),
  82628. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82629. /* should accept NULL for type buffer */
  82630. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  82631. MAX_SERVER_CERT_TYPE_CNT),
  82632. WOLFSSL_SUCCESS);
  82633. /* should accept zero for type count */
  82634. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82635. 0),
  82636. WOLFSSL_SUCCESS);
  82637. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82638. MAX_CLIENT_CERT_TYPE_CNT),
  82639. WOLFSSL_SUCCESS);
  82640. /*--------------------------------------------*/
  82641. /* tests for wolfSSL_set_client_cert_type */
  82642. /*--------------------------------------------*/
  82643. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  82644. MAX_CLIENT_CERT_TYPE_CNT),
  82645. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82646. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82647. sizeof(ctype)),
  82648. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82649. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82650. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82651. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82652. MAX_CLIENT_CERT_TYPE_CNT),
  82653. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82654. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82655. ctype[1] = 10; /* set unknown cert type */
  82656. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82657. MAX_CLIENT_CERT_TYPE_CNT),
  82658. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82659. /* pass larger type count */
  82660. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82661. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82662. ctype[2] = 1; /* pass unacceptable type count */
  82663. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82664. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82665. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82666. /* should accept NULL for type buffer */
  82667. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  82668. MAX_CLIENT_CERT_TYPE_CNT),
  82669. WOLFSSL_SUCCESS);
  82670. /* should accept zero for type count */
  82671. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82672. 0),
  82673. WOLFSSL_SUCCESS);
  82674. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82675. MAX_CLIENT_CERT_TYPE_CNT),
  82676. WOLFSSL_SUCCESS);
  82677. /*--------------------------------------------*/
  82678. /* tests for wolfSSL_CTX_set_server_cert_type */
  82679. /*--------------------------------------------*/
  82680. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  82681. MAX_SERVER_CERT_TYPE_CNT),
  82682. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82683. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82684. sizeof(ctype)),
  82685. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82686. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82687. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82688. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82689. MAX_SERVER_CERT_TYPE_CNT),
  82690. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82691. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82692. ctype[1] = 10; /* set unknown cert type */
  82693. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82694. MAX_SERVER_CERT_TYPE_CNT),
  82695. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82696. /* pass larger type count */
  82697. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82698. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82699. ctype[2] = 1; /* pass unacceptable type count */
  82700. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82701. MAX_SERVER_CERT_TYPE_CNT + 1),
  82702. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82703. /* should accept NULL for type buffer */
  82704. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  82705. MAX_SERVER_CERT_TYPE_CNT),
  82706. WOLFSSL_SUCCESS);
  82707. /* should accept zero for type count */
  82708. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82709. 0),
  82710. WOLFSSL_SUCCESS);
  82711. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82712. MAX_SERVER_CERT_TYPE_CNT),
  82713. WOLFSSL_SUCCESS);
  82714. /*------------------------------------------------*/
  82715. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  82716. /*------------------------------------------------*/
  82717. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  82718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82719. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  82720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82721. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  82722. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82723. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  82724. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82725. /* clean up */
  82726. wolfSSL_free(ssl);
  82727. wolfSSL_CTX_free(ctx);
  82728. #endif
  82729. return EXPECT_RESULT();
  82730. }
  82731. static int test_tls13_rpk_handshake(void)
  82732. {
  82733. EXPECT_DECLS;
  82734. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  82735. #ifdef WOLFSSL_TLS13
  82736. int ret = 0;
  82737. #endif
  82738. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82739. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82740. struct test_memio_ctx test_ctx;
  82741. int err;
  82742. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  82743. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  82744. int typeCnt_c;
  82745. int typeCnt_s;
  82746. int tp = 0;
  82747. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82748. int isServer;
  82749. #endif
  82750. (void)err;
  82751. (void)typeCnt_c;
  82752. (void)typeCnt_s;
  82753. (void)certType_c;
  82754. (void)certType_s;
  82755. #ifndef WOLFSSL_NO_TLS12
  82756. /* TLS1.2
  82757. * Both client and server load x509 cert and start handshaking.
  82758. * Check no negotiation occurred.
  82759. */
  82760. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82761. ExpectIntEQ(
  82762. test_rpk_memio_setup(
  82763. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82764. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82765. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82766. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82767. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82768. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  82769. , 0);
  82770. /* set client certificate type in client end */
  82771. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82772. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82773. typeCnt_c = 2;
  82774. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82775. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82776. typeCnt_s = 2;
  82777. /* both client and server do not call client/server_cert_type APIs,
  82778. * expecting default settings works and no negotiation performed.
  82779. */
  82780. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82781. return TEST_FAIL;
  82782. /* confirm no negotiation occurred */
  82783. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82784. WOLFSSL_SUCCESS);
  82785. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82786. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82787. WOLFSSL_SUCCESS);
  82788. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82789. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82790. WOLFSSL_SUCCESS);
  82791. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82792. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82793. WOLFSSL_SUCCESS);
  82794. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82795. (void)typeCnt_c;
  82796. (void)typeCnt_s;
  82797. wolfSSL_free(ssl_c);
  82798. wolfSSL_CTX_free(ctx_c);
  82799. wolfSSL_free(ssl_s);
  82800. wolfSSL_CTX_free(ctx_s);
  82801. ssl_c = ssl_s = NULL;
  82802. ctx_c = ctx_s = NULL;
  82803. #endif
  82804. #ifdef WOLFSSL_TLS13
  82805. /* Both client and server load x509 cert and start handshaking.
  82806. * Check no negotiation occurred.
  82807. */
  82808. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82809. ExpectIntEQ(
  82810. test_rpk_memio_setup(
  82811. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82812. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82813. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82814. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82815. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82816. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82817. , 0);
  82818. /* set client certificate type in client end */
  82819. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82820. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82821. typeCnt_c = 2;
  82822. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82823. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82824. typeCnt_s = 2;
  82825. /* both client and server do not call client/server_cert_type APIs,
  82826. * expecting default settings works and no negotiation performed.
  82827. */
  82828. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82829. return TEST_FAIL;
  82830. /* confirm no negotiation occurred */
  82831. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82832. WOLFSSL_SUCCESS);
  82833. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82834. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82835. WOLFSSL_SUCCESS);
  82836. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82837. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82838. WOLFSSL_SUCCESS);
  82839. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82840. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82841. WOLFSSL_SUCCESS);
  82842. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82843. (void)typeCnt_c;
  82844. (void)typeCnt_s;
  82845. wolfSSL_free(ssl_c);
  82846. wolfSSL_CTX_free(ctx_c);
  82847. wolfSSL_free(ssl_s);
  82848. wolfSSL_CTX_free(ctx_s);
  82849. ssl_c = ssl_s = NULL;
  82850. ctx_c = ctx_s = NULL;
  82851. /* Both client and server load RPK cert and start handshaking.
  82852. * Confirm negotiated cert types match as expected.
  82853. */
  82854. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82855. ExpectIntEQ(
  82856. test_rpk_memio_setup(
  82857. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82858. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82859. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82860. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82861. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82862. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82863. , 0);
  82864. /* set client certificate type in client end */
  82865. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82866. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82867. typeCnt_c = 2;
  82868. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82869. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82870. typeCnt_s = 2;
  82871. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82872. WOLFSSL_SUCCESS);
  82873. /* set server certificate type in client end */
  82874. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82875. WOLFSSL_SUCCESS);
  82876. /* set client certificate type in server end */
  82877. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82878. WOLFSSL_SUCCESS);
  82879. /* set server certificate type in server end */
  82880. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82881. WOLFSSL_SUCCESS);
  82882. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82883. return TEST_FAIL;
  82884. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82885. WOLFSSL_SUCCESS);
  82886. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82887. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82888. WOLFSSL_SUCCESS);
  82889. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82890. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82891. WOLFSSL_SUCCESS);
  82892. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82893. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82894. WOLFSSL_SUCCESS);
  82895. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82896. wolfSSL_free(ssl_c);
  82897. wolfSSL_CTX_free(ctx_c);
  82898. wolfSSL_free(ssl_s);
  82899. wolfSSL_CTX_free(ctx_s);
  82900. ssl_c = ssl_s = NULL;
  82901. ctx_c = ctx_s = NULL;
  82902. #endif
  82903. #ifndef WOLFSSL_NO_TLS12
  82904. /* TLS1.2
  82905. * Both client and server load RPK cert and start handshaking.
  82906. * Confirm negotiated cert types match as expected.
  82907. */
  82908. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82909. ExpectIntEQ(
  82910. test_rpk_memio_setup(
  82911. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82912. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82913. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82914. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82915. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82916. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82917. , 0);
  82918. /* set client certificate type in client end */
  82919. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82920. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82921. typeCnt_c = 2;
  82922. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82923. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82924. typeCnt_s = 2;
  82925. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82926. WOLFSSL_SUCCESS);
  82927. /* set server certificate type in client end */
  82928. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82929. WOLFSSL_SUCCESS);
  82930. /* set client certificate type in server end */
  82931. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82932. WOLFSSL_SUCCESS);
  82933. /* set server certificate type in server end */
  82934. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82935. WOLFSSL_SUCCESS);
  82936. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82937. return TEST_FAIL;
  82938. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82939. WOLFSSL_SUCCESS);
  82940. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82941. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82942. WOLFSSL_SUCCESS);
  82943. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82944. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82945. WOLFSSL_SUCCESS);
  82946. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82947. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82948. WOLFSSL_SUCCESS);
  82949. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82950. wolfSSL_free(ssl_c);
  82951. wolfSSL_CTX_free(ctx_c);
  82952. wolfSSL_free(ssl_s);
  82953. wolfSSL_CTX_free(ctx_s);
  82954. ssl_c = ssl_s = NULL;
  82955. ctx_c = ctx_s = NULL;
  82956. #endif
  82957. #ifdef WOLFSSL_TLS13
  82958. /* Both client and server load x509 cert.
  82959. * Have client call set_client_cert_type with both RPK and x509.
  82960. * This doesn't makes client add client cert type extension to ClientHello,
  82961. * since it does not load RPK cert actually.
  82962. */
  82963. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82964. ExpectIntEQ(
  82965. test_rpk_memio_setup(
  82966. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82967. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82968. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82969. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82970. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82971. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82972. , 0);
  82973. /* set client certificate type in client end
  82974. *
  82975. * client indicates both RPK and x509 certs are available but loaded RPK
  82976. * cert only. It does not have client add client-cert-type extension in CH.
  82977. */
  82978. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82979. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82980. typeCnt_c = 2;
  82981. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82982. WOLFSSL_SUCCESS);
  82983. /* client indicates both RPK and x509 certs are acceptable */
  82984. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82985. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82986. typeCnt_s = 2;
  82987. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82988. WOLFSSL_SUCCESS);
  82989. /* server indicates both RPK and x509 certs are acceptable */
  82990. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82991. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82992. typeCnt_c = 2;
  82993. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82994. WOLFSSL_SUCCESS);
  82995. /* server should indicate only RPK cert is available */
  82996. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82997. certType_s[1] = -1;
  82998. typeCnt_s = 1;
  82999. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83000. WOLFSSL_SUCCESS);
  83001. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83002. return TEST_FAIL;
  83003. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  83004. * be returned as cert type.
  83005. */
  83006. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83007. WOLFSSL_SUCCESS);
  83008. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83009. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83010. WOLFSSL_SUCCESS);
  83011. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83012. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83013. WOLFSSL_SUCCESS);
  83014. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83015. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83016. WOLFSSL_SUCCESS);
  83017. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83018. wolfSSL_free(ssl_c);
  83019. wolfSSL_CTX_free(ctx_c);
  83020. wolfSSL_free(ssl_s);
  83021. wolfSSL_CTX_free(ctx_s);
  83022. ssl_c = ssl_s = NULL;
  83023. ctx_c = ctx_s = NULL;
  83024. /* Have client load RPK cert and have server load x509 cert.
  83025. * Check the negotiation result from both ends.
  83026. */
  83027. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83028. ExpectIntEQ(
  83029. test_rpk_memio_setup(
  83030. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83031. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83032. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83033. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83034. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83035. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83036. , 0);
  83037. /* have client tell to use RPK cert */
  83038. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83039. certType_c[1] = -1;
  83040. typeCnt_c = 1;
  83041. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83042. WOLFSSL_SUCCESS);
  83043. /* have client tell to accept both RPK and x509 cert */
  83044. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83045. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83046. typeCnt_s = 2;
  83047. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83048. WOLFSSL_SUCCESS);
  83049. /* have server accept to both RPK and x509 cert */
  83050. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83051. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83052. typeCnt_c = 2;
  83053. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83054. WOLFSSL_SUCCESS);
  83055. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  83056. * end, expecting the default setting works.
  83057. */
  83058. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83059. return TEST_FAIL;
  83060. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83061. WOLFSSL_SUCCESS);
  83062. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83063. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83064. WOLFSSL_SUCCESS);
  83065. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83066. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83067. WOLFSSL_SUCCESS);
  83068. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83069. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83070. WOLFSSL_SUCCESS);
  83071. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83072. wolfSSL_free(ssl_c);
  83073. wolfSSL_CTX_free(ctx_c);
  83074. wolfSSL_free(ssl_s);
  83075. wolfSSL_CTX_free(ctx_s);
  83076. ssl_c = ssl_s = NULL;
  83077. ctx_c = ctx_s = NULL;
  83078. /* Have both client and server load RPK cert, however, have server
  83079. * indicate its cert type x509.
  83080. * Client is expected to detect the cert type mismatch then to send alert
  83081. * with "unsupported_certificate".
  83082. */
  83083. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83084. ExpectIntEQ(
  83085. test_rpk_memio_setup(
  83086. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83087. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83088. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83089. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  83090. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83091. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83092. , 0);
  83093. /* have client tell to use RPK cert */
  83094. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83095. certType_c[1] = -1;
  83096. typeCnt_c = 1;
  83097. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83098. WOLFSSL_SUCCESS);
  83099. /* have client tell to accept both RPK and x509 cert */
  83100. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83101. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83102. typeCnt_s = 2;
  83103. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83104. WOLFSSL_SUCCESS);
  83105. /* have server accept to both RPK and x509 cert */
  83106. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83107. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83108. typeCnt_c = 2;
  83109. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83110. WOLFSSL_SUCCESS);
  83111. /* have server tell to use x509 cert intentionally. This will bring
  83112. * certificate type mismatch in client side.
  83113. */
  83114. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83115. certType_s[1] = -1;
  83116. typeCnt_s = 1;
  83117. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83118. WOLFSSL_SUCCESS);
  83119. /* expect client detect cert type mismatch then send Alert */
  83120. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83121. if (ret != -1)
  83122. return TEST_FAIL;
  83123. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83124. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83125. WOLFSSL_SUCCESS);
  83126. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83127. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83128. WOLFSSL_SUCCESS);
  83129. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83130. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83131. WOLFSSL_SUCCESS);
  83132. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83133. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83134. WOLFSSL_SUCCESS);
  83135. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83136. wolfSSL_free(ssl_c);
  83137. wolfSSL_CTX_free(ctx_c);
  83138. wolfSSL_free(ssl_s);
  83139. wolfSSL_CTX_free(ctx_s);
  83140. ssl_c = ssl_s = NULL;
  83141. ctx_c = ctx_s = NULL;
  83142. /* Have client load x509 cert and server load RPK cert,
  83143. * however, have client indicate its cert type RPK.
  83144. * Server is expected to detect the cert type mismatch then to send alert
  83145. * with "unsupported_certificate".
  83146. */
  83147. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83148. ExpectIntEQ(
  83149. test_rpk_memio_setup(
  83150. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83151. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83152. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83153. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83154. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83155. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83156. , 0);
  83157. /* have client tell to use RPK cert intentionally */
  83158. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83159. certType_c[1] = -1;
  83160. typeCnt_c = 1;
  83161. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83162. WOLFSSL_SUCCESS);
  83163. /* have client tell to accept both RPK and x509 cert */
  83164. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83165. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83166. typeCnt_s = 2;
  83167. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83168. WOLFSSL_SUCCESS);
  83169. /* have server accept to both RPK and x509 cert */
  83170. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83171. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83172. typeCnt_c = 2;
  83173. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83174. WOLFSSL_SUCCESS);
  83175. /* have server tell to use x509 cert intentionally. This will bring
  83176. * certificate type mismatch in client side.
  83177. */
  83178. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83179. certType_s[1] = -1;
  83180. typeCnt_s = 1;
  83181. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83182. WOLFSSL_SUCCESS);
  83183. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83184. /* expect server detect cert type mismatch then send Alert */
  83185. ExpectIntNE(ret, 0);
  83186. err = wolfSSL_get_error(ssl_c, ret);
  83187. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83188. /* client did not load RPK cert actually, so negotiation did not happen */
  83189. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83190. WOLFSSL_SUCCESS);
  83191. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83192. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83193. WOLFSSL_SUCCESS);
  83194. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83195. /* client did not load RPK cert actually, so negotiation did not happen */
  83196. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83197. WOLFSSL_SUCCESS);
  83198. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83199. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83200. WOLFSSL_SUCCESS);
  83201. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83202. wolfSSL_free(ssl_c);
  83203. wolfSSL_CTX_free(ctx_c);
  83204. wolfSSL_free(ssl_s);
  83205. wolfSSL_CTX_free(ctx_s);
  83206. ssl_c = ssl_s = NULL;
  83207. ctx_c = ctx_s = NULL;
  83208. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  83209. /* Both client and server load RPK cert and set certificate verify
  83210. * callbacks then start handshaking.
  83211. * Confirm both side can refer the peer's cert.
  83212. */
  83213. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83214. ExpectIntEQ(
  83215. test_rpk_memio_setup(
  83216. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83217. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83218. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83219. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83220. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83221. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83222. , 0);
  83223. /* set client certificate type in client end */
  83224. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83225. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83226. typeCnt_c = 2;
  83227. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83228. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83229. typeCnt_s = 2;
  83230. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83231. WOLFSSL_SUCCESS);
  83232. /* set server certificate type in client end */
  83233. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83234. WOLFSSL_SUCCESS);
  83235. /* set client certificate type in server end */
  83236. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83237. WOLFSSL_SUCCESS);
  83238. /* set server certificate type in server end */
  83239. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83240. WOLFSSL_SUCCESS);
  83241. /* set certificate verify callback to both client and server */
  83242. isServer = 0;
  83243. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  83244. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  83245. isServer = 1;
  83246. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  83247. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  83248. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83249. if (ret != 0)
  83250. return TEST_FAIL;
  83251. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83252. WOLFSSL_SUCCESS);
  83253. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83254. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83255. WOLFSSL_SUCCESS);
  83256. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83257. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83258. WOLFSSL_SUCCESS);
  83259. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83260. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83261. WOLFSSL_SUCCESS);
  83262. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83263. wolfSSL_free(ssl_c);
  83264. wolfSSL_CTX_free(ctx_c);
  83265. wolfSSL_free(ssl_s);
  83266. wolfSSL_CTX_free(ctx_s);
  83267. ssl_c = ssl_s = NULL;
  83268. ctx_c = ctx_s = NULL;
  83269. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  83270. #endif /* WOLFSSL_TLS13 */
  83271. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  83272. return EXPECT_RESULT();
  83273. }
  83274. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83275. static int test_dtls13_bad_epoch_ch(void)
  83276. {
  83277. EXPECT_DECLS;
  83278. WOLFSSL_CTX *ctx_c = NULL;
  83279. WOLFSSL_CTX *ctx_s = NULL;
  83280. WOLFSSL *ssl_c = NULL;
  83281. WOLFSSL *ssl_s = NULL;
  83282. struct test_memio_ctx test_ctx;
  83283. const int EPOCH_OFF = 3;
  83284. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83285. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83286. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83287. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  83288. * with just one message */
  83289. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  83290. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83291. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83292. WOLFSSL_ERROR_WANT_READ);
  83293. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  83294. /* first CH should use epoch 0x0 */
  83295. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  83296. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  83297. /* change epoch to 2 */
  83298. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  83299. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83300. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83301. WOLFSSL_ERROR_WANT_READ);
  83302. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  83303. /* resend the CH */
  83304. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83305. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83306. wolfSSL_free(ssl_c);
  83307. wolfSSL_CTX_free(ctx_c);
  83308. wolfSSL_free(ssl_s);
  83309. wolfSSL_CTX_free(ctx_s);
  83310. return EXPECT_RESULT();
  83311. }
  83312. #else
  83313. static int test_dtls13_bad_epoch_ch(void)
  83314. {
  83315. return TEST_SKIPPED;
  83316. }
  83317. #endif
  83318. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83319. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83320. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  83321. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83322. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  83323. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83324. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  83325. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  83326. {
  83327. EXPECT_DECLS;
  83328. WOLFSSL_SESSION *sess = NULL;
  83329. /* Setup the session to avoid errors */
  83330. ssl->session->timeout = -1;
  83331. ssl->session->side = WOLFSSL_CLIENT_END;
  83332. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  83333. defined(HAVE_SESSION_TICKET))
  83334. ssl->session->version = ssl->version;
  83335. #endif
  83336. /* Force a short session ID to be sent */
  83337. ssl->session->sessionIDSz = 4;
  83338. #ifndef NO_SESSION_CACHE_REF
  83339. /* Allow the client cache to be used */
  83340. ssl->session->idLen = 4;
  83341. #endif
  83342. ssl->session->isSetup = 1;
  83343. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  83344. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  83345. return EXPECT_RESULT();
  83346. }
  83347. static int test_short_session_id(void)
  83348. {
  83349. EXPECT_DECLS;
  83350. test_ssl_cbf client_cbf;
  83351. test_ssl_cbf server_cbf;
  83352. size_t i;
  83353. struct {
  83354. method_provider client_meth;
  83355. method_provider server_meth;
  83356. const char* tls_version;
  83357. } params[] = {
  83358. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83359. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83360. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  83361. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  83362. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  83363. #ifdef WOLFSSL_DTLS13
  83364. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  83365. #endif
  83366. #endif
  83367. #ifndef WOLFSSL_NO_TLS12
  83368. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  83369. #ifdef WOLFSSL_DTLS
  83370. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  83371. #endif
  83372. #endif
  83373. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83374. !defined(NO_DES3))
  83375. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  83376. #ifdef WOLFSSL_DTLS
  83377. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  83378. #endif
  83379. #endif
  83380. };
  83381. fprintf(stderr, "\n");
  83382. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  83383. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  83384. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  83385. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  83386. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  83387. client_cbf.method = params[i].client_meth;
  83388. server_cbf.method = params[i].server_meth;
  83389. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  83390. &server_cbf, NULL), TEST_SUCCESS);
  83391. }
  83392. return EXPECT_RESULT();
  83393. }
  83394. #else
  83395. static int test_short_session_id(void)
  83396. {
  83397. return TEST_SKIPPED;
  83398. }
  83399. #endif
  83400. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  83401. && defined(WOLFSSL_DTLS13)
  83402. static byte* test_find_string(const char *string,
  83403. byte *buf, int buf_size)
  83404. {
  83405. int string_size, i;
  83406. string_size = (int)XSTRLEN(string);
  83407. for (i = 0; i < buf_size - string_size - 1; i++) {
  83408. if (XSTRCMP((char*)&buf[i], string) == 0)
  83409. return &buf[i];
  83410. }
  83411. return NULL;
  83412. }
  83413. static int test_wolfSSL_dtls13_null_cipher(void)
  83414. {
  83415. EXPECT_DECLS;
  83416. WOLFSSL_CTX *ctx_c = NULL;
  83417. WOLFSSL_CTX *ctx_s = NULL;
  83418. WOLFSSL *ssl_c = NULL;
  83419. WOLFSSL *ssl_s = NULL;
  83420. struct test_memio_ctx test_ctx;
  83421. const char *test_str = "test";
  83422. int test_str_size;
  83423. byte buf[255], *ptr = NULL;
  83424. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83425. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  83426. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83427. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83428. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83429. test_str_size = XSTRLEN("test") + 1;
  83430. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83431. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  83432. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  83433. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83434. /* check that the packet was sent cleartext */
  83435. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  83436. test_ctx.s_len));
  83437. if (ptr != NULL) {
  83438. /* modify the message */
  83439. *ptr = 'H';
  83440. /* bad messages should be ignored in DTLS */
  83441. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  83442. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  83443. }
  83444. wolfSSL_free(ssl_c);
  83445. wolfSSL_free(ssl_s);
  83446. wolfSSL_CTX_free(ctx_c);
  83447. wolfSSL_CTX_free(ctx_s);
  83448. return TEST_SUCCESS;
  83449. }
  83450. #else
  83451. static int test_wolfSSL_dtls13_null_cipher(void)
  83452. {
  83453. return TEST_SKIPPED;
  83454. }
  83455. #endif
  83456. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83457. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83458. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  83459. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  83460. {
  83461. SOCKADDR_S peer;
  83462. XSOCKLENT len;
  83463. int ret;
  83464. XMEMSET((byte*)&peer, 0, sizeof(peer));
  83465. len = sizeof(peer);
  83466. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  83467. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  83468. return -1;
  83469. switch (peer.ss_family) {
  83470. #ifdef WOLFSSL_IPV6
  83471. case WOLFSSL_IP6: {
  83472. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  83473. break;
  83474. }
  83475. #endif /* WOLFSSL_IPV6 */
  83476. case WOLFSSL_IP4:
  83477. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  83478. break;
  83479. default:
  83480. return -1;
  83481. }
  83482. return 0;
  83483. }
  83484. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  83485. {
  83486. char buf[1] = {'t'};
  83487. SOCKADDR_IN_T addr;
  83488. int sock_fd;
  83489. word16 port;
  83490. int err;
  83491. (void)ssl;
  83492. (void)ctx;
  83493. if (ssl == NULL)
  83494. return -1;
  83495. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  83496. if (err != 0)
  83497. return -1;
  83498. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  83499. if (sock_fd == -1)
  83500. return -1;
  83501. build_addr(&addr, wolfSSLIP, port, 1, 0);
  83502. /* send a packet to the server. Being another socket, the kernel will ensure
  83503. * the source port will be different. */
  83504. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  83505. sizeof(addr));
  83506. close(sock_fd);
  83507. if (err == -1)
  83508. return -1;
  83509. return 0;
  83510. }
  83511. /* setup a SSL session but just after the handshake send a packet to the server
  83512. * with a source address different than the one of the connected client. The I/O
  83513. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  83514. * is done in test_dtls_msg_from_other_peer_cb */
  83515. static int test_dtls_msg_from_other_peer(void)
  83516. {
  83517. EXPECT_DECLS;
  83518. callback_functions client_cbs;
  83519. callback_functions server_cbs;
  83520. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  83521. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  83522. client_cbs.method = wolfDTLSv1_2_client_method;
  83523. server_cbs.method = wolfDTLSv1_2_server_method;
  83524. client_cbs.doUdp = 1;
  83525. server_cbs.doUdp = 1;
  83526. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  83527. test_dtls_msg_from_other_peer_cb);
  83528. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  83529. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  83530. return EXPECT_RESULT();
  83531. }
  83532. #else
  83533. static int test_dtls_msg_from_other_peer(void)
  83534. {
  83535. return TEST_SKIPPED;
  83536. }
  83537. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83538. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83539. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  83540. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  83541. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83542. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83543. static int test_dtls_ipv6_check(void)
  83544. {
  83545. EXPECT_DECLS;
  83546. WOLFSSL_CTX *ctx_c = NULL;
  83547. WOLFSSL_CTX *ctx_s = NULL;
  83548. WOLFSSL *ssl_c = NULL;
  83549. WOLFSSL *ssl_s = NULL;
  83550. SOCKADDR_IN fake_addr6;
  83551. int sockfd = -1;
  83552. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  83553. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  83554. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  83555. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  83556. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83557. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  83558. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83559. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  83560. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  83561. /* mimic a sockaddr_in6 struct, this way we can't test without
  83562. * WOLFSSL_IPV6 */
  83563. fake_addr6.sin_family = WOLFSSL_IP6;
  83564. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  83565. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83566. /* can't return error here, as the peer is opaque for wolfssl library at
  83567. * this point */
  83568. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  83569. WOLFSSL_SUCCESS);
  83570. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  83571. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  83572. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83573. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83574. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  83575. WOLFSSL_SUCCESS);
  83576. /* reuse the socket */
  83577. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83578. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  83579. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83580. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83581. if (sockfd != -1)
  83582. close(sockfd);
  83583. wolfSSL_free(ssl_c);
  83584. wolfSSL_CTX_free(ctx_c);
  83585. wolfSSL_free(ssl_s);
  83586. wolfSSL_CTX_free(ctx_s);
  83587. return EXPECT_RESULT();
  83588. }
  83589. #else
  83590. static int test_dtls_ipv6_check(void)
  83591. {
  83592. return TEST_SKIPPED;
  83593. }
  83594. #endif
  83595. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83596. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83597. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  83598. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  83599. {
  83600. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83601. }
  83602. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  83603. {
  83604. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  83605. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  83606. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  83607. }
  83608. else {
  83609. char testMsg[] = "Message after SCR";
  83610. char msgBuf[sizeof(testMsg)];
  83611. int ret;
  83612. if (!wolfSSL_is_server(ssl)) {
  83613. AssertIntEQ(WOLFSSL_SUCCESS,
  83614. wolfSSL_set_session(ssl,
  83615. test_wolfSSL_SCR_after_resumption_session));
  83616. }
  83617. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83618. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83619. sizeof(testMsg));
  83620. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83621. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  83622. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83623. AssertIntEQ(ret, sizeof(msgBuf));
  83624. }
  83625. }
  83626. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  83627. {
  83628. AssertIntEQ(WOLFSSL_SUCCESS,
  83629. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  83630. }
  83631. static int test_wolfSSL_SCR_after_resumption(void)
  83632. {
  83633. EXPECT_DECLS;
  83634. callback_functions func_cb_client;
  83635. callback_functions func_cb_server;
  83636. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83637. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83638. func_cb_client.method = wolfTLSv1_2_client_method;
  83639. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83640. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83641. func_cb_server.method = wolfTLSv1_2_server_method;
  83642. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83643. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83644. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83645. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83646. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  83647. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83648. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83649. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83650. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83651. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  83652. return EXPECT_RESULT();
  83653. }
  83654. #else
  83655. static int test_wolfSSL_SCR_after_resumption(void)
  83656. {
  83657. return TEST_SKIPPED;
  83658. }
  83659. #endif
  83660. static int test_wolfSSL_configure_args(void)
  83661. {
  83662. EXPECT_DECLS;
  83663. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  83664. ExpectNotNull(wolfSSL_configure_args());
  83665. #endif
  83666. return EXPECT_RESULT();
  83667. }
  83668. static int test_dtls_no_extensions(void)
  83669. {
  83670. EXPECT_DECLS;
  83671. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  83672. !defined(WOLFSSL_NO_TLS12)
  83673. WOLFSSL *ssl_s = NULL;
  83674. WOLFSSL_CTX *ctx_s = NULL;
  83675. struct test_memio_ctx test_ctx;
  83676. const byte chNoExtensions[] = {
  83677. /* Handshake type */
  83678. 0x16,
  83679. /* Version */
  83680. 0xfe, 0xff,
  83681. /* Epoch */
  83682. 0x00, 0x00,
  83683. /* Seq number */
  83684. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83685. /* Length */
  83686. 0x00, 0x40,
  83687. /* CH type */
  83688. 0x01,
  83689. /* Length */
  83690. 0x00, 0x00, 0x34,
  83691. /* Msg Seq */
  83692. 0x00, 0x00,
  83693. /* Frag offset */
  83694. 0x00, 0x00, 0x00,
  83695. /* Frag length */
  83696. 0x00, 0x00, 0x34,
  83697. /* Version */
  83698. 0xfe, 0xff,
  83699. /* Random */
  83700. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  83701. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  83702. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  83703. /* Session Length */
  83704. 0x00,
  83705. /* Cookie Length */
  83706. 0x00,
  83707. /* CS Length */
  83708. 0x00, 0x0c,
  83709. /* CS */
  83710. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  83711. /* Comp Meths Length */
  83712. 0x01,
  83713. /* Comp Meths */
  83714. 0x00
  83715. /* And finally... no extensions */
  83716. };
  83717. int i;
  83718. #ifdef OPENSSL_EXTRA
  83719. int repeats = 2;
  83720. #else
  83721. int repeats = 1;
  83722. #endif
  83723. for (i = 0; i < repeats; i++) {
  83724. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83725. ssl_s = NULL;
  83726. ctx_s = NULL;
  83727. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  83728. NULL, wolfDTLS_server_method), 0);
  83729. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  83730. test_ctx.s_len = sizeof(chNoExtensions);
  83731. #ifdef OPENSSL_EXTRA
  83732. if (i > 0) {
  83733. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  83734. WOLFSSL_SUCCESS);
  83735. }
  83736. #endif
  83737. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  83738. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83739. /* Expecting a handshake msg. Either HVR or SH. */
  83740. ExpectIntGT(test_ctx.c_len, 0);
  83741. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  83742. wolfSSL_free(ssl_s);
  83743. wolfSSL_CTX_free(ctx_s);
  83744. }
  83745. #endif
  83746. return EXPECT_RESULT();
  83747. }
  83748. static int test_tls_alert_no_server_hello(void)
  83749. {
  83750. EXPECT_DECLS;
  83751. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83752. WOLFSSL *ssl_c = NULL;
  83753. WOLFSSL_CTX *ctx_c = NULL;
  83754. struct test_memio_ctx test_ctx;
  83755. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  83756. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83757. ssl_c = NULL;
  83758. ctx_c = NULL;
  83759. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83760. wolfTLSv1_2_client_method, NULL), 0);
  83761. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  83762. test_ctx.c_len = sizeof(alert_msg);
  83763. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83764. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  83765. wolfSSL_free(ssl_c);
  83766. wolfSSL_CTX_free(ctx_c);
  83767. #endif
  83768. return EXPECT_RESULT();
  83769. }
  83770. static int test_TLSX_CA_NAMES_bad_extension(void)
  83771. {
  83772. EXPECT_DECLS;
  83773. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83774. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  83775. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  83776. defined(HAVE_NULL_CIPHER)
  83777. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  83778. * parse the CA Names extension. Otherwise it will return other non-related
  83779. * errors. If CA Names will be parsed in more configurations, that should
  83780. * be reflected in the macro guard above. */
  83781. WOLFSSL *ssl_c = NULL;
  83782. WOLFSSL_CTX *ctx_c = NULL;
  83783. struct test_memio_ctx test_ctx;
  83784. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  83785. const byte shBadCaNamesExt[] = {
  83786. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83787. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83788. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83789. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83790. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83791. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83792. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  83793. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  83794. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  83795. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83796. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  83797. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  83798. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  83799. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  83800. };
  83801. const byte shBadCaNamesExt2[] = {
  83802. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83803. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83804. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83805. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83806. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83807. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83808. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  83809. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  83810. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  83811. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83812. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  83813. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  83814. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  83815. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  83816. };
  83817. int i = 0;
  83818. for (i = 0; i < 2; i++) {
  83819. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83820. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83821. wolfTLSv1_3_client_method, NULL), 0);
  83822. switch (i) {
  83823. case 0:
  83824. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  83825. sizeof(shBadCaNamesExt));
  83826. test_ctx.c_len = sizeof(shBadCaNamesExt);
  83827. break;
  83828. case 1:
  83829. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  83830. sizeof(shBadCaNamesExt2));
  83831. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  83832. break;
  83833. }
  83834. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83835. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  83836. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  83837. #else
  83838. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  83839. #endif
  83840. wolfSSL_free(ssl_c);
  83841. ssl_c = NULL;
  83842. wolfSSL_CTX_free(ctx_c);
  83843. ctx_c = NULL;
  83844. }
  83845. #endif
  83846. return EXPECT_RESULT();
  83847. }
  83848. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83849. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83850. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  83851. {
  83852. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83853. WOLFSSL_SUCCESS);
  83854. }
  83855. static int test_dtls_1_0_hvr_downgrade(void)
  83856. {
  83857. EXPECT_DECLS;
  83858. callback_functions func_cb_client;
  83859. callback_functions func_cb_server;
  83860. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83861. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83862. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83863. func_cb_client.method = wolfDTLS_client_method;
  83864. func_cb_server.method = wolfDTLSv1_2_server_method;
  83865. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  83866. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83867. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83868. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83869. return EXPECT_RESULT();
  83870. }
  83871. #else
  83872. static int test_dtls_1_0_hvr_downgrade(void)
  83873. {
  83874. EXPECT_DECLS;
  83875. return EXPECT_RESULT();
  83876. }
  83877. #endif
  83878. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  83879. defined(HAVE_SESSION_TICKET)
  83880. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  83881. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  83882. {
  83883. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  83884. AssertNotNull(test_session_ticket_no_id_session);
  83885. }
  83886. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  83887. {
  83888. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  83889. }
  83890. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  83891. {
  83892. test_session_ticket_no_id_session->sessionIDSz = 0;
  83893. AssertIntEQ(WOLFSSL_SUCCESS,
  83894. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  83895. }
  83896. static int test_session_ticket_no_id(void)
  83897. {
  83898. /* We are testing an expired (invalid crypto context in out case since the
  83899. * ctx changes) session ticket being sent with the session ID being 0
  83900. * length. */
  83901. EXPECT_DECLS;
  83902. callback_functions func_cb_client;
  83903. callback_functions func_cb_server;
  83904. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83905. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83906. func_cb_client.method = wolfTLSv1_2_client_method;
  83907. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83908. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  83909. func_cb_server.method = wolfTLSv1_2_server_method;
  83910. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83911. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83912. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83913. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83914. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83915. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83916. func_cb_client.method = wolfTLSv1_2_client_method;
  83917. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83918. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  83919. func_cb_server.method = wolfTLSv1_2_server_method;
  83920. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83921. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83922. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83923. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83924. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  83925. return EXPECT_RESULT();
  83926. }
  83927. #else
  83928. static int test_session_ticket_no_id(void)
  83929. {
  83930. EXPECT_DECLS;
  83931. return EXPECT_RESULT();
  83932. }
  83933. #endif
  83934. static int test_session_ticket_hs_update(void)
  83935. {
  83936. EXPECT_DECLS;
  83937. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83938. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  83939. struct test_memio_ctx test_ctx;
  83940. struct test_memio_ctx test_ctx2;
  83941. struct test_memio_ctx test_ctx3;
  83942. WOLFSSL_CTX *ctx_c = NULL;
  83943. WOLFSSL_CTX *ctx_s = NULL;
  83944. WOLFSSL *ssl_c = NULL;
  83945. WOLFSSL *ssl_c2 = NULL;
  83946. WOLFSSL *ssl_c3 = NULL;
  83947. WOLFSSL *ssl_s = NULL;
  83948. WOLFSSL *ssl_s2 = NULL;
  83949. WOLFSSL *ssl_s3 = NULL;
  83950. WOLFSSL_SESSION *sess = NULL;
  83951. byte read_data[1];
  83952. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83953. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  83954. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  83955. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83956. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83957. /* Generate tickets */
  83958. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83959. wolfSSL_SetLoggingPrefix("client");
  83960. /* Read the ticket msg */
  83961. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  83962. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83963. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83964. WOLFSSL_ERROR_WANT_READ);
  83965. wolfSSL_SetLoggingPrefix(NULL);
  83966. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  83967. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83968. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  83969. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83970. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  83971. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  83972. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  83973. wolfSSL_SetLoggingPrefix("client");
  83974. /* Exchange initial flights for the second connection */
  83975. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83976. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83977. WOLFSSL_ERROR_WANT_READ);
  83978. wolfSSL_SetLoggingPrefix(NULL);
  83979. wolfSSL_SetLoggingPrefix("server");
  83980. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83981. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83982. WOLFSSL_ERROR_WANT_READ);
  83983. wolfSSL_SetLoggingPrefix(NULL);
  83984. /* Complete third connection so that new tickets are exchanged */
  83985. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  83986. /* Read the ticket msg */
  83987. wolfSSL_SetLoggingPrefix("client");
  83988. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  83989. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83990. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83991. WOLFSSL_ERROR_WANT_READ);
  83992. wolfSSL_SetLoggingPrefix(NULL);
  83993. /* Complete second connection */
  83994. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  83995. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  83996. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  83997. wolfSSL_free(ssl_c);
  83998. wolfSSL_free(ssl_c2);
  83999. wolfSSL_free(ssl_c3);
  84000. wolfSSL_free(ssl_s);
  84001. wolfSSL_free(ssl_s2);
  84002. wolfSSL_free(ssl_s3);
  84003. wolfSSL_CTX_free(ctx_c);
  84004. wolfSSL_CTX_free(ctx_s);
  84005. wolfSSL_SESSION_free(sess);
  84006. #endif
  84007. return EXPECT_RESULT();
  84008. }
  84009. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84010. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84011. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  84012. {
  84013. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84014. WOLFSSL_SUCCESS);
  84015. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84016. }
  84017. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  84018. {
  84019. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84020. }
  84021. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  84022. {
  84023. char testMsg[] = "Message after SCR";
  84024. char msgBuf[sizeof(testMsg)];
  84025. if (wolfSSL_is_server(ssl)) {
  84026. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84027. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84028. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84029. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84030. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84031. sizeof(testMsg));
  84032. }
  84033. else {
  84034. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84035. sizeof(testMsg));
  84036. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84037. }
  84038. }
  84039. static int test_dtls_downgrade_scr_server(void)
  84040. {
  84041. EXPECT_DECLS;
  84042. callback_functions func_cb_client;
  84043. callback_functions func_cb_server;
  84044. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84045. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84046. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84047. func_cb_client.method = wolfDTLSv1_2_client_method;
  84048. func_cb_server.method = wolfDTLS_server_method;
  84049. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  84050. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  84051. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  84052. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  84053. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84054. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84055. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84056. return EXPECT_RESULT();
  84057. }
  84058. #else
  84059. static int test_dtls_downgrade_scr_server(void)
  84060. {
  84061. EXPECT_DECLS;
  84062. return EXPECT_RESULT();
  84063. }
  84064. #endif
  84065. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84066. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84067. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  84068. {
  84069. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84070. WOLFSSL_SUCCESS);
  84071. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84072. }
  84073. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  84074. {
  84075. char testMsg[] = "Message after SCR";
  84076. char msgBuf[sizeof(testMsg)];
  84077. if (wolfSSL_is_server(ssl)) {
  84078. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84079. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84080. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84081. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84082. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84083. sizeof(testMsg));
  84084. }
  84085. else {
  84086. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84087. sizeof(testMsg));
  84088. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84089. }
  84090. }
  84091. static int test_dtls_downgrade_scr(void)
  84092. {
  84093. EXPECT_DECLS;
  84094. callback_functions func_cb_client;
  84095. callback_functions func_cb_server;
  84096. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84097. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84098. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84099. func_cb_client.method = wolfDTLS_client_method;
  84100. func_cb_server.method = wolfDTLSv1_2_server_method;
  84101. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  84102. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  84103. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  84104. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84105. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84106. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84107. return EXPECT_RESULT();
  84108. }
  84109. #else
  84110. static int test_dtls_downgrade_scr(void)
  84111. {
  84112. EXPECT_DECLS;
  84113. return EXPECT_RESULT();
  84114. }
  84115. #endif
  84116. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84117. && !defined(WOLFSSL_NO_TLS12)
  84118. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  84119. char *data, int sz, void *ctx)
  84120. {
  84121. static int call_counter = 0;
  84122. call_counter++;
  84123. (void)ssl;
  84124. (void)data;
  84125. (void)sz;
  84126. (void)ctx;
  84127. switch (call_counter) {
  84128. case 1:
  84129. case 2:
  84130. return WOLFSSL_CBIO_ERR_TIMEOUT;
  84131. case 3:
  84132. return WOLFSSL_CBIO_ERR_WANT_READ;
  84133. default:
  84134. AssertIntLE(call_counter, 3);
  84135. return -1;
  84136. }
  84137. }
  84138. #endif
  84139. /* Make sure we don't send acks before getting a server hello */
  84140. static int test_dtls_client_hello_timeout_downgrade(void)
  84141. {
  84142. EXPECT_DECLS;
  84143. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84144. && !defined(WOLFSSL_NO_TLS12)
  84145. WOLFSSL_CTX *ctx_c = NULL;
  84146. WOLFSSL_CTX *ctx_s = NULL;
  84147. WOLFSSL *ssl_c = NULL;
  84148. WOLFSSL *ssl_s = NULL;
  84149. struct test_memio_ctx test_ctx;
  84150. DtlsRecordLayerHeader* dtlsRH;
  84151. size_t len;
  84152. byte sequence_number[8];
  84153. int i;
  84154. for (i = 0; i < 2; i++) {
  84155. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84156. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84157. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  84158. if (i == 0) {
  84159. /* First time simulate timeout in IO layer */
  84160. /* CH1 */
  84161. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84162. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84163. /* HVR */
  84164. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84165. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84166. /* CH2 */
  84167. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84168. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84169. /* SH flight */
  84170. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84171. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84172. /* Drop the SH */
  84173. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  84174. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84175. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84176. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84177. (sizeof(DtlsRecordLayerHeader) + len));
  84178. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84179. /* Read the remainder of the flight */
  84180. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84181. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84182. wolfSSL_SSLSetIORecv(ssl_c,
  84183. test_dtls_client_hello_timeout_downgrade_read_cb);
  84184. /* CH3 */
  84185. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84186. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84187. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  84188. }
  84189. else {
  84190. /* Second time call wolfSSL_dtls_got_timeout */
  84191. /* CH1 */
  84192. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84193. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84194. /* HVR */
  84195. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84196. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84197. /* CH2 */
  84198. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84199. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84200. /* SH flight */
  84201. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84202. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84203. /* Drop the SH */
  84204. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  84205. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84206. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84207. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84208. (sizeof(DtlsRecordLayerHeader) + len));
  84209. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84210. /* Read the remainder of the flight */
  84211. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84212. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84213. /* Quick timeout should be set as we received at least one msg */
  84214. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  84215. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84216. /* Quick timeout should be cleared after a quick timeout */
  84217. /* CH3 */
  84218. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  84219. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84220. }
  84221. /* Parse out to make sure we got exactly one ClientHello message */
  84222. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84223. /* Second ClientHello after HVR */
  84224. sequence_number[7] = 2;
  84225. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84226. ExpectIntEQ(dtlsRH->type, handshake);
  84227. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84228. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84229. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84230. sizeof(sequence_number)), 0);
  84231. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84232. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84233. /* Connection should be able to continue */
  84234. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84235. wolfSSL_free(ssl_c);
  84236. wolfSSL_free(ssl_s);
  84237. wolfSSL_CTX_free(ctx_c);
  84238. wolfSSL_CTX_free(ctx_s);
  84239. ssl_c = NULL;
  84240. ssl_s = NULL;
  84241. ctx_c = NULL;
  84242. ctx_s = NULL;
  84243. if (!EXPECT_SUCCESS())
  84244. break;
  84245. }
  84246. #endif
  84247. return EXPECT_RESULT();
  84248. }
  84249. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84250. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  84251. int sz, void *ctx)
  84252. {
  84253. static int call_counter = 0;
  84254. call_counter++;
  84255. (void)ssl;
  84256. (void)data;
  84257. (void)sz;
  84258. (void)ctx;
  84259. switch (call_counter) {
  84260. case 1:
  84261. return WOLFSSL_CBIO_ERR_TIMEOUT;
  84262. case 2:
  84263. return WOLFSSL_CBIO_ERR_WANT_READ;
  84264. default:
  84265. AssertIntLE(call_counter, 2);
  84266. return -1;
  84267. }
  84268. }
  84269. #endif
  84270. /* Make sure we don't send acks before getting a server hello */
  84271. static int test_dtls_client_hello_timeout(void)
  84272. {
  84273. EXPECT_DECLS;
  84274. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84275. WOLFSSL *ssl_c = NULL;
  84276. WOLFSSL_CTX *ctx_c = NULL;
  84277. struct test_memio_ctx test_ctx;
  84278. DtlsRecordLayerHeader* dtlsRH;
  84279. size_t idx;
  84280. size_t len;
  84281. byte sequence_number[8];
  84282. int i;
  84283. for (i = 0; i < 2; i++) {
  84284. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84285. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84286. wolfDTLSv1_3_client_method, NULL), 0);
  84287. if (i == 0) {
  84288. /* First time simulate timeout in IO layer */
  84289. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  84290. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84291. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84292. }
  84293. else {
  84294. /* Second time call wolfSSL_dtls_got_timeout */
  84295. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84296. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84297. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84298. }
  84299. /* Parse out to make sure we got exactly two ClientHello messages */
  84300. idx = 0;
  84301. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84302. /* First ClientHello */
  84303. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84304. ExpectIntEQ(dtlsRH->type, handshake);
  84305. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84306. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84307. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84308. sizeof(sequence_number)), 0);
  84309. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84310. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84311. idx += sizeof(DtlsRecordLayerHeader) + len;
  84312. /* Second ClientHello */
  84313. sequence_number[7] = 1;
  84314. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84315. ExpectIntEQ(dtlsRH->type, handshake);
  84316. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84317. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84318. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84319. sizeof(sequence_number)), 0);
  84320. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84321. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84322. wolfSSL_free(ssl_c);
  84323. wolfSSL_CTX_free(ctx_c);
  84324. ssl_c = NULL;
  84325. ctx_c = NULL;
  84326. if (!EXPECT_SUCCESS())
  84327. break;
  84328. }
  84329. #endif
  84330. return EXPECT_RESULT();
  84331. }
  84332. /* DTLS test when dropping the changed cipher spec message */
  84333. static int test_dtls_dropped_ccs(void)
  84334. {
  84335. EXPECT_DECLS;
  84336. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84337. && !defined(WOLFSSL_NO_TLS12)
  84338. WOLFSSL_CTX *ctx_c = NULL;
  84339. WOLFSSL_CTX *ctx_s = NULL;
  84340. WOLFSSL *ssl_c = NULL;
  84341. WOLFSSL *ssl_s = NULL;
  84342. struct test_memio_ctx test_ctx;
  84343. DtlsRecordLayerHeader* dtlsRH;
  84344. size_t len;
  84345. byte data[1];
  84346. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84347. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84348. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84349. /* CH1 */
  84350. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84351. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84352. /* HVR */
  84353. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84354. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84355. /* CH2 */
  84356. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84357. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84358. /* Server first flight */
  84359. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84360. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84361. /* Client flight */
  84362. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84363. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84364. /* Server ccs + finished */
  84365. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  84366. /* Drop the ccs */
  84367. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84368. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84369. ExpectIntEQ(len, 1);
  84370. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  84371. if (EXPECT_SUCCESS()) {
  84372. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84373. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84374. (sizeof(DtlsRecordLayerHeader) + len));
  84375. }
  84376. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84377. /* Client rtx flight */
  84378. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84379. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84380. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84381. /* Server ccs + finished rtx */
  84382. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  84383. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84384. /* Client processes finished */
  84385. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  84386. wolfSSL_free(ssl_c);
  84387. wolfSSL_free(ssl_s);
  84388. wolfSSL_CTX_free(ctx_c);
  84389. wolfSSL_CTX_free(ctx_s);
  84390. #endif
  84391. return EXPECT_RESULT();
  84392. }
  84393. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84394. && !defined(WOLFSSL_NO_TLS12)
  84395. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  84396. byte seq_num)
  84397. {
  84398. EXPECT_DECLS;
  84399. DtlsRecordLayerHeader* dtlsRH;
  84400. byte sequence_number[8];
  84401. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84402. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  84403. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  84404. ExpectIntEQ(dtlsRH->type, handshake);
  84405. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84406. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84407. sequence_number[7] = seq_num;
  84408. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84409. sizeof(sequence_number)), 0);
  84410. return EXPECT_RESULT();
  84411. }
  84412. #endif
  84413. /*
  84414. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  84415. * and after a HelloRetryRequest. This is testing the server side as it is
  84416. * operating statelessly and should copy the sequence number of the ClientHello.
  84417. */
  84418. static int test_dtls_seq_num_downgrade(void)
  84419. {
  84420. EXPECT_DECLS;
  84421. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84422. && !defined(WOLFSSL_NO_TLS12)
  84423. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84424. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84425. struct test_memio_ctx test_ctx;
  84426. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84427. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84428. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  84429. /* CH1 */
  84430. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84431. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84432. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84433. test_ctx.s_len, 0), TEST_SUCCESS);
  84434. /* HVR */
  84435. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84436. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84437. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84438. test_ctx.c_len, 0), TEST_SUCCESS);
  84439. /* CH2 */
  84440. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84441. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84442. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84443. test_ctx.s_len, 1), TEST_SUCCESS);
  84444. /* Server first flight */
  84445. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84446. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84447. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84448. test_ctx.c_len, 1), TEST_SUCCESS);
  84449. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84450. wolfSSL_free(ssl_c);
  84451. wolfSSL_CTX_free(ctx_c);
  84452. wolfSSL_free(ssl_s);
  84453. wolfSSL_CTX_free(ctx_s);
  84454. #endif
  84455. return EXPECT_RESULT();
  84456. }
  84457. /**
  84458. * Make sure we don't send RSA Signature Hash Algorithms in the
  84459. * CertificateRequest when we don't have any such ciphers set.
  84460. * @return EXPECT_RESULT()
  84461. */
  84462. static int test_certreq_sighash_algos(void)
  84463. {
  84464. EXPECT_DECLS;
  84465. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84466. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  84467. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  84468. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  84469. WOLFSSL_CTX *ctx_c = NULL;
  84470. WOLFSSL_CTX *ctx_s = NULL;
  84471. WOLFSSL *ssl_c = NULL;
  84472. WOLFSSL *ssl_s = NULL;
  84473. struct test_memio_ctx test_ctx;
  84474. int idx = 0;
  84475. int maxIdx = 0;
  84476. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84477. test_ctx.c_ciphers = test_ctx.s_ciphers =
  84478. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  84479. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84480. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  84481. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  84482. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  84483. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  84484. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  84485. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84486. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  84487. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84488. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84489. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84490. WOLFSSL_ERROR_WANT_READ);
  84491. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84492. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84493. WOLFSSL_ERROR_WANT_READ);
  84494. /* Find the CertificateRequest message */
  84495. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  84496. word16 len;
  84497. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  84498. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  84499. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  84500. ato16(test_ctx.c_buff + idx, &len);
  84501. idx += OPAQUE16_LEN;
  84502. if (test_ctx.c_buff[idx] == certificate_request) {
  84503. idx++;
  84504. /* length */
  84505. idx += OPAQUE24_LEN;
  84506. /* cert types */
  84507. idx += 1 + test_ctx.c_buff[idx];
  84508. /* Sig algos */
  84509. ato16(test_ctx.c_buff + idx, &len);
  84510. idx += OPAQUE16_LEN;
  84511. maxIdx = idx + (int)len;
  84512. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  84513. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  84514. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  84515. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  84516. else
  84517. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  84518. }
  84519. break;
  84520. }
  84521. else {
  84522. idx += (int)len;
  84523. }
  84524. }
  84525. ExpectIntLT(idx, test_ctx.c_len);
  84526. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84527. wolfSSL_free(ssl_c);
  84528. wolfSSL_free(ssl_s);
  84529. wolfSSL_CTX_free(ctx_c);
  84530. wolfSSL_CTX_free(ctx_s);
  84531. #endif
  84532. return EXPECT_RESULT();
  84533. }
  84534. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84535. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84536. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  84537. {
  84538. EXPECT_DECLS;
  84539. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84540. myVerifyAction = VERIFY_USE_PREVERFIY;
  84541. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84542. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84543. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84544. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84545. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84546. WOLFSSL_SUCCESS);
  84547. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84548. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84549. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84550. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84551. "./certs/crl/ca-int.pem",
  84552. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84553. return EXPECT_RESULT();
  84554. }
  84555. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  84556. {
  84557. EXPECT_DECLS;
  84558. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84559. myVerifyAction = VERIFY_USE_PREVERFIY;
  84560. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84561. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84562. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84563. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84564. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84565. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84566. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84567. WOLFSSL_SUCCESS);
  84568. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84569. "./certs/crl/ca-int2.pem",
  84570. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84571. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84572. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84573. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84574. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84575. "./certs/crl/ca-int.pem",
  84576. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84577. return EXPECT_RESULT();
  84578. }
  84579. static int test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb(int ret,
  84580. WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm, void* ctx)
  84581. {
  84582. (void)crl;
  84583. (void)cm;
  84584. (void)ctx;
  84585. if (ret == WC_NO_ERR_TRACE(CRL_MISSING))
  84586. return 1;
  84587. return 0;
  84588. }
  84589. /* Here we are allowing missing CRL's but want to error out when its revoked */
  84590. static int test_revoked_loaded_int_cert_ctx_ready3(WOLFSSL_CTX* ctx)
  84591. {
  84592. EXPECT_DECLS;
  84593. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84594. myVerifyAction = VERIFY_USE_PREVERFIY;
  84595. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84596. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84597. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84598. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84599. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84600. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84601. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84602. WOLFSSL_SUCCESS);
  84603. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84604. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84605. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84606. ExpectIntEQ(wolfSSL_CTX_SetCRL_ErrorCb(ctx,
  84607. test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb, NULL),
  84608. WOLFSSL_SUCCESS);
  84609. return EXPECT_RESULT();
  84610. }
  84611. #endif
  84612. static int test_revoked_loaded_int_cert(void)
  84613. {
  84614. EXPECT_DECLS;
  84615. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84616. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84617. test_ssl_cbf client_cbf;
  84618. test_ssl_cbf server_cbf;
  84619. struct {
  84620. const char* certPemFile;
  84621. const char* keyPemFile;
  84622. ctx_cb client_ctx_ready;
  84623. } test_params[] = {
  84624. {"./certs/intermediate/ca-int2-cert.pem",
  84625. "./certs/intermediate/ca-int2-key.pem",
  84626. test_revoked_loaded_int_cert_ctx_ready1},
  84627. {"./certs/intermediate/server-chain.pem",
  84628. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84629. {"./certs/intermediate/server-chain-short.pem",
  84630. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84631. {"./certs/intermediate/server-chain-short.pem",
  84632. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready3},
  84633. };
  84634. size_t i;
  84635. printf("\n");
  84636. for (i = 0; i < XELEM_CNT(test_params); i++) {
  84637. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84638. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84639. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  84640. server_cbf.certPemFile = test_params[i].certPemFile;
  84641. server_cbf.keyPemFile = test_params[i].keyPemFile;
  84642. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  84643. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84644. &server_cbf, NULL), -1001);
  84645. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  84646. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  84647. if (!EXPECT_SUCCESS())
  84648. break;
  84649. printf("\t%s passed\n", test_params[i].certPemFile);
  84650. }
  84651. #endif
  84652. return EXPECT_RESULT();
  84653. }
  84654. static int test_dtls13_frag_ch_pq(void)
  84655. {
  84656. EXPECT_DECLS;
  84657. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84658. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  84659. WOLFSSL_CTX *ctx_c = NULL;
  84660. WOLFSSL_CTX *ctx_s = NULL;
  84661. WOLFSSL *ssl_c = NULL;
  84662. WOLFSSL *ssl_s = NULL;
  84663. struct test_memio_ctx test_ctx;
  84664. const char *test_str = "test";
  84665. int test_str_size;
  84666. byte buf[255];
  84667. int group = WOLFSSL_KYBER_LEVEL5;
  84668. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84669. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84670. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84671. /* Add in a large post-quantum key share to make the CH long. */
  84672. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  84673. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  84674. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84675. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84676. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  84677. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  84678. test_str_size = XSTRLEN("test") + 1;
  84679. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84680. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84681. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84682. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84683. wolfSSL_free(ssl_c);
  84684. wolfSSL_free(ssl_s);
  84685. wolfSSL_CTX_free(ctx_c);
  84686. wolfSSL_CTX_free(ctx_s);
  84687. #endif
  84688. return EXPECT_RESULT();
  84689. }
  84690. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84691. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84692. static int test_dtls_frag_ch_count_records(byte* b, int len)
  84693. {
  84694. DtlsRecordLayerHeader* dtlsRH;
  84695. int records = 0;
  84696. size_t recordLen;
  84697. while (len > 0) {
  84698. records++;
  84699. dtlsRH = (DtlsRecordLayerHeader*)b;
  84700. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  84701. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  84702. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  84703. }
  84704. return records;
  84705. }
  84706. #endif
  84707. static int test_dtls_frag_ch(void)
  84708. {
  84709. EXPECT_DECLS;
  84710. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84711. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84712. WOLFSSL_CTX *ctx_c = NULL;
  84713. WOLFSSL_CTX *ctx_s = NULL;
  84714. WOLFSSL *ssl_c = NULL;
  84715. WOLFSSL *ssl_s = NULL;
  84716. struct test_memio_ctx test_ctx;
  84717. static unsigned int DUMMY_MTU = 256;
  84718. unsigned char four_frag_CH[] = {
  84719. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84720. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84721. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  84722. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  84723. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  84724. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84725. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84726. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84727. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84728. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  84729. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  84730. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  84731. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  84732. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  84733. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  84734. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  84735. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  84736. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  84737. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  84738. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84739. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  84740. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  84741. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  84742. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  84743. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  84744. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  84745. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  84746. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  84747. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  84748. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  84749. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  84750. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  84751. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  84752. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  84753. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  84754. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  84755. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  84756. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  84757. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  84758. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  84759. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  84760. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  84761. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  84762. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  84763. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  84764. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  84765. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  84766. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  84767. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  84768. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  84769. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  84770. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  84771. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  84772. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  84773. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  84774. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  84775. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  84776. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  84777. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  84778. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  84779. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  84780. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  84781. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  84782. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  84783. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  84784. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  84785. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  84786. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  84787. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  84788. 0xa5, 0xcb, 0x68, 0xf3
  84789. };
  84790. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84791. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84792. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84793. /* Fragment msgs */
  84794. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  84795. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  84796. /* Add in some key shares to make the CH long */
  84797. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  84798. WOLFSSL_SUCCESS);
  84799. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  84800. WOLFSSL_SUCCESS);
  84801. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  84802. WOLFSSL_SUCCESS);
  84803. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  84804. WOLFSSL_SUCCESS);
  84805. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84806. /* Reject fragmented first CH */
  84807. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  84808. sizeof(four_frag_CH)), 4);
  84809. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  84810. test_ctx.s_len = sizeof(four_frag_CH);
  84811. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  84812. int s_len = test_ctx.s_len;
  84813. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84814. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84815. /* Fail if we didn't advance the buffer to avoid infinite loops */
  84816. ExpectIntLT(test_ctx.s_len, s_len);
  84817. }
  84818. /* Expect all fragments read */
  84819. ExpectIntEQ(test_ctx.s_len, 0);
  84820. /* Expect quietly dropping fragmented first CH */
  84821. ExpectIntEQ(test_ctx.c_len, 0);
  84822. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  84823. /* Disable ECH as it pushes it over our MTU */
  84824. wolfSSL_SetEchEnable(ssl_c, 0);
  84825. #endif
  84826. /* Limit options to make the CH a fixed length */
  84827. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  84828. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  84829. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  84830. #ifdef OPENSSL_EXTRA
  84831. ":DHE-RSA-AES256-GCM-SHA384"
  84832. #endif
  84833. ));
  84834. /* CH1 */
  84835. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84836. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84837. /* Count records. Expect 1 unfragmented CH */
  84838. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84839. test_ctx.s_len), 1);
  84840. /* HRR */
  84841. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84842. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84843. /* CH2 */
  84844. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84845. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84846. /* Count records. Expect fragmented CH */
  84847. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84848. test_ctx.s_len), 1);
  84849. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84850. wolfSSL_free(ssl_c);
  84851. wolfSSL_free(ssl_s);
  84852. wolfSSL_CTX_free(ctx_c);
  84853. wolfSSL_CTX_free(ctx_s);
  84854. ssl_c = ssl_s = NULL;
  84855. ctx_c = ctx_s = NULL;
  84856. #endif
  84857. return EXPECT_RESULT();
  84858. }
  84859. static int test_dtls_empty_keyshare_with_cookie(void)
  84860. {
  84861. EXPECT_DECLS;
  84862. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84863. WOLFSSL_CTX *ctx_s = NULL;
  84864. WOLFSSL *ssl_s = NULL;
  84865. struct test_memio_ctx test_ctx;
  84866. unsigned char ch_empty_keyshare_with_cookie[] = {
  84867. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  84868. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  84869. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  84870. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  84871. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  84872. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84873. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84874. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84875. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84876. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  84877. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  84878. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  84879. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  84880. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  84881. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  84882. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  84883. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  84884. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  84885. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  84886. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  84887. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  84888. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  84889. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  84890. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  84891. };
  84892. DtlsRecordLayerHeader* dtlsRH;
  84893. byte sequence_number[8];
  84894. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84895. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84896. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  84897. sizeof(ch_empty_keyshare_with_cookie));
  84898. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  84899. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84900. NULL, wolfDTLSv1_3_server_method), 0);
  84901. /* CH1 */
  84902. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84903. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84904. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  84905. ExpectIntEQ(test_ctx.c_len, 15);
  84906. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84907. ExpectIntEQ(dtlsRH->type, alert);
  84908. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84909. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84910. sequence_number[7] = 1;
  84911. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84912. sizeof(sequence_number)), 0);
  84913. ExpectIntEQ(dtlsRH->length[0], 0);
  84914. ExpectIntEQ(dtlsRH->length[1], 2);
  84915. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  84916. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  84917. wolfSSL_free(ssl_s);
  84918. wolfSSL_CTX_free(ctx_s);
  84919. #endif
  84920. return EXPECT_RESULT();
  84921. }
  84922. static int test_dtls_old_seq_number(void)
  84923. {
  84924. EXPECT_DECLS;
  84925. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  84926. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84927. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84928. struct test_memio_ctx test_ctx;
  84929. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84930. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84931. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84932. /* CH1 */
  84933. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84934. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84935. /* HVR */
  84936. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84937. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84938. /* CH2 */
  84939. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84940. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84941. /* Server first flight */
  84942. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84943. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84944. /* Client second flight */
  84945. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84946. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84947. /* Modify the sequence number */
  84948. {
  84949. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84950. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  84951. }
  84952. /* Server second flight */
  84953. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84954. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84955. /* Server should not do anything as a pkt was dropped */
  84956. ExpectIntEQ(test_ctx.c_len, 0);
  84957. ExpectIntEQ(test_ctx.s_len, 0);
  84958. /* Trigger rtx */
  84959. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84960. /* Complete connection */
  84961. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84962. wolfSSL_free(ssl_c);
  84963. wolfSSL_CTX_free(ctx_c);
  84964. wolfSSL_free(ssl_s);
  84965. wolfSSL_CTX_free(ctx_s);
  84966. #endif
  84967. return EXPECT_RESULT();
  84968. }
  84969. static int test_dtls13_basic_connection_id(void)
  84970. {
  84971. EXPECT_DECLS;
  84972. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84973. && defined(WOLFSSL_DTLS_CID)
  84974. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  84975. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  84976. unsigned char readBuf[30];
  84977. const char* params[] = {
  84978. #ifndef NO_SHA256
  84979. #ifdef WOLFSSL_AES_128
  84980. #ifdef HAVE_AESGCM
  84981. "TLS13-AES128-GCM-SHA256",
  84982. #endif
  84983. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  84984. "TLS13-CHACHA20-POLY1305-SHA256",
  84985. #endif
  84986. #ifdef HAVE_AESCCM
  84987. "TLS13-AES128-CCM-8-SHA256",
  84988. "TLS13-AES128-CCM-SHA256",
  84989. #endif
  84990. #endif
  84991. #ifdef HAVE_NULL_CIPHER
  84992. "TLS13-SHA256-SHA256",
  84993. #endif
  84994. #endif
  84995. };
  84996. size_t i;
  84997. /* We check if the side included the CID in their output */
  84998. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  84999. client_cid, sizeof(client_cid))
  85000. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  85001. server_cid, sizeof(server_cid))
  85002. printf("\n");
  85003. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  85004. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85005. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85006. struct test_memio_ctx test_ctx;
  85007. printf("Testing %s ... ", params[i]);
  85008. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85009. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85010. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85011. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS);
  85012. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS);
  85013. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  85014. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)),
  85015. 1);
  85016. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  85017. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)),
  85018. 1);
  85019. /* CH1 */
  85020. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85021. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85022. ExpectNull(CLIENT_CID());
  85023. /* HRR */
  85024. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85025. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85026. ExpectNull(SERVER_CID());
  85027. /* CH2 */
  85028. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85029. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85030. ExpectNull(CLIENT_CID());
  85031. /* Server first flight */
  85032. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85033. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85034. ExpectNotNull(SERVER_CID());
  85035. /* Client second flight */
  85036. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85037. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85038. ExpectNotNull(CLIENT_CID());
  85039. /* Server process flight */
  85040. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  85041. /* Client process flight */
  85042. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  85043. /* Write some data */
  85044. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], XSTRLEN(params[i])),
  85045. XSTRLEN(params[i]));
  85046. ExpectNotNull(CLIENT_CID());
  85047. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], XSTRLEN(params[i])),
  85048. XSTRLEN(params[i]));
  85049. ExpectNotNull(SERVER_CID());
  85050. /* Read the data */
  85051. XMEMSET(readBuf, 0, sizeof(readBuf));
  85052. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  85053. XSTRLEN(params[i]));
  85054. ExpectStrEQ(readBuf, params[i]);
  85055. XMEMSET(readBuf, 0, sizeof(readBuf));
  85056. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  85057. XSTRLEN(params[i]));
  85058. ExpectStrEQ(readBuf, params[i]);
  85059. /* Write short data */
  85060. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  85061. ExpectNotNull(CLIENT_CID());
  85062. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  85063. ExpectNotNull(SERVER_CID());
  85064. /* Read the short data */
  85065. XMEMSET(readBuf, 0, sizeof(readBuf));
  85066. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  85067. ExpectIntEQ(readBuf[0], params[i][0]);
  85068. XMEMSET(readBuf, 0, sizeof(readBuf));
  85069. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  85070. ExpectIntEQ(readBuf[0], params[i][0]);
  85071. /* Close connection */
  85072. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  85073. ExpectNotNull(CLIENT_CID());
  85074. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85075. ExpectNotNull(SERVER_CID());
  85076. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  85077. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  85078. if (EXPECT_SUCCESS())
  85079. printf("ok\n");
  85080. else
  85081. printf("failed\n");
  85082. wolfSSL_free(ssl_c);
  85083. wolfSSL_CTX_free(ctx_c);
  85084. wolfSSL_free(ssl_s);
  85085. wolfSSL_CTX_free(ctx_s);
  85086. }
  85087. #undef CLIENT_CID
  85088. #undef SERVER_CID
  85089. #endif
  85090. return EXPECT_RESULT();
  85091. }
  85092. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  85093. defined(HAVE_LIBOQS)
  85094. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  85095. {
  85096. int group = WOLFSSL_KYBER_LEVEL5;
  85097. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  85098. }
  85099. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  85100. {
  85101. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  85102. }
  85103. #endif
  85104. static int test_tls13_pq_groups(void)
  85105. {
  85106. EXPECT_DECLS;
  85107. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  85108. defined(HAVE_LIBOQS)
  85109. callback_functions func_cb_client;
  85110. callback_functions func_cb_server;
  85111. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  85112. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  85113. func_cb_client.method = wolfTLSv1_3_client_method;
  85114. func_cb_server.method = wolfTLSv1_3_server_method;
  85115. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  85116. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  85117. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  85118. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  85119. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  85120. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  85121. #endif
  85122. return EXPECT_RESULT();
  85123. }
  85124. static int test_tls13_early_data(void)
  85125. {
  85126. EXPECT_DECLS;
  85127. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85128. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  85129. int written = 0;
  85130. int read = 0;
  85131. size_t i;
  85132. int splitEarlyData;
  85133. char msg[] = "This is early data";
  85134. char msg2[] = "This is client data";
  85135. char msg3[] = "This is server data";
  85136. char msg4[] = "This is server immediate data";
  85137. char msgBuf[50];
  85138. struct {
  85139. method_provider client_meth;
  85140. method_provider server_meth;
  85141. const char* tls_version;
  85142. int isUdp;
  85143. } params[] = {
  85144. #ifdef WOLFSSL_TLS13
  85145. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  85146. "TLS 1.3", 0 },
  85147. #endif
  85148. #ifdef WOLFSSL_DTLS13
  85149. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  85150. "DTLS 1.3", 1 },
  85151. #endif
  85152. };
  85153. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85154. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  85155. struct test_memio_ctx test_ctx;
  85156. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85157. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85158. WOLFSSL_SESSION *sess = NULL;
  85159. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85160. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  85161. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  85162. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  85163. /* Get a ticket so that we can do 0-RTT on the next connection */
  85164. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85165. /* Make sure we read the ticket */
  85166. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  85167. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85168. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  85169. wolfSSL_free(ssl_c);
  85170. ssl_c = NULL;
  85171. wolfSSL_free(ssl_s);
  85172. ssl_s = NULL;
  85173. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85174. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85175. params[i].client_meth, params[i].server_meth), 0);
  85176. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  85177. #ifdef WOLFSSL_DTLS13
  85178. if (params[i].isUdp) {
  85179. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  85180. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  85181. #else
  85182. /* Let's test this but we generally don't recommend turning off the
  85183. * cookie exchange */
  85184. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  85185. #endif
  85186. }
  85187. #endif
  85188. /* Test 0-RTT data */
  85189. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  85190. &written), sizeof(msg));
  85191. ExpectIntEQ(written, sizeof(msg));
  85192. if (splitEarlyData) {
  85193. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  85194. &written), sizeof(msg));
  85195. ExpectIntEQ(written, sizeof(msg));
  85196. }
  85197. /* Read first 0-RTT data (if split otherwise entire data) */
  85198. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85199. &read), sizeof(msg));
  85200. ExpectIntEQ(read, sizeof(msg));
  85201. ExpectStrEQ(msg, msgBuf);
  85202. /* Test 0.5-RTT data */
  85203. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  85204. if (splitEarlyData) {
  85205. /* Read second 0-RTT data */
  85206. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85207. &read), sizeof(msg));
  85208. ExpectIntEQ(read, sizeof(msg));
  85209. ExpectStrEQ(msg, msgBuf);
  85210. }
  85211. if (params[i].isUdp) {
  85212. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85213. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  85214. /* Read server 0.5-RTT data */
  85215. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  85216. ExpectStrEQ(msg4, msgBuf);
  85217. /* Complete handshake */
  85218. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85219. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85220. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  85221. * a user would loop until it is true but here we control both sides so we
  85222. * just assert the expected value. wolfSSL_read_early_data does not provide
  85223. * handshake status to us with non-blocking IO and we can't use
  85224. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  85225. * parsing logic. */
  85226. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  85227. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85228. &read), 0);
  85229. ExpectIntEQ(read, 0);
  85230. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  85231. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  85232. }
  85233. else {
  85234. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  85235. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  85236. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85237. &read), 0);
  85238. ExpectIntEQ(read, 0);
  85239. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  85240. /* Read server 0.5-RTT data */
  85241. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  85242. ExpectStrEQ(msg4, msgBuf);
  85243. }
  85244. /* Test bi-directional write */
  85245. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  85246. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  85247. ExpectStrEQ(msg2, msgBuf);
  85248. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  85249. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  85250. ExpectStrEQ(msg3, msgBuf);
  85251. ExpectTrue(wolfSSL_session_reused(ssl_c));
  85252. ExpectTrue(wolfSSL_session_reused(ssl_s));
  85253. wolfSSL_SESSION_free(sess);
  85254. wolfSSL_free(ssl_c);
  85255. wolfSSL_free(ssl_s);
  85256. wolfSSL_CTX_free(ctx_c);
  85257. wolfSSL_CTX_free(ctx_s);
  85258. }
  85259. }
  85260. #endif
  85261. return EXPECT_RESULT();
  85262. }
  85263. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  85264. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  85265. {
  85266. EXPECT_DECLS;
  85267. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85268. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  85269. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  85270. return EXPECT_RESULT();
  85271. }
  85272. #endif
  85273. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  85274. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  85275. {
  85276. EXPECT_DECLS;
  85277. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85278. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  85279. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  85280. return EXPECT_RESULT();
  85281. }
  85282. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  85283. {
  85284. EXPECT_DECLS;
  85285. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85286. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  85287. 0), 1);
  85288. return EXPECT_RESULT();
  85289. }
  85290. #endif
  85291. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  85292. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  85293. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  85294. {
  85295. EXPECT_DECLS;
  85296. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85297. return EXPECT_RESULT();
  85298. }
  85299. #endif
  85300. static int test_self_signed_stapling(void)
  85301. {
  85302. EXPECT_DECLS;
  85303. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  85304. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  85305. test_ssl_cbf client_cbf;
  85306. test_ssl_cbf server_cbf;
  85307. size_t i;
  85308. struct {
  85309. method_provider client_meth;
  85310. method_provider server_meth;
  85311. ctx_cb client_ctx;
  85312. const char* tls_version;
  85313. } params[] = {
  85314. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  85315. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  85316. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  85317. #endif
  85318. #ifndef WOLFSSL_NO_TLS12
  85319. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  85320. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85321. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  85322. #endif
  85323. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  85324. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85325. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  85326. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85327. test_self_signed_stapling_client_v2_multi_ctx_ready,
  85328. "TLSv1_2 v2 multi" },
  85329. #endif
  85330. #endif
  85331. };
  85332. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85333. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85334. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85335. printf("\nTesting self-signed cert with status request: %s\n",
  85336. params[i].tls_version);
  85337. client_cbf.method = params[i].client_meth;
  85338. client_cbf.ctx_ready = params[i].client_ctx;
  85339. server_cbf.method = params[i].server_meth;
  85340. server_cbf.certPemFile = "certs/ca-cert.pem";
  85341. server_cbf.keyPemFile = "certs/ca-key.pem";
  85342. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  85343. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85344. &server_cbf, NULL), TEST_SUCCESS);
  85345. }
  85346. #endif
  85347. return EXPECT_RESULT();
  85348. }
  85349. static int test_tls_multi_handshakes_one_record(void)
  85350. {
  85351. EXPECT_DECLS;
  85352. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  85353. struct test_memio_ctx test_ctx;
  85354. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85355. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85356. RecordLayerHeader* rh = NULL;
  85357. byte *len ;
  85358. int newRecIdx = RECORD_HEADER_SZ;
  85359. int idx = 0;
  85360. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85361. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85362. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  85363. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85364. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85365. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  85366. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85367. /* Combine server handshake msgs into one record */
  85368. while (idx < test_ctx.c_len) {
  85369. word16 recLen;
  85370. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  85371. len = &rh->length[0];
  85372. ato16((const byte*)len, &recLen);
  85373. idx += RECORD_HEADER_SZ;
  85374. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  85375. (size_t)recLen);
  85376. newRecIdx += recLen;
  85377. idx += recLen;
  85378. }
  85379. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  85380. len = &rh->length[0];
  85381. c16toa(newRecIdx - RECORD_HEADER_SZ, len);
  85382. test_ctx.c_len = newRecIdx;
  85383. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85384. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85385. wolfSSL_free(ssl_c);
  85386. wolfSSL_free(ssl_s);
  85387. wolfSSL_CTX_free(ctx_c);
  85388. wolfSSL_CTX_free(ctx_s);
  85389. #endif
  85390. return EXPECT_RESULT();
  85391. }
  85392. static int test_write_dup(void)
  85393. {
  85394. EXPECT_DECLS;
  85395. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  85396. size_t i, j;
  85397. char hiWorld[] = "dup message";
  85398. char readData[sizeof(hiWorld) + 5];
  85399. struct {
  85400. method_provider client_meth;
  85401. method_provider server_meth;
  85402. const char* version_name;
  85403. int version;
  85404. } methods[] = {
  85405. #ifndef WOLFSSL_NO_TLS12
  85406. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  85407. #endif
  85408. #ifdef WOLFSSL_TLS13
  85409. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  85410. #endif
  85411. };
  85412. struct {
  85413. const char* cipher;
  85414. int version;
  85415. } ciphers[] = {
  85416. /* For simplicity the macros are copied from internal.h */
  85417. /* TLS 1.2 */
  85418. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  85419. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  85420. #ifndef NO_RSA
  85421. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  85422. #endif
  85423. #endif
  85424. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  85425. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  85426. #endif
  85427. #endif
  85428. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  85429. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  85430. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85431. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85432. #endif
  85433. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85434. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85435. #endif
  85436. #endif
  85437. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  85438. && !defined(NO_TLS) && !defined(NO_AES)
  85439. #ifdef HAVE_AESGCM
  85440. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85441. #ifndef NO_RSA
  85442. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85443. #endif
  85444. #endif
  85445. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85446. #ifndef NO_RSA
  85447. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85448. #endif
  85449. #endif
  85450. #endif
  85451. #endif
  85452. /* TLS 1.3 */
  85453. #ifdef WOLFSSL_TLS13
  85454. #ifdef HAVE_AESGCM
  85455. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85456. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  85457. #endif
  85458. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85459. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  85460. #endif
  85461. #endif
  85462. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85463. #ifndef NO_SHA256
  85464. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  85465. #endif
  85466. #endif
  85467. #ifdef HAVE_AESCCM
  85468. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85469. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  85470. #endif
  85471. #endif
  85472. #endif
  85473. };
  85474. for (i = 0; i < XELEM_CNT(methods); i++) {
  85475. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  85476. struct test_memio_ctx test_ctx;
  85477. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85478. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85479. WOLFSSL *ssl_c2 = NULL;
  85480. if (methods[i].version != ciphers[j].version)
  85481. continue;
  85482. if (i == 0 && j == 0)
  85483. printf("\n");
  85484. printf("Testing %s with %s... ", methods[i].version_name,
  85485. ciphers[j].cipher);
  85486. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85487. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  85488. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85489. methods[i].client_meth, methods[i].server_meth), 0);
  85490. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85491. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  85492. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  85493. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  85494. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  85495. sizeof(hiWorld));
  85496. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  85497. sizeof(hiWorld));
  85498. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  85499. sizeof(hiWorld));
  85500. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  85501. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  85502. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  85503. sizeof(hiWorld));
  85504. if (EXPECT_SUCCESS())
  85505. printf("ok\n");
  85506. else
  85507. printf("failed\n");
  85508. wolfSSL_free(ssl_c);
  85509. wolfSSL_free(ssl_c2);
  85510. wolfSSL_free(ssl_s);
  85511. wolfSSL_CTX_free(ctx_c);
  85512. wolfSSL_CTX_free(ctx_s);
  85513. }
  85514. }
  85515. #endif
  85516. return EXPECT_RESULT();
  85517. }
  85518. static int test_read_write_hs(void)
  85519. {
  85520. EXPECT_DECLS;
  85521. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  85522. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  85523. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  85524. struct test_memio_ctx test_ctx;
  85525. byte test_buffer[16];
  85526. unsigned int test;
  85527. /* test == 0 : client writes, server reads */
  85528. /* test == 1 : server writes, client reads */
  85529. for (test = 0; test < 2; test++) {
  85530. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85531. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85532. wolfTLSv1_2_client_method,
  85533. wolfTLSv1_2_server_method), 0);
  85534. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  85535. /* CH -> */
  85536. if (test == 0) {
  85537. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85538. } else {
  85539. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85540. sizeof(test_buffer)), -1);
  85541. }
  85542. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85543. /* <- SH + SKE + SHD */
  85544. if (test == 0) {
  85545. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85546. sizeof(test_buffer)), -1);
  85547. } else {
  85548. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85549. }
  85550. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85551. /* -> CKE + CLIENT FINISHED */
  85552. if (test == 0) {
  85553. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85554. } else {
  85555. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85556. sizeof(test_buffer)), -1);
  85557. }
  85558. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85559. /* abide clang static analyzer */
  85560. if (ssl_s != NULL) {
  85561. /* disable group message to separate sending of ChangeCipherspec
  85562. * from Finished */
  85563. ssl_s->options.groupMessages = 0;
  85564. }
  85565. /* allow writing of CS, but not FINISHED */
  85566. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  85567. /* <- CS */
  85568. if (test == 0) {
  85569. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85570. sizeof(test_buffer)), -1);
  85571. } else {
  85572. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85573. }
  85574. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  85575. /* move CS message where the client can read it */
  85576. memmove(test_ctx.c_buff,
  85577. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  85578. test_ctx.c_len = 6;
  85579. /* read CS */
  85580. if (test == 0) {
  85581. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85582. } else {
  85583. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85584. sizeof(test_buffer)), -1);
  85585. }
  85586. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85587. ExpectIntEQ(test_ctx.c_len, 0);
  85588. if (test == 0) {
  85589. /* send SERVER FINISHED */
  85590. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85591. sizeof(test_buffer)), -1);
  85592. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  85593. WOLFSSL_ERROR_WANT_READ);
  85594. } else {
  85595. /* send SERVER FINISHED + App Data */
  85596. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  85597. }
  85598. ExpectIntGT(test_ctx.c_len, 0);
  85599. /* Send and receive the data */
  85600. if (test == 0) {
  85601. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  85602. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85603. sizeof(test_buffer)), 5);
  85604. } else {
  85605. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85606. sizeof(test_buffer)), 5);
  85607. }
  85608. ExpectBufEQ(test_buffer, "hello", 5);
  85609. wolfSSL_free(ssl_c);
  85610. wolfSSL_free(ssl_s);
  85611. wolfSSL_CTX_free(ctx_c);
  85612. wolfSSL_CTX_free(ctx_s);
  85613. ssl_c = ssl_s = NULL;
  85614. ctx_c = ctx_s = NULL;
  85615. }
  85616. #endif
  85617. return EXPECT_RESULT();
  85618. }
  85619. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85620. static const char* test_get_signature_nid_siglag;
  85621. static int test_get_signature_nid_sig;
  85622. static int test_get_signature_nid_hash;
  85623. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  85624. {
  85625. EXPECT_DECLS;
  85626. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  85627. if (!wolfSSL_is_server(ssl)) {
  85628. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  85629. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  85630. }
  85631. return EXPECT_RESULT();
  85632. }
  85633. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85634. {
  85635. EXPECT_DECLS;
  85636. int nid = 0;
  85637. (void)ctx;
  85638. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  85639. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85640. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85641. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85642. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85643. }
  85644. else /* No sigalg info on static ciphersuite */
  85645. return TEST_SUCCESS;
  85646. return EXPECT_RESULT();
  85647. }
  85648. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85649. {
  85650. EXPECT_DECLS;
  85651. int nid = 0;
  85652. (void)ctx;
  85653. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85654. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85655. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85656. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85657. return EXPECT_RESULT();
  85658. }
  85659. #endif
  85660. static int test_get_signature_nid(void)
  85661. {
  85662. EXPECT_DECLS;
  85663. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85664. test_ssl_cbf client_cbf;
  85665. test_ssl_cbf server_cbf;
  85666. size_t i;
  85667. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  85668. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  85669. caCertFile }
  85670. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  85671. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  85672. caEccCertFile }
  85673. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  85674. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  85675. caCertFile }
  85676. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  85677. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  85678. caEccCertFile }
  85679. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  85680. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  85681. caEdCertFile }
  85682. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  85683. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  85684. caEd448CertFile }
  85685. struct {
  85686. const char* siglag;
  85687. int sig_nid;
  85688. int hash_nid;
  85689. int tls_ver;
  85690. const char* server_cert;
  85691. const char* server_key;
  85692. const char* client_ca;
  85693. } params[] = {
  85694. #ifndef NO_RSA
  85695. #ifndef NO_SHA256
  85696. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  85697. #ifdef WC_RSA_PSS
  85698. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85699. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85700. #endif
  85701. #endif
  85702. #ifdef WOLFSSL_SHA512
  85703. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  85704. #ifdef WC_RSA_PSS
  85705. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85706. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85707. #endif
  85708. #endif
  85709. #endif
  85710. #ifdef HAVE_ECC
  85711. #ifndef NO_SHA256
  85712. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85713. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85714. #endif
  85715. #endif
  85716. #ifdef HAVE_ED25519
  85717. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  85718. #endif
  85719. #ifdef HAVE_ED448
  85720. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  85721. #endif
  85722. };
  85723. printf("\n");
  85724. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  85725. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85726. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85727. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  85728. params[i].siglag);
  85729. switch (params[i].tls_ver) {
  85730. #ifndef WOLFSSL_NO_TLS12
  85731. case WOLFSSL_TLSV1_2:
  85732. client_cbf.method = wolfTLSv1_2_client_method;
  85733. server_cbf.method = wolfTLSv1_2_server_method;
  85734. break;
  85735. #endif
  85736. #ifdef WOLFSSL_TLS13
  85737. case WOLFSSL_TLSV1_3:
  85738. client_cbf.method = wolfTLSv1_3_client_method;
  85739. server_cbf.method = wolfTLSv1_3_server_method;
  85740. break;
  85741. #endif
  85742. default:
  85743. printf("skipping\n");
  85744. continue;
  85745. }
  85746. test_get_signature_nid_siglag = params[i].siglag;
  85747. test_get_signature_nid_sig = params[i].sig_nid;
  85748. test_get_signature_nid_hash = params[i].hash_nid;
  85749. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85750. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85751. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  85752. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  85753. server_cbf.certPemFile = params[i].server_cert;
  85754. server_cbf.keyPemFile = params[i].server_key;
  85755. client_cbf.caPemFile = params[i].client_ca;
  85756. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85757. &server_cbf, NULL), TEST_SUCCESS);
  85758. if (EXPECT_SUCCESS())
  85759. printf("passed\n");
  85760. }
  85761. #endif
  85762. return EXPECT_RESULT();
  85763. }
  85764. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85765. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  85766. {
  85767. #ifndef NO_MD5
  85768. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  85769. #elif !defined(NO_SHA)
  85770. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  85771. #elif !defined(NO_SHA256)
  85772. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  85773. #else
  85774. #error "We need a digest to hash the Signer object"
  85775. #endif
  85776. byte hashBuf[WC_MAX_DIGEST_SIZE];
  85777. wc_HashAlg hash;
  85778. size_t i;
  85779. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  85780. for (i = 0; i < CA_TABLE_SIZE; i++) {
  85781. Signer* cur;
  85782. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  85783. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  85784. sizeof(*cur)), 0);
  85785. }
  85786. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  85787. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  85788. return MakeWordFromHash(hashBuf);
  85789. }
  85790. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  85791. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  85792. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  85793. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  85794. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  85795. {
  85796. EXPECT_DECLS;
  85797. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  85798. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  85799. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85800. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  85801. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  85802. return EXPECT_RESULT();
  85803. }
  85804. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  85805. {
  85806. EXPECT_DECLS;
  85807. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  85808. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85809. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85810. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85811. return EXPECT_RESULT();
  85812. }
  85813. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85814. {
  85815. EXPECT_DECLS;
  85816. WOLFSSL_CERT_MANAGER* cm;
  85817. (void)ssl;
  85818. /* WARNING: this approach bypasses the reference counter check in
  85819. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  85820. * cause unexpected behaviour when other active connections try accessing
  85821. * the caTable. */
  85822. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  85823. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  85824. WOLFSSL_SUCCESS);
  85825. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85826. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85827. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  85828. return EXPECT_RESULT();
  85829. }
  85830. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  85831. {
  85832. EXPECT_DECLS;
  85833. WOLFSSL_CTX* ctx;
  85834. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  85835. return EXPECT_RESULT();
  85836. }
  85837. #endif
  85838. static int test_tls_cert_store_unchanged(void)
  85839. {
  85840. EXPECT_DECLS;
  85841. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85842. test_ssl_cbf client_cbf;
  85843. test_ssl_cbf server_cbf;
  85844. int i;
  85845. for (i = 0; i < 2; i++) {
  85846. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85847. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85848. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  85849. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  85850. sizeof(test_tls_cert_store_unchanged_before_hashes));
  85851. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  85852. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  85853. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85854. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85855. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85856. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85857. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85858. switch (i) {
  85859. case 0:
  85860. client_cbf.on_ctx_cleanup =
  85861. test_tls_cert_store_unchanged_ctx_cleanup;
  85862. server_cbf.on_ctx_cleanup =
  85863. test_tls_cert_store_unchanged_ctx_cleanup;
  85864. break;
  85865. case 1:
  85866. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85867. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85868. break;
  85869. default:
  85870. Fail(("Should not enter here"), ("Entered here"));
  85871. }
  85872. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  85873. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  85874. server_cbf.caPemFile = caCertFile;
  85875. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85876. &server_cbf, NULL), TEST_SUCCESS);
  85877. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  85878. test_tls_cert_store_unchanged_after_hashes,
  85879. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85880. }
  85881. #endif
  85882. return EXPECT_RESULT();
  85883. }
  85884. static int test_wolfSSL_SendUserCanceled(void)
  85885. {
  85886. EXPECT_DECLS;
  85887. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  85888. size_t i;
  85889. struct {
  85890. method_provider client_meth;
  85891. method_provider server_meth;
  85892. const char* tls_version;
  85893. } params[] = {
  85894. #if defined(WOLFSSL_TLS13)
  85895. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  85896. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  85897. #ifdef WOLFSSL_DTLS13
  85898. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  85899. #endif
  85900. #endif
  85901. #ifndef WOLFSSL_NO_TLS12
  85902. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  85903. #ifdef WOLFSSL_DTLS
  85904. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  85905. #endif
  85906. #endif
  85907. #if !defined(NO_OLD_TLS)
  85908. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  85909. #ifdef WOLFSSL_DTLS
  85910. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  85911. #endif
  85912. #endif
  85913. };
  85914. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85915. WOLFSSL_CTX *ctx_c = NULL;
  85916. WOLFSSL_CTX *ctx_s = NULL;
  85917. WOLFSSL *ssl_c = NULL;
  85918. WOLFSSL *ssl_s = NULL;
  85919. struct test_memio_ctx test_ctx;
  85920. WOLFSSL_ALERT_HISTORY h;
  85921. printf("Testing %s\n", params[i].tls_version);
  85922. XMEMSET(&h, 0, sizeof(h));
  85923. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85924. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85925. params[i].client_meth, params[i].server_meth), 0);
  85926. /* CH1 */
  85927. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85928. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85929. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85930. /* Alert closed connection */
  85931. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85932. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  85933. /* Last alert will be close notify because user_canceled should be
  85934. * followed by a close_notify */
  85935. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  85936. ExpectIntEQ(h.last_rx.code, close_notify);
  85937. ExpectIntEQ(h.last_rx.level, alert_warning);
  85938. wolfSSL_free(ssl_c);
  85939. wolfSSL_free(ssl_s);
  85940. wolfSSL_CTX_free(ctx_c);
  85941. wolfSSL_CTX_free(ctx_s);
  85942. }
  85943. #endif
  85944. return EXPECT_RESULT();
  85945. }
  85946. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85947. defined(HAVE_OCSP) && \
  85948. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  85949. !defined(WOLFSSL_NO_TLS12)
  85950. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  85951. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  85952. {
  85953. (void)ctx;
  85954. (void)url;
  85955. (void)urlSz;
  85956. (void)ocspReqBuf;
  85957. (void)ocspReqSz;
  85958. (void)ocspRespBuf;
  85959. return -1;
  85960. }
  85961. static int test_ocsp_callback_fails(void)
  85962. {
  85963. WOLFSSL_CTX *ctx_c = NULL;
  85964. WOLFSSL_CTX *ctx_s = NULL;
  85965. WOLFSSL *ssl_c = NULL;
  85966. WOLFSSL *ssl_s = NULL;
  85967. struct test_memio_ctx test_ctx;
  85968. EXPECT_DECLS;
  85969. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85970. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85971. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85972. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  85973. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  85974. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  85975. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  85976. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  85977. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  85978. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  85979. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  85980. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  85981. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  85982. wolfSSL_free(ssl_c);
  85983. wolfSSL_free(ssl_s);
  85984. wolfSSL_CTX_free(ctx_c);
  85985. wolfSSL_CTX_free(ctx_s);
  85986. return EXPECT_RESULT();
  85987. }
  85988. #else
  85989. static int test_ocsp_callback_fails(void)
  85990. {
  85991. return TEST_SKIPPED;
  85992. }
  85993. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85994. defined(HAVE_OCSP) && \
  85995. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  85996. /*----------------------------------------------------------------------------*
  85997. | Main
  85998. *----------------------------------------------------------------------------*/
  85999. typedef int (*TEST_FUNC)(void);
  86000. typedef struct {
  86001. const char *name;
  86002. TEST_FUNC func;
  86003. byte run:1;
  86004. byte fail:1;
  86005. } TEST_CASE;
  86006. #define TEST_DECL(func) { #func, func, 0, 0 }
  86007. int testAll = 1;
  86008. TEST_CASE testCases[] = {
  86009. TEST_DECL(test_fileAccess),
  86010. /*********************************
  86011. * wolfcrypt
  86012. *********************************/
  86013. TEST_DECL(test_ForceZero),
  86014. TEST_DECL(test_wolfCrypt_Init),
  86015. TEST_DECL(test_wc_LoadStaticMemory_ex),
  86016. /* Locking with Compat Mutex */
  86017. TEST_DECL(test_wc_SetMutexCb),
  86018. TEST_DECL(test_wc_LockMutex_ex),
  86019. /* Digests */
  86020. TEST_DECL(test_wc_InitMd5),
  86021. TEST_DECL(test_wc_Md5Update),
  86022. TEST_DECL(test_wc_Md5Final),
  86023. TEST_DECL(test_wc_InitSha),
  86024. TEST_DECL(test_wc_ShaUpdate),
  86025. TEST_DECL(test_wc_ShaFinal),
  86026. TEST_DECL(test_wc_InitSha256),
  86027. TEST_DECL(test_wc_Sha256Update),
  86028. TEST_DECL(test_wc_Sha256Final),
  86029. TEST_DECL(test_wc_Sha256FinalRaw),
  86030. TEST_DECL(test_wc_Sha256GetFlags),
  86031. TEST_DECL(test_wc_Sha256Free),
  86032. TEST_DECL(test_wc_Sha256GetHash),
  86033. TEST_DECL(test_wc_Sha256Copy),
  86034. TEST_DECL(test_wc_InitSha224),
  86035. TEST_DECL(test_wc_Sha224Update),
  86036. TEST_DECL(test_wc_Sha224Final),
  86037. TEST_DECL(test_wc_Sha224SetFlags),
  86038. TEST_DECL(test_wc_Sha224GetFlags),
  86039. TEST_DECL(test_wc_Sha224Free),
  86040. TEST_DECL(test_wc_Sha224GetHash),
  86041. TEST_DECL(test_wc_Sha224Copy),
  86042. TEST_DECL(test_wc_InitSha512),
  86043. TEST_DECL(test_wc_Sha512Update),
  86044. TEST_DECL(test_wc_Sha512Final),
  86045. TEST_DECL(test_wc_Sha512GetFlags),
  86046. TEST_DECL(test_wc_Sha512FinalRaw),
  86047. TEST_DECL(test_wc_Sha512Free),
  86048. TEST_DECL(test_wc_Sha512GetHash),
  86049. TEST_DECL(test_wc_Sha512Copy),
  86050. TEST_DECL(test_wc_InitSha512_224),
  86051. TEST_DECL(test_wc_Sha512_224Update),
  86052. TEST_DECL(test_wc_Sha512_224Final),
  86053. TEST_DECL(test_wc_Sha512_224GetFlags),
  86054. TEST_DECL(test_wc_Sha512_224FinalRaw),
  86055. TEST_DECL(test_wc_Sha512_224Free),
  86056. TEST_DECL(test_wc_Sha512_224GetHash),
  86057. TEST_DECL(test_wc_Sha512_224Copy),
  86058. TEST_DECL(test_wc_InitSha512_256),
  86059. TEST_DECL(test_wc_Sha512_256Update),
  86060. TEST_DECL(test_wc_Sha512_256Final),
  86061. TEST_DECL(test_wc_Sha512_256GetFlags),
  86062. TEST_DECL(test_wc_Sha512_256FinalRaw),
  86063. TEST_DECL(test_wc_Sha512_256Free),
  86064. TEST_DECL(test_wc_Sha512_256GetHash),
  86065. TEST_DECL(test_wc_Sha512_256Copy),
  86066. TEST_DECL(test_wc_InitSha384),
  86067. TEST_DECL(test_wc_Sha384Update),
  86068. TEST_DECL(test_wc_Sha384Final),
  86069. TEST_DECL(test_wc_Sha384GetFlags),
  86070. TEST_DECL(test_wc_Sha384FinalRaw),
  86071. TEST_DECL(test_wc_Sha384Free),
  86072. TEST_DECL(test_wc_Sha384GetHash),
  86073. TEST_DECL(test_wc_Sha384Copy),
  86074. TEST_DECL(test_wc_InitBlake2b),
  86075. TEST_DECL(test_wc_InitBlake2b_WithKey),
  86076. TEST_DECL(test_wc_InitBlake2s_WithKey),
  86077. TEST_DECL(test_wc_InitRipeMd),
  86078. TEST_DECL(test_wc_RipeMdUpdate),
  86079. TEST_DECL(test_wc_RipeMdFinal),
  86080. TEST_DECL(test_wc_InitSha3),
  86081. TEST_DECL(testing_wc_Sha3_Update),
  86082. TEST_DECL(test_wc_Sha3_224_Final),
  86083. TEST_DECL(test_wc_Sha3_256_Final),
  86084. TEST_DECL(test_wc_Sha3_384_Final),
  86085. TEST_DECL(test_wc_Sha3_512_Final),
  86086. TEST_DECL(test_wc_Sha3_224_Copy),
  86087. TEST_DECL(test_wc_Sha3_256_Copy),
  86088. TEST_DECL(test_wc_Sha3_384_Copy),
  86089. TEST_DECL(test_wc_Sha3_512_Copy),
  86090. TEST_DECL(test_wc_Sha3_GetFlags),
  86091. TEST_DECL(test_wc_InitShake256),
  86092. TEST_DECL(testing_wc_Shake256_Update),
  86093. TEST_DECL(test_wc_Shake256_Final),
  86094. TEST_DECL(test_wc_Shake256_Copy),
  86095. TEST_DECL(test_wc_Shake256Hash),
  86096. /* SM3 Digest */
  86097. TEST_DECL(test_wc_InitSm3Free),
  86098. TEST_DECL(test_wc_Sm3UpdateFinal),
  86099. TEST_DECL(test_wc_Sm3GetHash),
  86100. TEST_DECL(test_wc_Sm3Copy),
  86101. TEST_DECL(test_wc_Sm3FinalRaw),
  86102. TEST_DECL(test_wc_Sm3GetSetFlags),
  86103. TEST_DECL(test_wc_Sm3Hash),
  86104. TEST_DECL(test_wc_HashInit),
  86105. TEST_DECL(test_wc_HashSetFlags),
  86106. TEST_DECL(test_wc_HashGetFlags),
  86107. /* HMAC */
  86108. TEST_DECL(test_wc_Md5HmacSetKey),
  86109. TEST_DECL(test_wc_Md5HmacUpdate),
  86110. TEST_DECL(test_wc_Md5HmacFinal),
  86111. TEST_DECL(test_wc_ShaHmacSetKey),
  86112. TEST_DECL(test_wc_ShaHmacUpdate),
  86113. TEST_DECL(test_wc_ShaHmacFinal),
  86114. TEST_DECL(test_wc_Sha224HmacSetKey),
  86115. TEST_DECL(test_wc_Sha224HmacUpdate),
  86116. TEST_DECL(test_wc_Sha224HmacFinal),
  86117. TEST_DECL(test_wc_Sha256HmacSetKey),
  86118. TEST_DECL(test_wc_Sha256HmacUpdate),
  86119. TEST_DECL(test_wc_Sha256HmacFinal),
  86120. TEST_DECL(test_wc_Sha384HmacSetKey),
  86121. TEST_DECL(test_wc_Sha384HmacUpdate),
  86122. TEST_DECL(test_wc_Sha384HmacFinal),
  86123. /* CMAC */
  86124. TEST_DECL(test_wc_InitCmac),
  86125. TEST_DECL(test_wc_CmacUpdate),
  86126. TEST_DECL(test_wc_CmacFinal),
  86127. TEST_DECL(test_wc_AesCmacGenerate),
  86128. /* Cipher */
  86129. TEST_DECL(test_wc_AesGcmStream),
  86130. TEST_DECL(test_wc_Des3_SetIV),
  86131. TEST_DECL(test_wc_Des3_SetKey),
  86132. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  86133. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  86134. TEST_DECL(test_wc_Des3_EcbEncrypt),
  86135. TEST_DECL(test_wc_Chacha_SetKey),
  86136. TEST_DECL(test_wc_Chacha_Process),
  86137. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  86138. TEST_DECL(test_wc_Poly1305SetKey),
  86139. TEST_DECL(test_wc_CamelliaSetKey),
  86140. TEST_DECL(test_wc_CamelliaSetIV),
  86141. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  86142. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  86143. TEST_DECL(test_wc_Arc4SetKey),
  86144. TEST_DECL(test_wc_Arc4Process),
  86145. TEST_DECL(test_wc_Rc2SetKey),
  86146. TEST_DECL(test_wc_Rc2SetIV),
  86147. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  86148. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  86149. /* AES cipher and GMAC. */
  86150. TEST_DECL(test_wc_AesSetKey),
  86151. TEST_DECL(test_wc_AesSetIV),
  86152. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  86153. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  86154. TEST_DECL(test_wc_AesGcmSetKey),
  86155. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  86156. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  86157. TEST_DECL(test_wc_GmacSetKey),
  86158. TEST_DECL(test_wc_GmacUpdate),
  86159. TEST_DECL(test_wc_AesCcmSetKey),
  86160. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  86161. #if defined(WOLFSSL_AES_EAX) && \
  86162. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  86163. TEST_DECL(test_wc_AesEaxVectors),
  86164. TEST_DECL(test_wc_AesEaxEncryptAuth),
  86165. TEST_DECL(test_wc_AesEaxDecryptAuth),
  86166. #endif /* WOLFSSL_AES_EAX */
  86167. /* SM4 cipher */
  86168. TEST_DECL(test_wc_Sm4),
  86169. TEST_DECL(test_wc_Sm4Ecb),
  86170. TEST_DECL(test_wc_Sm4Cbc),
  86171. TEST_DECL(test_wc_Sm4Ctr),
  86172. TEST_DECL(test_wc_Sm4Gcm),
  86173. TEST_DECL(test_wc_Sm4Ccm),
  86174. /* RNG tests */
  86175. #ifdef HAVE_HASHDRBG
  86176. #ifdef TEST_RESEED_INTERVAL
  86177. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  86178. #endif
  86179. TEST_DECL(test_wc_RNG_GenerateBlock),
  86180. #endif
  86181. TEST_DECL(test_get_rand_digit),
  86182. TEST_DECL(test_wc_InitRngNonce),
  86183. TEST_DECL(test_wc_InitRngNonce_ex),
  86184. /* MP API tests */
  86185. TEST_DECL(test_get_digit_count),
  86186. TEST_DECL(test_mp_cond_copy),
  86187. TEST_DECL(test_mp_rand),
  86188. TEST_DECL(test_get_digit),
  86189. TEST_DECL(test_wc_export_int),
  86190. /* RSA */
  86191. TEST_DECL(test_wc_InitRsaKey),
  86192. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  86193. TEST_DECL(test_wc_RsaPublicKeyDecode),
  86194. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  86195. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  86196. TEST_DECL(test_wc_MakeRsaKey),
  86197. TEST_DECL(test_wc_CheckProbablePrime),
  86198. TEST_DECL(test_wc_RsaPSS_Verify),
  86199. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  86200. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  86201. TEST_DECL(test_wc_RsaKeyToDer),
  86202. TEST_DECL(test_wc_RsaKeyToPublicDer),
  86203. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  86204. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  86205. TEST_DECL(test_wc_RsaEncryptSize),
  86206. TEST_DECL(test_wc_RsaSSL_SignVerify),
  86207. TEST_DECL(test_wc_RsaFlattenPublicKey),
  86208. TEST_DECL(test_RsaDecryptBoundsCheck),
  86209. /* DSA */
  86210. TEST_DECL(test_wc_InitDsaKey),
  86211. TEST_DECL(test_wc_DsaSignVerify),
  86212. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  86213. TEST_DECL(test_wc_MakeDsaKey),
  86214. TEST_DECL(test_wc_DsaKeyToDer),
  86215. TEST_DECL(test_wc_DsaKeyToPublicDer),
  86216. TEST_DECL(test_wc_DsaImportParamsRaw),
  86217. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  86218. TEST_DECL(test_wc_DsaExportParamsRaw),
  86219. TEST_DECL(test_wc_DsaExportKeyRaw),
  86220. /* DH */
  86221. TEST_DECL(test_wc_DhPublicKeyDecode),
  86222. /* wolfCrypt ECC tests */
  86223. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  86224. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  86225. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  86226. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  86227. !defined(HAVE_SELFTEST) && \
  86228. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  86229. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  86230. #endif
  86231. TEST_DECL(test_wc_ecc_make_key),
  86232. TEST_DECL(test_wc_ecc_init),
  86233. TEST_DECL(test_wc_ecc_check_key),
  86234. TEST_DECL(test_wc_ecc_get_generator),
  86235. TEST_DECL(test_wc_ecc_size),
  86236. TEST_DECL(test_wc_ecc_params),
  86237. TEST_DECL(test_wc_ecc_signVerify_hash),
  86238. TEST_DECL(test_wc_ecc_shared_secret),
  86239. TEST_DECL(test_wc_ecc_export_x963),
  86240. TEST_DECL(test_wc_ecc_export_x963_ex),
  86241. TEST_DECL(test_wc_ecc_import_x963),
  86242. TEST_DECL(test_wc_ecc_import_private_key),
  86243. TEST_DECL(test_wc_ecc_export_private_only),
  86244. TEST_DECL(test_wc_ecc_rs_to_sig),
  86245. TEST_DECL(test_wc_ecc_import_raw),
  86246. TEST_DECL(test_wc_ecc_import_unsigned),
  86247. TEST_DECL(test_wc_ecc_sig_size),
  86248. TEST_DECL(test_wc_ecc_ctx_new),
  86249. TEST_DECL(test_wc_ecc_ctx_reset),
  86250. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  86251. TEST_DECL(test_wc_ecc_ctx_set_info),
  86252. TEST_DECL(test_wc_ecc_encryptDecrypt),
  86253. TEST_DECL(test_wc_ecc_del_point),
  86254. TEST_DECL(test_wc_ecc_pointFns),
  86255. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  86256. TEST_DECL(test_wc_ecc_verify_hash_ex),
  86257. TEST_DECL(test_wc_ecc_mulmod),
  86258. TEST_DECL(test_wc_ecc_is_valid_idx),
  86259. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  86260. TEST_DECL(test_wc_ecc_sig_size_calc),
  86261. TEST_DECL(test_wc_EccPrivateKeyToDer),
  86262. /* SM2 elliptic curve */
  86263. TEST_DECL(test_wc_ecc_sm2_make_key),
  86264. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  86265. TEST_DECL(test_wc_ecc_sm2_create_digest),
  86266. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  86267. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  86268. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  86269. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  86270. /* Curve25519 */
  86271. TEST_DECL(test_wc_curve25519_init),
  86272. TEST_DECL(test_wc_curve25519_size),
  86273. TEST_DECL(test_wc_curve25519_export_key_raw),
  86274. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  86275. TEST_DECL(test_wc_curve25519_make_key),
  86276. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  86277. TEST_DECL(test_wc_curve25519_make_pub),
  86278. TEST_DECL(test_wc_curve25519_export_public_ex),
  86279. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  86280. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  86281. TEST_DECL(test_wc_curve25519_import_private),
  86282. /* ED25519 */
  86283. TEST_DECL(test_wc_ed25519_make_key),
  86284. TEST_DECL(test_wc_ed25519_init),
  86285. TEST_DECL(test_wc_ed25519_sign_msg),
  86286. TEST_DECL(test_wc_ed25519_import_public),
  86287. TEST_DECL(test_wc_ed25519_import_private_key),
  86288. TEST_DECL(test_wc_ed25519_export),
  86289. TEST_DECL(test_wc_ed25519_size),
  86290. TEST_DECL(test_wc_ed25519_exportKey),
  86291. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  86292. TEST_DECL(test_wc_Ed25519KeyToDer),
  86293. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  86294. /* Curve448 */
  86295. TEST_DECL(test_wc_curve448_make_key),
  86296. TEST_DECL(test_wc_curve448_shared_secret_ex),
  86297. TEST_DECL(test_wc_curve448_export_public_ex),
  86298. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  86299. TEST_DECL(test_wc_curve448_export_key_raw),
  86300. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  86301. TEST_DECL(test_wc_curve448_import_private),
  86302. TEST_DECL(test_wc_curve448_init),
  86303. TEST_DECL(test_wc_curve448_size),
  86304. /* Ed448 */
  86305. TEST_DECL(test_wc_ed448_make_key),
  86306. TEST_DECL(test_wc_ed448_init),
  86307. TEST_DECL(test_wc_ed448_sign_msg),
  86308. TEST_DECL(test_wc_ed448_import_public),
  86309. TEST_DECL(test_wc_ed448_import_private_key),
  86310. TEST_DECL(test_wc_ed448_export),
  86311. TEST_DECL(test_wc_ed448_size),
  86312. TEST_DECL(test_wc_ed448_exportKey),
  86313. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  86314. TEST_DECL(test_wc_Ed448KeyToDer),
  86315. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  86316. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  86317. /* Kyber */
  86318. TEST_DECL(test_wc_kyber_make_key_kats),
  86319. TEST_DECL(test_wc_kyber_encapsulate_kats),
  86320. TEST_DECL(test_wc_kyber_decapsulate_kats),
  86321. /* Dilithium */
  86322. TEST_DECL(test_wc_dilithium),
  86323. TEST_DECL(test_wc_dilithium_make_key),
  86324. TEST_DECL(test_wc_dilithium_sign),
  86325. TEST_DECL(test_wc_dilithium_verify),
  86326. TEST_DECL(test_wc_dilithium_sign_vfy),
  86327. TEST_DECL(test_wc_dilithium_check_key),
  86328. TEST_DECL(test_wc_dilithium_public_der_decode),
  86329. TEST_DECL(test_wc_dilithium_der),
  86330. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  86331. TEST_DECL(test_wc_dilithium_sig_kats),
  86332. TEST_DECL(test_wc_dilithium_verify_kats),
  86333. /* Signature API */
  86334. TEST_DECL(test_wc_SignatureGetSize_ecc),
  86335. TEST_DECL(test_wc_SignatureGetSize_rsa),
  86336. /* PEM and DER APIs. */
  86337. TEST_DECL(test_wc_PemToDer),
  86338. TEST_DECL(test_wc_AllocDer),
  86339. TEST_DECL(test_wc_CertPemToDer),
  86340. TEST_DECL(test_wc_KeyPemToDer),
  86341. TEST_DECL(test_wc_PubKeyPemToDer),
  86342. TEST_DECL(test_wc_PemPubKeyToDer),
  86343. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  86344. TEST_DECL(test_wc_CheckCertSigPubKey),
  86345. /* wolfCrypt ASN tests */
  86346. TEST_DECL(test_ToTraditional),
  86347. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  86348. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  86349. /* Certificate */
  86350. TEST_DECL(test_wc_SetSubjectRaw),
  86351. TEST_DECL(test_wc_GetSubjectRaw),
  86352. TEST_DECL(test_wc_SetIssuerRaw),
  86353. TEST_DECL(test_wc_SetIssueBuffer),
  86354. TEST_DECL(test_wc_SetSubjectKeyId),
  86355. TEST_DECL(test_wc_SetSubject),
  86356. TEST_DECL(test_CheckCertSignature),
  86357. TEST_DECL(test_wc_ParseCert),
  86358. TEST_DECL(test_wc_ParseCert_Error),
  86359. TEST_DECL(test_MakeCertWithPathLen),
  86360. TEST_DECL(test_MakeCertWith0Ser),
  86361. TEST_DECL(test_MakeCertWithCaFalse),
  86362. TEST_DECL(test_wc_SetKeyUsage),
  86363. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  86364. TEST_DECL(test_wc_SetSubjectBuffer),
  86365. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  86366. /* wolfcrypt PKCS#7 */
  86367. TEST_DECL(test_wc_PKCS7_New),
  86368. TEST_DECL(test_wc_PKCS7_Init),
  86369. TEST_DECL(test_wc_PKCS7_InitWithCert),
  86370. TEST_DECL(test_wc_PKCS7_EncodeData),
  86371. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  86372. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  86373. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  86374. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  86375. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  86376. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  86377. TEST_DECL(test_wc_PKCS7_Degenerate),
  86378. TEST_DECL(test_wc_PKCS7_BER),
  86379. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  86380. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  86381. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  86382. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  86383. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  86384. /* wolfCrypt PKCS#12 */
  86385. TEST_DECL(test_wc_i2d_PKCS12),
  86386. /*
  86387. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  86388. * avoid memory leaks.
  86389. */
  86390. TEST_DECL(test_wolfCrypt_Cleanup),
  86391. TEST_DECL(test_wolfSSL_Init),
  86392. TEST_DECL(test_dual_alg_support),
  86393. /*********************************
  86394. * OpenSSL compatibility API tests
  86395. *********************************/
  86396. /* If at some point a stub get implemented this test should fail indicating
  86397. * a need to implement a new test case
  86398. */
  86399. TEST_DECL(test_stubs_are_stubs),
  86400. /* ASN.1 compatibility API tests */
  86401. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  86402. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  86403. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  86404. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  86405. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  86406. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  86407. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  86408. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  86409. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  86410. TEST_DECL(test_wolfSSL_ASN1_get_object),
  86411. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  86412. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  86413. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  86414. TEST_DECL(test_wolfSSL_ASN1_STRING),
  86415. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  86416. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  86417. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  86418. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  86419. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  86420. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  86421. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  86422. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  86423. TEST_DECL(test_wolfSSL_ASN1_TIME),
  86424. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  86425. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  86426. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  86427. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  86428. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  86429. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  86430. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  86431. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  86432. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  86433. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  86434. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  86435. TEST_DECL(test_ASN1_strings),
  86436. TEST_DECL(test_wolfSSL_lhash),
  86437. TEST_DECL(test_wolfSSL_certs),
  86438. TEST_DECL(test_wolfSSL_private_keys),
  86439. TEST_DECL(test_wolfSSL_PEM_def_callback),
  86440. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  86441. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  86442. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  86443. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  86444. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  86445. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  86446. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  86447. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  86448. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  86449. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  86450. #ifndef NO_BIO
  86451. TEST_DECL(test_wolfSSL_BIO),
  86452. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  86453. TEST_DECL(test_wolfSSL_PEM_read_bio),
  86454. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  86455. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  86456. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  86457. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  86458. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  86459. #endif
  86460. /* EVP API testing */
  86461. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  86462. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  86463. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  86464. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  86465. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  86466. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  86467. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  86468. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  86469. TEST_DECL(test_wolfSSL_EVP_shake128),
  86470. TEST_DECL(test_wolfSSL_EVP_shake256),
  86471. TEST_DECL(test_wolfSSL_EVP_sm3),
  86472. TEST_DECL(test_EVP_blake2),
  86473. #ifdef OPENSSL_ALL
  86474. TEST_DECL(test_wolfSSL_EVP_md4),
  86475. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  86476. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  86477. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  86478. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  86479. #endif
  86480. TEST_DECL(test_EVP_MD_do_all),
  86481. TEST_DECL(test_wolfSSL_EVP_MD_size),
  86482. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  86483. TEST_DECL(test_wolfSSL_EVP_Digest),
  86484. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  86485. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  86486. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  86487. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  86488. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  86489. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  86490. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  86491. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  86492. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  86493. TEST_DECL(test_wolfssl_EVP_chacha20),
  86494. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  86495. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  86496. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  86497. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  86498. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  86499. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  86500. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  86501. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  86502. #ifdef OPENSSL_ALL
  86503. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  86504. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  86505. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  86506. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  86507. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  86508. TEST_DECL(test_wolfSSL_EVP_rc4),
  86509. TEST_DECL(test_wolfSSL_EVP_enc_null),
  86510. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  86511. TEST_DECL(test_wolfSSL_EVP_mdc2),
  86512. TEST_DECL(test_evp_cipher_aes_gcm),
  86513. #endif
  86514. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  86515. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  86516. #ifdef OPENSSL_EXTRA
  86517. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  86518. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  86519. #endif
  86520. #ifdef OPENSSL_ALL
  86521. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  86522. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  86523. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  86524. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  86525. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  86526. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  86527. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  86528. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  86529. #endif
  86530. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  86531. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  86532. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  86533. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  86534. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  86535. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  86536. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  86537. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  86538. #ifndef NO_BIO
  86539. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  86540. #endif
  86541. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  86542. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  86543. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86544. #ifndef NO_BIO
  86545. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  86546. #endif /* !NO_BIO */
  86547. #endif
  86548. #ifdef OPENSSL_ALL
  86549. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  86550. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  86551. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  86552. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  86553. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  86554. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  86555. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  86556. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  86557. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  86558. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  86559. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  86560. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  86561. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  86562. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  86563. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  86564. #endif
  86565. TEST_DECL(test_EVP_PKEY_rsa),
  86566. TEST_DECL(test_EVP_PKEY_ec),
  86567. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  86568. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  86569. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  86570. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  86571. TEST_DECL(test_EVP_PKEY_cmp),
  86572. #ifdef OPENSSL_ALL
  86573. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  86574. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  86575. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  86576. #endif
  86577. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  86578. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  86579. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  86580. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  86581. #endif
  86582. #ifndef NO_BIO
  86583. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  86584. TEST_DECL(test_wolfSSL_GetLoggingCb),
  86585. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  86586. TEST_DECL(test_wc_ERR_remove_state),
  86587. TEST_DECL(test_wc_ERR_print_errors_fp),
  86588. #endif
  86589. TEST_DECL(test_wolfSSL_configure_args),
  86590. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  86591. TEST_DECL(test_wolfSSL_set1_curves_list),
  86592. TEST_DECL(test_wolfSSL_curves_mismatch),
  86593. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  86594. TEST_DECL(test_wolfSSL_OtherName),
  86595. TEST_DECL(test_wolfSSL_FPKI),
  86596. TEST_DECL(test_wolfSSL_URI),
  86597. TEST_DECL(test_wolfSSL_TBS),
  86598. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  86599. TEST_DECL(test_X509_STORE_untrusted),
  86600. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  86601. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  86602. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  86603. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  86604. TEST_DECL(test_wolfSSL_X509_Name_canon),
  86605. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  86606. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  86607. TEST_DECL(test_wolfSSL_X509_NID),
  86608. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  86609. TEST_DECL(test_wolfSSL_get0_param),
  86610. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  86611. TEST_DECL(test_wolfSSL_set1_host),
  86612. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  86613. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  86614. TEST_DECL(test_wolfSSL_X509_STORE),
  86615. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  86616. TEST_DECL(test_X509_STORE_get0_objects),
  86617. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  86618. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  86619. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  86620. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  86621. TEST_DECL(test_wolfSSL_X509_cmp_time),
  86622. TEST_DECL(test_wolfSSL_X509_time_adj),
  86623. /* X509 tests */
  86624. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  86625. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  86626. TEST_DECL(test_wolfSSL_X509_check_host),
  86627. TEST_DECL(test_wolfSSL_X509_check_email),
  86628. TEST_DECL(test_wolfSSL_X509_check_private_key),
  86629. TEST_DECL(test_wolfSSL_X509),
  86630. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  86631. TEST_DECL(test_wolfSSL_X509_sign),
  86632. TEST_DECL(test_wolfSSL_X509_sign2),
  86633. TEST_DECL(test_wolfSSL_X509_verify),
  86634. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  86635. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  86636. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  86637. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  86638. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  86639. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  86640. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  86641. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  86642. TEST_DECL(test_wolfSSL_X509_NAME),
  86643. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  86644. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  86645. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  86646. TEST_DECL(test_wolfSSL_X509_set_name),
  86647. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  86648. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  86649. TEST_DECL(test_wolfSSL_X509_set_version),
  86650. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  86651. TEST_DECL(test_wolfSSL_X509_CRL),
  86652. TEST_DECL(test_wolfSSL_i2d_X509),
  86653. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  86654. TEST_DECL(test_wolfSSL_PEM_read_X509),
  86655. TEST_DECL(test_wolfSSL_X509_check_ca),
  86656. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  86657. TEST_DECL(test_wolfSSL_X509_bad_altname),
  86658. TEST_DECL(test_wolfSSL_X509_name_match),
  86659. TEST_DECL(test_wolfSSL_X509_name_match2),
  86660. TEST_DECL(test_wolfSSL_X509_name_match3),
  86661. TEST_DECL(test_wolfSSL_X509_max_altnames),
  86662. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  86663. TEST_DECL(test_wolfSSL_make_cert),
  86664. /* X509 ACERT tests */
  86665. TEST_DECL(test_wolfSSL_X509_ACERT_verify),
  86666. TEST_DECL(test_wolfSSL_X509_ACERT_misc_api),
  86667. #ifndef NO_BIO
  86668. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  86669. TEST_DECL(test_wolfSSL_X509_INFO),
  86670. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  86671. #endif
  86672. #ifdef OPENSSL_ALL
  86673. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  86674. #endif
  86675. TEST_DECL(test_wolfSSL_X509_CA_num),
  86676. TEST_DECL(test_x509_get_key_id),
  86677. TEST_DECL(test_wolfSSL_X509_get_version),
  86678. #ifndef NO_BIO
  86679. TEST_DECL(test_wolfSSL_X509_print),
  86680. TEST_DECL(test_wolfSSL_X509_CRL_print),
  86681. #endif
  86682. TEST_DECL(test_X509_get_signature_nid),
  86683. /* X509 extension testing. */
  86684. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  86685. TEST_DECL(test_wolfSSL_X509_get_ext),
  86686. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  86687. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  86688. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  86689. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  86690. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  86691. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  86692. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  86693. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  86694. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  86695. TEST_DECL(test_wolfSSL_X509V3_EXT),
  86696. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  86697. TEST_DECL(test_wolfSSL_X509_cmp),
  86698. TEST_DECL(test_GENERAL_NAME_set0_othername),
  86699. TEST_DECL(test_othername_and_SID_ext),
  86700. TEST_DECL(test_wolfSSL_dup_CA_list),
  86701. /* OpenSSL sk_X509 API test */
  86702. TEST_DECL(test_sk_X509),
  86703. /* OpenSSL sk_X509_CRL API test */
  86704. TEST_DECL(test_sk_X509_CRL),
  86705. /* OpenSSL X509 REQ API test */
  86706. TEST_DECL(test_X509_REQ),
  86707. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  86708. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  86709. TEST_DECL(test_X509_LOOKUP_add_dir),
  86710. /* RAND compatibility API */
  86711. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  86712. TEST_DECL(test_wolfSSL_RAND_bytes),
  86713. TEST_DECL(test_wolfSSL_RAND),
  86714. /* BN compatibility API */
  86715. TEST_DECL(test_wolfSSL_BN_CTX),
  86716. TEST_DECL(test_wolfSSL_BN),
  86717. TEST_DECL(test_wolfSSL_BN_init),
  86718. TEST_DECL(test_wolfSSL_BN_enc_dec),
  86719. TEST_DECL(test_wolfSSL_BN_word),
  86720. TEST_DECL(test_wolfSSL_BN_bits),
  86721. TEST_DECL(test_wolfSSL_BN_shift),
  86722. TEST_DECL(test_wolfSSL_BN_math),
  86723. TEST_DECL(test_wolfSSL_BN_math_mod),
  86724. TEST_DECL(test_wolfSSL_BN_math_other),
  86725. TEST_DECL(test_wolfSSL_BN_rand),
  86726. TEST_DECL(test_wolfSSL_BN_prime),
  86727. /* OpenSSL PKCS5 API test */
  86728. TEST_DECL(test_wolfSSL_PKCS5),
  86729. /* OpenSSL PKCS8 API test */
  86730. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  86731. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  86732. /* OpenSSL PKCS7 API test */
  86733. TEST_DECL(test_wolfssl_PKCS7),
  86734. TEST_DECL(test_wolfSSL_PKCS7_certs),
  86735. TEST_DECL(test_wolfSSL_PKCS7_sign),
  86736. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  86737. #ifndef NO_BIO
  86738. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  86739. #ifdef HAVE_SMIME
  86740. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  86741. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  86742. #endif /* HAVE_SMIME */
  86743. #endif /* !NO_BIO */
  86744. /* OpenSSL PKCS12 API test */
  86745. TEST_DECL(test_wolfSSL_PKCS12),
  86746. /* Can't memory test as callbacks use Assert. */
  86747. TEST_DECL(test_error_queue_per_thread),
  86748. TEST_DECL(test_wolfSSL_ERR_put_error),
  86749. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  86750. #ifndef NO_BIO
  86751. TEST_DECL(test_wolfSSL_ERR_print_errors),
  86752. #endif
  86753. TEST_DECL(test_OBJ_NAME_do_all),
  86754. TEST_DECL(test_wolfSSL_OBJ),
  86755. TEST_DECL(test_wolfSSL_OBJ_cmp),
  86756. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  86757. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  86758. #ifdef OPENSSL_ALL
  86759. TEST_DECL(test_wolfSSL_OBJ_ln),
  86760. TEST_DECL(test_wolfSSL_OBJ_sn),
  86761. #endif
  86762. #ifndef NO_BIO
  86763. TEST_DECL(test_wolfSSL_BIO_gets),
  86764. TEST_DECL(test_wolfSSL_BIO_puts),
  86765. TEST_DECL(test_wolfSSL_BIO_dump),
  86766. /* Can't memory test as server hangs. */
  86767. TEST_DECL(test_wolfSSL_BIO_should_retry),
  86768. TEST_DECL(test_wolfSSL_BIO_write),
  86769. TEST_DECL(test_wolfSSL_BIO_printf),
  86770. TEST_DECL(test_wolfSSL_BIO_f_md),
  86771. TEST_DECL(test_wolfSSL_BIO_up_ref),
  86772. TEST_DECL(test_wolfSSL_BIO_reset),
  86773. TEST_DECL(test_wolfSSL_BIO_get_len),
  86774. #endif
  86775. TEST_DECL(test_wolfSSL_check_domain),
  86776. TEST_DECL(test_wolfSSL_cert_cb),
  86777. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  86778. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  86779. TEST_DECL(test_wolfSSL_sigalg_info),
  86780. /* Can't memory test as tcp_connect aborts. */
  86781. TEST_DECL(test_wolfSSL_SESSION),
  86782. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  86783. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  86784. TEST_DECL(test_wolfSSL_ticket_keys),
  86785. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  86786. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  86787. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  86788. TEST_DECL(test_wolfSSL_verify_mode),
  86789. TEST_DECL(test_wolfSSL_verify_depth),
  86790. TEST_DECL(test_wolfSSL_verify_result),
  86791. TEST_DECL(test_wolfSSL_msg_callback),
  86792. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  86793. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  86794. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  86795. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  86796. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  86797. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  86798. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  86799. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  86800. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  86801. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  86802. TEST_DECL(test_wolfSSL_PEM_read),
  86803. TEST_DECL(test_wolfSSL_OpenSSL_version),
  86804. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  86805. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  86806. TEST_DECL(test_CONF_modules_xxx),
  86807. #ifdef OPENSSL_ALL
  86808. TEST_DECL(test_wolfSSL_TXT_DB),
  86809. TEST_DECL(test_wolfSSL_NCONF),
  86810. #endif
  86811. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  86812. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  86813. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  86814. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  86815. TEST_DECL(test_CRYPTO_THREADID_xxx),
  86816. TEST_DECL(test_ENGINE_cleanup),
  86817. /* test the no op functions for compatibility */
  86818. TEST_DECL(test_no_op_functions),
  86819. /* OpenSSL error API tests */
  86820. TEST_DECL(test_ERR_load_crypto_strings),
  86821. #ifdef OPENSSL_ALL
  86822. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  86823. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  86824. TEST_DECL(test_wolfSSL_CTX_ctrl),
  86825. #endif /* OPENSSL_ALL */
  86826. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86827. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  86828. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  86829. /*********************************
  86830. * Crypto API tests
  86831. *********************************/
  86832. TEST_DECL(test_wolfSSL_MD4),
  86833. TEST_DECL(test_wolfSSL_MD5),
  86834. TEST_DECL(test_wolfSSL_MD5_Transform),
  86835. TEST_DECL(test_wolfSSL_SHA),
  86836. TEST_DECL(test_wolfSSL_SHA_Transform),
  86837. TEST_DECL(test_wolfSSL_SHA224),
  86838. TEST_DECL(test_wolfSSL_SHA256),
  86839. TEST_DECL(test_wolfSSL_SHA256_Transform),
  86840. TEST_DECL(test_wolfSSL_SHA512_Transform),
  86841. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  86842. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  86843. TEST_DECL(test_wolfSSL_HMAC_CTX),
  86844. TEST_DECL(test_wolfSSL_HMAC),
  86845. TEST_DECL(test_wolfSSL_CMAC),
  86846. TEST_DECL(test_wolfSSL_DES),
  86847. TEST_DECL(test_wolfSSL_DES_ncbc),
  86848. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  86849. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  86850. TEST_DECL(test_wolfSSL_AES_encrypt),
  86851. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  86852. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  86853. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  86854. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  86855. TEST_DECL(test_wolfSSL_RC4),
  86856. TEST_DECL(test_wolfSSL_RSA),
  86857. TEST_DECL(test_wolfSSL_RSA_DER),
  86858. TEST_DECL(test_wolfSSL_RSA_print),
  86859. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  86860. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  86861. TEST_DECL(test_wolfSSL_RSA_get0_key),
  86862. TEST_DECL(test_wolfSSL_RSA_meth),
  86863. TEST_DECL(test_wolfSSL_RSA_verify),
  86864. TEST_DECL(test_wolfSSL_RSA_sign),
  86865. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  86866. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  86867. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  86868. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  86869. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  86870. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  86871. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  86872. TEST_DECL(test_wolfSSL_RSA_ex_data),
  86873. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  86874. TEST_DECL(test_wolfSSL_RSA_To_Der),
  86875. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  86876. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  86877. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  86878. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  86879. TEST_DECL(test_wolfSSL_DH),
  86880. TEST_DECL(test_wolfSSL_DH_dup),
  86881. TEST_DECL(test_wolfSSL_DH_check),
  86882. TEST_DECL(test_wolfSSL_DH_prime),
  86883. TEST_DECL(test_wolfSSL_DH_1536_prime),
  86884. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  86885. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  86886. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  86887. TEST_DECL(test_wolfSSL_d2i_DHparams),
  86888. TEST_DECL(test_wolfSSL_DH_LoadDer),
  86889. TEST_DECL(test_wolfSSL_i2d_DHparams),
  86890. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  86891. TEST_DECL(test_wolfSSL_EC_GROUP),
  86892. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  86893. TEST_DECL(test_wolfSSL_EC_POINT),
  86894. TEST_DECL(test_wolfSSL_SPAKE),
  86895. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  86896. TEST_DECL(test_EC_i2d),
  86897. TEST_DECL(test_wolfSSL_EC_curve),
  86898. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  86899. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  86900. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  86901. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  86902. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  86903. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  86904. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  86905. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  86906. TEST_DECL(test_ECDSA_size_sign),
  86907. TEST_DECL(test_ECDH_compute_key),
  86908. #endif
  86909. #ifdef OPENSSL_EXTRA
  86910. TEST_DECL(test_EC25519),
  86911. TEST_DECL(test_ED25519),
  86912. TEST_DECL(test_EC448),
  86913. TEST_DECL(test_ED448),
  86914. #endif
  86915. TEST_DECL(test_DSA_do_sign_verify),
  86916. #ifdef OPENSSL_ALL
  86917. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  86918. TEST_DECL(test_wolfSSL_DSA_SIG),
  86919. #endif
  86920. TEST_DECL(test_openssl_generate_key_and_cert),
  86921. TEST_DECL(test_wolfSSL_FIPS_mode),
  86922. TEST_DECL(test_openssl_FIPS_drbg),
  86923. /*********************************
  86924. * CertManager API tests
  86925. *********************************/
  86926. TEST_DECL(test_wolfSSL_CertManagerAPI),
  86927. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  86928. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  86929. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  86930. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  86931. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  86932. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  86933. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  86934. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  86935. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  86936. TEST_DECL(test_wolfSSL_CertManagerCRL),
  86937. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  86938. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  86939. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86940. TEST_DECL(test_various_pathlen_chains),
  86941. #endif
  86942. /*********************************
  86943. * SSL/TLS API tests
  86944. *********************************/
  86945. TEST_DECL(test_wolfSSL_Method_Allocators),
  86946. #ifndef NO_WOLFSSL_SERVER
  86947. TEST_DECL(test_wolfSSL_CTX_new),
  86948. #endif
  86949. TEST_DECL(test_server_wolfSSL_new),
  86950. TEST_DECL(test_client_wolfSSL_new),
  86951. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  86952. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  86953. TEST_DECL(test_for_double_Free),
  86954. #endif
  86955. TEST_DECL(test_wolfSSL_set_options),
  86956. #ifdef WOLFSSL_TLS13
  86957. /* TLS v1.3 API tests */
  86958. TEST_DECL(test_tls13_apis),
  86959. TEST_DECL(test_tls13_cipher_suites),
  86960. #endif
  86961. TEST_DECL(test_wolfSSL_tmp_dh),
  86962. TEST_DECL(test_wolfSSL_ctrl),
  86963. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  86964. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  86965. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  86966. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  86967. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  86968. #endif
  86969. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  86970. TEST_DECL(test_wolfSSL_security_level),
  86971. TEST_DECL(test_wolfSSL_SSL_in_init),
  86972. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  86973. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  86974. TEST_DECL(test_CONF_CTX_FILE),
  86975. TEST_DECL(test_CONF_CTX_CMDLINE),
  86976. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  86977. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  86978. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  86979. /* Bad certificate signature tests */
  86980. TEST_DECL(test_EccSigFailure_cm),
  86981. TEST_DECL(test_RsaSigFailure_cm),
  86982. #endif /* NO_CERTS */
  86983. /* PKCS8 testing */
  86984. TEST_DECL(test_wolfSSL_no_password_cb),
  86985. TEST_DECL(test_wolfSSL_PKCS8),
  86986. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  86987. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  86988. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86989. TEST_DECL(test_wolfSSL_get_finished),
  86990. /* Uses Assert in handshake callback. */
  86991. TEST_DECL(test_wolfSSL_CTX_add_session),
  86992. /* Large number of memory allocations. */
  86993. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  86994. /* Large number of memory allocations. */
  86995. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  86996. /* Large number of memory allocations. */
  86997. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  86998. /* Large number of memory allocations. */
  86999. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  87000. /* Large number of memory allocations. */
  87001. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  87002. /* Large number of memory allocations. */
  87003. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  87004. #endif
  87005. TEST_DECL(test_SSL_CIPHER_get_xxx),
  87006. TEST_DECL(test_wolfSSL_ERR_strings),
  87007. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  87008. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  87009. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  87010. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  87011. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  87012. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  87013. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  87014. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  87015. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  87016. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  87017. /* Large number of memory allocations. */
  87018. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  87019. #ifdef HAVE_CERT_CHAIN_VALIDATION
  87020. TEST_DECL(test_wolfSSL_CertRsaPss),
  87021. #endif
  87022. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  87023. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  87024. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  87025. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  87026. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  87027. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  87028. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  87029. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  87030. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  87031. TEST_DECL(test_multiple_crls_same_issuer),
  87032. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  87033. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  87034. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  87035. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  87036. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  87037. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  87038. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  87039. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  87040. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  87041. TEST_DECL(test_SetTmpEC_DHE_Sz),
  87042. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  87043. #ifdef WOLFSSL_DTLS
  87044. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  87045. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  87046. #endif
  87047. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  87048. /* Uses Assert in handshake callback. */
  87049. TEST_DECL(test_wolfSSL_dtls_plaintext),
  87050. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  87051. defined(HAVE_IO_TESTS_DEPENDENCIES)
  87052. TEST_DECL(test_wolfSSL_read_write),
  87053. /* Can't memory test as server hangs if client fails before second connect.
  87054. */
  87055. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  87056. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  87057. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  87058. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  87059. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  87060. /* Can't memory test as server hangs. */
  87061. TEST_DECL(test_wolfSSL_dtls_export),
  87062. /* Uses Assert in handshake callback. */
  87063. TEST_DECL(test_wolfSSL_tls_export),
  87064. #endif
  87065. TEST_DECL(test_wolfSSL_dtls_export_peers),
  87066. TEST_DECL(test_wolfSSL_SetMinVersion),
  87067. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  87068. /* wolfSSL handshake APIs. */
  87069. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  87070. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  87071. TEST_DECL(test_wolfSSL_BUF),
  87072. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  87073. /* Can't memory test as server hangs. */
  87074. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  87075. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  87076. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  87077. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  87078. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  87079. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  87080. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  87081. /* Can't memory test as server hangs. */
  87082. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  87083. TEST_DECL(test_wolfSSL_Tls13_postauth),
  87084. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  87085. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  87086. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  87087. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  87088. TEST_DECL(test_wolfSSL_THREADID_hash),
  87089. /* TLS extensions tests */
  87090. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  87091. #ifdef HAVE_SNI
  87092. TEST_DECL(test_wolfSSL_UseSNI_params),
  87093. /* Uses Assert in handshake callback. */
  87094. TEST_DECL(test_wolfSSL_UseSNI_connection),
  87095. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  87096. #endif /* HAVE_SNI */
  87097. #endif
  87098. TEST_DECL(test_wolfSSL_UseTrustedCA),
  87099. TEST_DECL(test_wolfSSL_UseMaxFragment),
  87100. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  87101. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  87102. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  87103. /* Uses Assert in handshake callback. */
  87104. TEST_DECL(test_wolfSSL_UseALPN_connection),
  87105. TEST_DECL(test_wolfSSL_UseALPN_params),
  87106. #endif
  87107. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  87108. /* Uses Assert in handshake callback. */
  87109. TEST_DECL(test_wolfSSL_set_alpn_protos),
  87110. #endif
  87111. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  87112. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  87113. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  87114. TEST_DECL(test_tls_ext_duplicate),
  87115. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  87116. defined(HAVE_IO_TESTS_DEPENDENCIES)
  87117. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  87118. /* Uses Assert in handshake callback. */
  87119. TEST_DECL(test_wolfSSL_Tls13_ECH),
  87120. #endif
  87121. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  87122. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  87123. /* OCSP Stapling */
  87124. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  87125. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  87126. TEST_DECL(test_self_signed_stapling),
  87127. TEST_DECL(test_ocsp_callback_fails),
  87128. /* Multicast */
  87129. TEST_DECL(test_wolfSSL_mcast),
  87130. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  87131. TEST_DECL(test_wolfSSL_msgCb),
  87132. TEST_DECL(test_wolfSSL_either_side),
  87133. TEST_DECL(test_wolfSSL_DTLS_either_side),
  87134. /* Uses Assert in handshake callback. */
  87135. TEST_DECL(test_wolfSSL_dtls_fragments),
  87136. /* Uses Assert in handshake callback. */
  87137. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  87138. /* Uses Assert in handshake callback. */
  87139. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  87140. /* Uses Assert in handshake callback. */
  87141. TEST_DECL(test_wolfSSL_dtls_bad_record),
  87142. /* Uses Assert in handshake callback. */
  87143. TEST_DECL(test_wolfSSL_dtls_stateless),
  87144. TEST_DECL(test_generate_cookie),
  87145. #ifndef NO_BIO
  87146. /* Can't memory test as server hangs. */
  87147. TEST_DECL(test_wolfSSL_BIO_connect),
  87148. /* Can't memory test as server Asserts in thread. */
  87149. TEST_DECL(test_wolfSSL_BIO_accept),
  87150. TEST_DECL(test_wolfSSL_BIO_tls),
  87151. TEST_DECL(test_wolfSSL_BIO_datagram),
  87152. #endif
  87153. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  87154. TEST_DECL(test_DhCallbacks),
  87155. #endif
  87156. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  87157. TEST_DECL(test_export_keying_material),
  87158. #endif
  87159. /* Can't memory test as client/server Asserts in thread. */
  87160. TEST_DECL(test_ticket_and_psk_mixing),
  87161. /* Can't memory test as client/server Asserts in thread. */
  87162. TEST_DECL(test_prioritize_psk),
  87163. /* Can't memory test as client/server hangs. */
  87164. TEST_DECL(test_wc_CryptoCb),
  87165. /* Can't memory test as client/server hangs. */
  87166. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  87167. #if !defined(NO_FILESYSTEM) && \
  87168. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  87169. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  87170. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  87171. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  87172. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  87173. #ifdef HAVE_MAX_FRAGMENT
  87174. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  87175. #endif /* HAVE_MAX_FRAGMENT */
  87176. #ifndef NO_RSA
  87177. TEST_DECL(test_wolfSSL_dtls_stateless2),
  87178. #if !defined(NO_OLD_TLS)
  87179. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  87180. #endif /* !defined(NO_OLD_TLS) */
  87181. #endif /* ! NO_RSA */
  87182. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  87183. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  87184. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  87185. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  87186. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  87187. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  87188. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  87189. && defined(WOLFSSL_TLS13) && \
  87190. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  87191. TEST_DECL(test_ticket_nonce_malloc),
  87192. #endif
  87193. TEST_DECL(test_ticket_ret_create),
  87194. TEST_DECL(test_wrong_cs_downgrade),
  87195. TEST_DECL(test_extra_alerts_wrong_cs),
  87196. TEST_DECL(test_extra_alerts_skip_hs),
  87197. TEST_DECL(test_extra_alerts_bad_psk),
  87198. TEST_DECL(test_multiple_alerts_EAGAIN),
  87199. TEST_DECL(test_tls13_bad_psk_binder),
  87200. /* Can't memory test as client/server Asserts. */
  87201. TEST_DECL(test_harden_no_secure_renegotiation),
  87202. TEST_DECL(test_override_alt_cert_chain),
  87203. TEST_DECL(test_rpk_set_xxx_cert_type),
  87204. TEST_DECL(test_tls13_rpk_handshake),
  87205. TEST_DECL(test_dtls13_bad_epoch_ch),
  87206. TEST_DECL(test_short_session_id),
  87207. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  87208. /* Can't memory test as client/server hangs. */
  87209. TEST_DECL(test_dtls_msg_from_other_peer),
  87210. TEST_DECL(test_dtls_ipv6_check),
  87211. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  87212. TEST_DECL(test_dtls_no_extensions),
  87213. TEST_DECL(test_tls_alert_no_server_hello),
  87214. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  87215. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  87216. TEST_DECL(test_session_ticket_no_id),
  87217. TEST_DECL(test_session_ticket_hs_update),
  87218. TEST_DECL(test_dtls_downgrade_scr_server),
  87219. TEST_DECL(test_dtls_downgrade_scr),
  87220. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  87221. TEST_DECL(test_dtls_client_hello_timeout),
  87222. TEST_DECL(test_dtls_dropped_ccs),
  87223. TEST_DECL(test_dtls_seq_num_downgrade),
  87224. TEST_DECL(test_certreq_sighash_algos),
  87225. TEST_DECL(test_revoked_loaded_int_cert),
  87226. TEST_DECL(test_dtls_frag_ch),
  87227. TEST_DECL(test_dtls13_frag_ch_pq),
  87228. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  87229. TEST_DECL(test_dtls_old_seq_number),
  87230. TEST_DECL(test_dtls13_basic_connection_id),
  87231. TEST_DECL(test_tls13_pq_groups),
  87232. TEST_DECL(test_tls13_early_data),
  87233. TEST_DECL(test_tls_multi_handshakes_one_record),
  87234. TEST_DECL(test_write_dup),
  87235. TEST_DECL(test_read_write_hs),
  87236. TEST_DECL(test_get_signature_nid),
  87237. TEST_DECL(test_tls_cert_store_unchanged),
  87238. TEST_DECL(test_wolfSSL_SendUserCanceled),
  87239. /* This test needs to stay at the end to clean up any caches allocated. */
  87240. TEST_DECL(test_wolfSSL_Cleanup)
  87241. };
  87242. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  87243. static void TestSetup(void)
  87244. {
  87245. /* Stub, for now. Add common test setup code here. */
  87246. }
  87247. static void TestCleanup(void)
  87248. {
  87249. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  87250. /* Clear any errors added to the error queue during the test run. */
  87251. wolfSSL_ERR_clear_error();
  87252. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  87253. }
  87254. /* Print out all API test cases with numeric identifier.
  87255. */
  87256. void ApiTest_PrintTestCases(void)
  87257. {
  87258. int i;
  87259. printf("All Test Cases:\n");
  87260. for (i = 0; i < TEST_CASE_CNT; i++) {
  87261. printf("%3d: %s\n", i + 1, testCases[i].name);
  87262. }
  87263. }
  87264. /* Add test case with index to the list to run.
  87265. *
  87266. * @param [in] idx Index of test case to run starting at 1.
  87267. * @return 0 on success.
  87268. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  87269. */
  87270. int ApiTest_RunIdx(int idx)
  87271. {
  87272. if (idx < 1 || idx > TEST_CASE_CNT) {
  87273. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  87274. return BAD_FUNC_ARG;
  87275. }
  87276. testAll = 0;
  87277. testCases[idx-1].run = 1;
  87278. return 0;
  87279. }
  87280. /* Add test case with name to the list to run.
  87281. *
  87282. * @param [in] name Name of test case to run.
  87283. * @return 0 on success.
  87284. * @return BAD_FUNC_ARG when name is not a known test case name.
  87285. */
  87286. int ApiTest_RunName(char* name)
  87287. {
  87288. int i;
  87289. for (i = 0; i < TEST_CASE_CNT; i++) {
  87290. if (XSTRCMP(testCases[i].name, name) == 0) {
  87291. testAll = 0;
  87292. testCases[i].run = 1;
  87293. return 0;
  87294. }
  87295. }
  87296. printf("Test case name not found: %s\n", name);
  87297. printf("Use --list to see all test case names.\n");
  87298. return BAD_FUNC_ARG;
  87299. }
  87300. /* Converts the result code to a string.
  87301. *
  87302. * @param [in] res Test result code.
  87303. * @return String describing test result.
  87304. */
  87305. static const char* apitest_res_string(int res)
  87306. {
  87307. const char* str = "invalid result";
  87308. switch (res) {
  87309. case TEST_SUCCESS:
  87310. str = "passed";
  87311. break;
  87312. case TEST_FAIL:
  87313. str = "failed";
  87314. break;
  87315. case TEST_SKIPPED:
  87316. str = "skipped";
  87317. break;
  87318. }
  87319. return str;
  87320. }
  87321. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87322. static double gettime_secs(void)
  87323. #if defined(_MSC_VER) && defined(_WIN32)
  87324. {
  87325. /* there's no gettimeofday for Windows, so we'll use system time */
  87326. #define EPOCH_DIFF 11644473600LL
  87327. FILETIME currentFileTime;
  87328. GetSystemTimePreciseAsFileTime(&currentFileTime);
  87329. ULARGE_INTEGER uli = { 0, 0 };
  87330. uli.LowPart = currentFileTime.dwLowDateTime;
  87331. uli.HighPart = currentFileTime.dwHighDateTime;
  87332. /* Convert to seconds since Unix epoch */
  87333. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  87334. }
  87335. #else
  87336. {
  87337. struct timeval tv;
  87338. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  87339. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  87340. }
  87341. #endif
  87342. #endif
  87343. int ApiTest(void)
  87344. {
  87345. int i;
  87346. int ret;
  87347. int res = 0;
  87348. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87349. double timeDiff;
  87350. #endif
  87351. printf(" Begin API Tests\n");
  87352. fflush(stdout);
  87353. /* we must perform init and cleanup if not all tests are running */
  87354. if (!testAll) {
  87355. #ifdef WOLFCRYPT_ONLY
  87356. if (wolfCrypt_Init() != 0) {
  87357. printf("wolfCrypt Initialization failed\n");
  87358. res = 1;
  87359. }
  87360. #else
  87361. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  87362. printf("wolfSSL Initialization failed\n");
  87363. res = 1;
  87364. }
  87365. #endif
  87366. }
  87367. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87368. if (res == 0) {
  87369. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  87370. printf("failed to create tmp dir\n");
  87371. res = 1;
  87372. }
  87373. else {
  87374. tmpDirNameSet = 1;
  87375. }
  87376. }
  87377. #endif
  87378. if (res == 0) {
  87379. for (i = 0; i < TEST_CASE_CNT; ++i) {
  87380. EXPECT_DECLS;
  87381. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87382. currentTestName = testCases[i].name;
  87383. #endif
  87384. /* When not testing all cases then skip if not marked for running.
  87385. */
  87386. if (!testAll && !testCases[i].run) {
  87387. continue;
  87388. }
  87389. TestSetup();
  87390. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  87391. fflush(stdout);
  87392. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87393. timeDiff = gettime_secs();
  87394. #endif
  87395. ret = testCases[i].func();
  87396. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87397. timeDiff = gettime_secs() - timeDiff;
  87398. #endif
  87399. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87400. if (ret != TEST_SKIPPED) {
  87401. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  87402. }
  87403. else
  87404. #endif
  87405. {
  87406. printf(" %s\n", apitest_res_string(ret));
  87407. }
  87408. fflush(stdout);
  87409. /* if return code is < 0 and not skipped then assert error */
  87410. Expect((ret > 0 || ret == TEST_SKIPPED),
  87411. ("Test failed\n"),
  87412. ("ret %d", ret));
  87413. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  87414. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  87415. TestCleanup();
  87416. }
  87417. }
  87418. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  87419. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  87420. wc_ecc_fp_free(); /* free per thread cache */
  87421. #endif
  87422. if (!testAll) {
  87423. #ifdef WOLFCRYPT_ONLY
  87424. wolfCrypt_Cleanup();
  87425. #else
  87426. wolfSSL_Cleanup();
  87427. #endif
  87428. }
  87429. (void)testDevId;
  87430. if (res != 0) {
  87431. printf("\nFAILURES:\n");
  87432. for (i = 0; i < TEST_CASE_CNT; ++i) {
  87433. if (testCases[i].fail) {
  87434. printf(" %3d: %s\n", i + 1, testCases[i].name);
  87435. }
  87436. }
  87437. printf("\n");
  87438. fflush(stdout);
  87439. }
  87440. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87441. if (tmpDirNameSet) {
  87442. printf("\nBinary dumps of the memio streams can be found in the\n"
  87443. "%s directory. This can be imported into\n"
  87444. "Wireshark by transforming the file with\n"
  87445. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  87446. "And then loading test_output.dump.hex into Wireshark using\n"
  87447. "the \"Import from Hex Dump...\" option and selecting the\n"
  87448. "TCP encapsulation option.\n", tmpDirName);
  87449. }
  87450. #endif
  87451. printf(" End API Tests\n");
  87452. fflush(stdout);
  87453. return res;
  87454. }